Documentation
¶
Overview ¶
Package voice runs speech-to-text and text-to-speech for a voice target "instance-id/model-id" on the llmgw-core provider of the target's instance: transcription is an Invoke on the audio_transcriptions surface with the OpenAI multipart transcription body, synthesis one on audio_speech with the OpenAI speech JSON. OpenAI-compatible endpoints, ElevenLabs, MiMo and extension providers all go through the same code.
Index ¶
- func AudioMetaForContentType(contentType string) (fileExt string, audioType string, ok bool)
- func AudioMetaForResponseFormat(responseFormat string) (string, string)
- func RecognizedSpeech(text string) (string, bool)
- func Surfaces(provider core.Provider, model string) []core.ModelSurface
- type Client
- type Options
- type Role
- type Speech
- type Transcription
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AudioMetaForContentType ¶
AudioMetaForContentType returns the file extension and content type of audio declared as contentType; ok is false when it names no audio format, such as application/octet-stream.
func AudioMetaForResponseFormat ¶
AudioMetaForResponseFormat returns the file extension and content type of audio in the OpenAI response format; empty is the API's default, MP3.
func RecognizedSpeech ¶
RecognizedSpeech returns the speech a transcript holds, trimmed, and whether it holds any. An empty transcript holds none, and neither does one without a letter or digit, such as "...", or one that is only a transcriber's annotation of audio without speech.
Types ¶
type Client ¶
type Client struct {
Target string
Model string
InstanceID string
// contains filtered or unexported fields
}
Client is one voice target on its core provider.
func New ¶
New returns the client of target for role, checking that the target's provider serves the role's surface for the target's model.
func (*Client) Synthesize ¶
func (c *Client) Synthesize(ctx context.Context, text, voice, responseFormat string) (*Speech, error)
Synthesize speaks text with voice (empty: the provider's default), requesting responseFormat (such as "opus" or "mp3"). A provider that rejects the format is asked again without one; the audio's format is what the provider says it returned, else what was asked for.
func (*Client) Transcribe ¶
func (c *Client) Transcribe(ctx context.Context, audio []byte, filename string) (*Transcription, error)
Transcribe transcribes audio. filename, such as "recording.wav", tells the provider the audio's format.
type Options ¶
type Options struct {
// ViaChat serves SpeechToText through the target's chat model with
// llmgw-core's ChatTranscriptionAdapter, opted in for exactly the
// target's model (config.VoiceConfig.STTViaChat).
ViaChat bool
// Resolver resolves the target and its secret; nil reads the auth store.
Resolver *modelservice.Resolver
// NewProvider builds the instance's core provider; nil uses
// providers.NewCoreProvider, as for every instance (an extension
// instance's provider serves the surfaces the daemon lists for it).
NewProvider func(*config.ProviderInstanceConfig) (core.Provider, error)
}
Options configure New.
type Speech ¶
type Speech struct {
Audio []byte
ContentType string
// FileExt is the file extension of ContentType, such as ".ogg".
FileExt string
}
Speech is synthesized audio and its format.
type Transcription ¶
type Transcription struct {
Text string `json:"text"`
Language string `json:"language,omitempty"`
Duration float64 `json:"duration,omitempty"`
}
Transcription is a speech-to-text result.