Documentation
¶
Overview ¶
Package speech is the voice-dictation module's domain layer: the speech-to-text port, its result value types, and the WAV validator that keeps unbilled garbage audio from reaching the provider. Provider adapters (Meta Model API, OpenAI-compatible transcription) live in the module's infrastructure package and implement the port.
Index ¶
Constants ¶
const ( // MaxAudioBytes bounds a dictation upload: five minutes of 16 kHz mono // 16-bit PCM (≈9.6 MB with the WAV header) fit, anything larger is // rejected before it reaches the provider. MaxAudioBytes = 10 << 20 )
Variables ¶
var ( // ErrInvalidAudio reports audio that is not a mono 16-bit PCM WAV file // at a supported sample rate. ErrInvalidAudio = errors.New("audio must be a mono 16-bit PCM WAV file") // ErrAudioTooLarge reports an upload beyond MaxAudioBytes. ErrAudioTooLarge = errors.New("audio exceeds the maximum dictation length") // ErrTranscriptionFailed reports a provider-side transcription failure. ErrTranscriptionFailed = errors.New("speech transcription failed") // ErrEmptyTranscript reports a provider response that carries no text. ErrEmptyTranscript = errors.New("speech transcription returned no text") )
Functions ¶
func NormalizeLanguage ¶
NormalizeLanguage trims a language hint for the provider request. An empty hint means auto-detect and stays empty; overlong values are dropped to empty rather than forwarded.
func ValidateWAV ¶
ValidateWAV rejects anything that is not a mono 16-bit PCM WAV file at a supported sample rate, or that exceeds MaxAudioBytes. It parses the RIFF envelope and the fmt chunk instead of trusting extensions or MIME types.
Types ¶
type SpeechToTextService ¶
type SpeechToTextService interface {
Transcribe(
ctx context.Context,
audio []byte,
language string,
) (Transcription, error)
}
SpeechToTextService defines the interface for speech-to-text providers.
type Transcription ¶
Transcription is the outcome of transcribing dictated audio: the full text plus the detected turns behind it.
func NewTranscription ¶
func NewTranscription(text string, turns []Turn) Transcription
NewTranscription assembles a transcription outcome from its text and turns.