voice

package
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 11, 2026 License: MIT Imports: 18 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func AudioMetaForContentType

func AudioMetaForContentType(contentType string) (fileExt string, audioType string, ok bool)

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

func AudioMetaForResponseFormat(responseFormat string) (string, string)

AudioMetaForResponseFormat returns the file extension and content type of audio in the OpenAI response format; empty is the API's default, MP3.

func RecognizedSpeech

func RecognizedSpeech(text string) (string, bool)

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.

func Surfaces

func Surfaces(provider core.Provider, model string) []core.ModelSurface

Surfaces returns every surface provider serves for model: translated ones when it reports them, else its native ones.

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

func New(cfg *config.Config, target string, role Role, options Options) (*Client, error)

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 Role

type Role int

Role is what a voice target does.

const (
	// SpeechToText transcribes audio: the audio_transcriptions surface.
	SpeechToText Role = iota
	// TextToSpeech synthesizes speech: the audio_speech surface.
	TextToSpeech
)

func (Role) String

func (r Role) String() string

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL