- audio.StemSeparator/StemSeparationProvider: Demucs zip transport via POST /upstream/<id>/v1/stems (Mode two -> two_stems=vocals; model + format fields); bounded zip unpack, entry name -> stem, ext -> MIME. - SFXModel reuses musicgen against the sync /upstream/<id>/v1/sfx route (JSON prompt/seconds/steps/cfg_scale/seed -> WAV); musicgen.Request gains CFGScale. - audio.SpeechEnhancer/SpeechEnhancementProvider: POST /upstream/<id>/v1/enhance -> WAV (result reuses SpeechResult). - SpeechRequest.ReferenceAudio/ReferenceMIME (+WithReferenceAudio): llamaswap switches to the chatterbox clone route POST /upstream/<id>/v1/audio/speech/upload (input + voice_file), wav MIME fallback. - TranscriptionRequest.Translate (+WithTranslate): translate=true form field, language=auto forced when no explicit hint (whisper.cpp default en would skip translation). - httptest contract tests (zip unpack, clone-route switch, translate + auto-language injection); ADR-0024 (index row deferred — MJ-A backfills the ADR index table and parallel edits would conflict). Co-Authored-By: Claude Fable 5 <[email protected]>
67 lines
2.3 KiB
Go
67 lines
2.3 KiB
Go
package audio
|
|
|
|
import "context"
|
|
|
|
// EnhancementRequest asks a speech-enhancement backend (DeepFilterNet style)
|
|
// to denoise a recording. Audio is carried as bytes (never a URL), mirroring
|
|
// TranscriptionRequest (ADR-0024).
|
|
type EnhancementRequest struct {
|
|
// Audio is the encoded audio to enhance.
|
|
Audio []byte
|
|
|
|
// MIME is the audio MIME type (e.g. "audio/mpeg"); "" = let the backend
|
|
// sniff it.
|
|
MIME string
|
|
|
|
// Filename is the multipart filename hint some backends key their format
|
|
// detection on; "" derives one from MIME or falls back to "audio".
|
|
Filename string
|
|
}
|
|
|
|
// EnhancementOption mutates an EnhancementRequest before it is sent.
|
|
// Reserved for future request settings (the reference backend takes no
|
|
// parameters).
|
|
type EnhancementOption func(*EnhancementRequest)
|
|
|
|
// Apply returns a copy of the request with all options applied.
|
|
func (r EnhancementRequest) Apply(opts ...EnhancementOption) EnhancementRequest {
|
|
for _, opt := range opts {
|
|
opt(&r)
|
|
}
|
|
return r
|
|
}
|
|
|
|
// SpeechEnhancer denoises speech recordings. The result reuses SpeechResult
|
|
// (audio bytes + MIME + Raw) — enhancement is audio-in/audio-out exactly
|
|
// like synthesis.
|
|
type SpeechEnhancer interface {
|
|
// Enhance returns the denoised audio.
|
|
Enhance(ctx context.Context, req EnhancementRequest, opts ...EnhancementOption) (*SpeechResult, error)
|
|
}
|
|
|
|
// SpeechEnhancerModelOption configures a SpeechEnhancer at construction time.
|
|
// Reserved for future per-model settings.
|
|
type SpeechEnhancerModelOption func(*SpeechEnhancerModelConfig)
|
|
|
|
// SpeechEnhancerModelConfig carries per-model construction settings.
|
|
type SpeechEnhancerModelConfig struct{}
|
|
|
|
// ApplySpeechEnhancerModelOptions folds options into a config.
|
|
func ApplySpeechEnhancerModelOptions(opts []SpeechEnhancerModelOption) SpeechEnhancerModelConfig {
|
|
var cfg SpeechEnhancerModelConfig
|
|
for _, opt := range opts {
|
|
opt(&cfg)
|
|
}
|
|
return cfg
|
|
}
|
|
|
|
// SpeechEnhancementProvider mints SpeechEnhancers bound to one backend.
|
|
type SpeechEnhancementProvider interface {
|
|
// Name is the registry identifier for the provider.
|
|
Name() string
|
|
|
|
// SpeechEnhancerModel returns a SpeechEnhancer bound to the given id
|
|
// (passed through to the backend verbatim; no catalog validation).
|
|
SpeechEnhancerModel(id string, opts ...SpeechEnhancerModelOption) (SpeechEnhancer, error)
|
|
}
|