tts

package
v0.0.87 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const TTSErrorType = "tts_error"

Variables

This section is empty.

Functions

func ApplyTextTransforms

func ApplyTextTransforms(text string) string

func Close added in v0.0.15

func Close(t TTS) error

func Collect added in v0.0.15

func Collect(stream ChunkedStream) (frame *model.AudioFrame, err error)

func EndSynthesizeStreamInput added in v0.0.15

func EndSynthesizeStreamInput(stream SynthesizeStream) error

func FilterEmoji

func FilterEmoji(text string) string

func FilterMarkdown

func FilterMarkdown(text string) string

func FilterToolCallMarkers added in v0.0.10

func FilterToolCallMarkers(text string) string

func Model added in v0.0.15

func Model(t TTS) string

func Prewarm added in v0.0.15

func Prewarm(t TTS)

func Provider added in v0.0.15

func Provider(t TTS) string

Types

type AvailabilityChangedEvent added in v0.0.15

type AvailabilityChangedEvent struct {
	TTS       TTS
	Available bool
}

type AvailabilityChangedHandler added in v0.0.15

type AvailabilityChangedHandler func(AvailabilityChangedEvent)

type ChunkedStream

type ChunkedStream interface {
	Next() (*SynthesizedAudio, error)
	Close() error
}

func SynthesizeWithStream added in v0.0.15

func SynthesizeWithStream(ctx context.Context, provider TTS, text string) (ChunkedStream, error)

type DoneStream added in v0.0.15

type DoneStream interface {
	Done() bool
}

type ErrorEmitter added in v0.0.15

type ErrorEmitter struct {
	// contains filtered or unexported fields
}

func (*ErrorEmitter) EmitError added in v0.0.15

func (e *ErrorEmitter) EmitError(err TTSError)

func (*ErrorEmitter) OnError added in v0.0.15

func (e *ErrorEmitter) OnError(handler TTSErrorHandler) func()

type ExceptionStream added in v0.0.15

type ExceptionStream interface {
	Exception() error
}

type FallbackAdapter

type FallbackAdapter struct {
	MetricsEmitter
	ErrorEmitter
	// contains filtered or unexported fields
}

func NewFallbackAdapter

func NewFallbackAdapter(ttss []TTS) *FallbackAdapter

func NewFallbackAdapterWithOptions added in v0.0.15

func NewFallbackAdapterWithOptions(ttss []TTS, options FallbackAdapterOptions) *FallbackAdapter

func (*FallbackAdapter) Capabilities

func (f *FallbackAdapter) Capabilities() TTSCapabilities

func (*FallbackAdapter) Close added in v0.0.15

func (f *FallbackAdapter) Close() error

func (*FallbackAdapter) Label

func (f *FallbackAdapter) Label() string

func (*FallbackAdapter) Model added in v0.0.15

func (f *FallbackAdapter) Model() string

func (*FallbackAdapter) NumChannels

func (f *FallbackAdapter) NumChannels() int

func (*FallbackAdapter) OnAvailabilityChanged added in v0.0.15

func (f *FallbackAdapter) OnAvailabilityChanged(handler AvailabilityChangedHandler) func()

func (*FallbackAdapter) OnError added in v0.0.15

func (f *FallbackAdapter) OnError(handler TTSErrorHandler) func()

func (*FallbackAdapter) OnMetricsCollected added in v0.0.15

func (f *FallbackAdapter) OnMetricsCollected(handler TTSMetricsHandler) func()

func (*FallbackAdapter) Prewarm added in v0.0.15

func (f *FallbackAdapter) Prewarm()

func (*FallbackAdapter) Provider added in v0.0.15

func (f *FallbackAdapter) Provider() string

func (*FallbackAdapter) SampleRate

func (f *FallbackAdapter) SampleRate() int

func (*FallbackAdapter) Stream

func (*FallbackAdapter) Synthesize

func (f *FallbackAdapter) Synthesize(ctx context.Context, text string) (ChunkedStream, error)

type FallbackAdapterOptions added in v0.0.15

type FallbackAdapterOptions struct {
	MaxRetryPerTTS int
	DisableRetries bool
	SampleRate     int
}

type MetricsEmitter added in v0.0.15

type MetricsEmitter struct {
	// contains filtered or unexported fields
}

func (*MetricsEmitter) EmitMetricsCollected added in v0.0.15

func (e *MetricsEmitter) EmitMetricsCollected(metrics *telemetry.TTSMetrics)

func (*MetricsEmitter) OnMetricsCollected added in v0.0.15

func (e *MetricsEmitter) OnMetricsCollected(handler TTSMetricsHandler) func()

type SentenceStreamPacer

type SentenceStreamPacer struct {
	// contains filtered or unexported fields
}

SentenceStreamPacer buffers text from the LLM, groups it into sentences, and only forwards sentences to the underlying TTS stream when the synthesized audio buffer falls below a certain duration threshold. This prevents runaway TTS generation costs if the user interrupts early.

func NewSentenceStreamPacerWithOptions added in v0.0.15

func NewSentenceStreamPacerWithOptions(ctx context.Context, underlying SynthesizeStream, opts SentenceStreamPacerOptions) *SentenceStreamPacer

func (*SentenceStreamPacer) Close

func (p *SentenceStreamPacer) Close() error

func (*SentenceStreamPacer) EndInput added in v0.0.15

func (p *SentenceStreamPacer) EndInput() error

func (*SentenceStreamPacer) Flush

func (p *SentenceStreamPacer) Flush() error

func (*SentenceStreamPacer) Next

func (*SentenceStreamPacer) PushText

func (p *SentenceStreamPacer) PushText(text string) error

type SentenceStreamPacerOptions added in v0.0.15

type SentenceStreamPacerOptions struct {
	MinRemainingAudio    time.Duration
	MinRemainingAudioSet bool
	MaxTextLength        int
	MaxTextLengthSet     bool
}

type StreamAdapter

type StreamAdapter struct {
	MetricsEmitter
	ErrorEmitter
	// contains filtered or unexported fields
}

func NewStreamAdapter

func NewStreamAdapter(t TTS) *StreamAdapter

func (*StreamAdapter) Capabilities

func (a *StreamAdapter) Capabilities() TTSCapabilities

func (*StreamAdapter) Close added in v0.0.15

func (a *StreamAdapter) Close() error

func (*StreamAdapter) Label

func (a *StreamAdapter) Label() string

func (*StreamAdapter) Model added in v0.0.15

func (a *StreamAdapter) Model() string

func (*StreamAdapter) NumChannels

func (a *StreamAdapter) NumChannels() int

func (*StreamAdapter) OnError added in v0.0.15

func (a *StreamAdapter) OnError(handler TTSErrorHandler) func()

func (*StreamAdapter) OnMetricsCollected added in v0.0.15

func (a *StreamAdapter) OnMetricsCollected(handler TTSMetricsHandler) func()

func (*StreamAdapter) Prewarm added in v0.0.15

func (a *StreamAdapter) Prewarm()

func (*StreamAdapter) Provider added in v0.0.15

func (a *StreamAdapter) Provider() string

func (*StreamAdapter) SampleRate

func (a *StreamAdapter) SampleRate() int

func (*StreamAdapter) Stream

func (*StreamAdapter) Synthesize

func (a *StreamAdapter) Synthesize(ctx context.Context, text string) (ChunkedStream, error)

type SynthesizeStream

type SynthesizeStream interface {
	PushText(text string) error
	Flush() error
	Close() error
	Next() (*SynthesizedAudio, error)
}

type SynthesizedAudio

type SynthesizedAudio struct {
	Frame           *model.AudioFrame `json:"frame"`
	RequestID       string            `json:"request_id"`
	IsFinal         bool              `json:"is_final"`
	SegmentID       string            `json:"segment_id"`
	DeltaText       string            `json:"delta_text"`
	TimedTranscript []TimedString     `json:"timed_transcript,omitempty"`
}

func (*SynthesizedAudio) UnmarshalJSON added in v0.0.52

func (a *SynthesizedAudio) UnmarshalJSON(data []byte) error

type TTS

type TTS interface {
	Label() string
	Capabilities() TTSCapabilities
	SampleRate() int
	NumChannels() int
	Synthesize(ctx context.Context, text string) (ChunkedStream, error)
	Stream(ctx context.Context) (SynthesizeStream, error)
}

type TTSCapabilities

type TTSCapabilities struct {
	Streaming         bool `json:"streaming"`
	AlignedTranscript bool `json:"aligned_transcript"`
}

func (*TTSCapabilities) UnmarshalJSON added in v0.0.52

func (c *TTSCapabilities) UnmarshalJSON(data []byte) error

type TTSError added in v0.0.15

type TTSError struct {
	Type        string
	Timestamp   time.Time
	Label       string
	Err         error
	Recoverable bool
}

func (TTSError) Error added in v0.0.15

func (e TTSError) Error() string

func (TTSError) MarshalJSON added in v0.0.52

func (e TTSError) MarshalJSON() ([]byte, error)

func (*TTSError) UnmarshalJSON added in v0.0.52

func (e *TTSError) UnmarshalJSON(data []byte) error

func (TTSError) Unwrap added in v0.0.15

func (e TTSError) Unwrap() error

type TTSErrorHandler added in v0.0.15

type TTSErrorHandler func(TTSError)

type TTSMetricsHandler added in v0.0.15

type TTSMetricsHandler func(*telemetry.TTSMetrics)

type TextReplaceBuffer added in v0.0.15

type TextReplaceBuffer struct {
	// contains filtered or unexported fields
}

func NewTextReplaceBuffer added in v0.0.15

func NewTextReplaceBuffer(replacements map[string]string, caseSensitive bool) *TextReplaceBuffer

func (*TextReplaceBuffer) Flush added in v0.0.15

func (b *TextReplaceBuffer) Flush() []string

func (*TextReplaceBuffer) Push added in v0.0.15

func (b *TextReplaceBuffer) Push(text string) []string

type TextTransformBuffer added in v0.0.15

type TextTransformBuffer struct {
	// contains filtered or unexported fields
}

func NewTextTransformBuffer added in v0.0.15

func NewTextTransformBuffer() *TextTransformBuffer

func (*TextTransformBuffer) Flush added in v0.0.15

func (b *TextTransformBuffer) Flush() []string

func (*TextTransformBuffer) Push added in v0.0.15

func (b *TextTransformBuffer) Push(text string) []string

type TimedString added in v0.0.15

type TimedString struct {
	Text            string  `json:"text"`
	StartTime       float64 `json:"start_time"`
	EndTime         float64 `json:"end_time"`
	Confidence      float64 `json:"confidence"`
	StartTimeOffset float64 `json:"start_time_offset"`
	SpeakerID       string  `json:"speaker_id"`
}

func CollectWithTimedTranscript added in v0.0.15

func CollectWithTimedTranscript(stream ChunkedStream) (frame *model.AudioFrame, timedTranscript []TimedString, err error)

func (TimedString) MarshalJSON added in v0.0.52

func (s TimedString) MarshalJSON() ([]byte, error)

func (TimedString) String added in v0.0.52

func (s TimedString) String() string

func (*TimedString) UnmarshalJSON added in v0.0.52

func (s *TimedString) UnmarshalJSON(data []byte) error

Jump to

Keyboard shortcuts

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