edgetts

package
v0.13.7 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT, GPL-3.0, LGPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// DefaultVoice is the default voice used for TTS.
	DefaultVoice = "en-US-EmmaMultilingualNeural"
)

Variables

View Source
var (
	// ErrNoAudioReceived is returned when the TTS stream completes without any audio data.
	ErrNoAudioReceived = errors.New("edgetts: no audio received from server")

	// ErrUnexpectedResponse is returned when the server sends a malformed message.
	ErrUnexpectedResponse = errors.New("edgetts: unexpected response from server")

	// ErrUnknownResponse is returned when the server sends an unrecognized metadata type.
	ErrUnknownResponse = errors.New("edgetts: unknown response type from server")

	// ErrWebSocket is returned when a WebSocket connection error occurs.
	ErrWebSocket = errors.New("edgetts: websocket error")

	// ErrSkewAdjustment is returned when clock skew correction fails.
	ErrSkewAdjustment = errors.New("edgetts: failed to adjust clock skew")

	// ErrInvalidConfig is returned when TTS configuration parameters are invalid.
	ErrInvalidConfig = errors.New("edgetts: invalid configuration")

	// ErrMixedBoundaryTypes is returned when word and sentence boundaries are mixed.
	ErrMixedBoundaryTypes = errors.New("edgetts: cannot mix word and sentence boundary types")
)

Functions

This section is empty.

Types

type BoundaryType

type BoundaryType string

BoundaryType specifies the type of boundary metadata to request.

const (
	// WordBoundary requests word-level timing metadata.
	WordBoundary BoundaryType = "WordBoundary"
	// SentenceBoundary requests sentence-level timing metadata.
	SentenceBoundary BoundaryType = "SentenceBoundary"
)

type ChunkType

type ChunkType string

ChunkType represents the type of a TTS chunk.

const (
	// ChunkTypeAudio indicates the chunk contains audio data.
	ChunkTypeAudio ChunkType = "audio"
	// ChunkTypeWordBoundary indicates the chunk contains word boundary metadata.
	ChunkTypeWordBoundary ChunkType = "WordBoundary"
	// ChunkTypeSentenceBoundary indicates the chunk contains sentence boundary metadata.
	ChunkTypeSentenceBoundary ChunkType = "SentenceBoundary"
)

type Communicate

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

Communicate handles text-to-speech synthesis via the Edge TTS WebSocket service.

func NewCommunicate

func NewCommunicate(text string, config TTSConfig, opts ...CommunicateOption) (*Communicate, error)

NewCommunicate creates a new Communicate instance for the given text and config.

func (*Communicate) Stream

func (c *Communicate) Stream(ctx context.Context, callback func(TTSChunk) error) error

Stream sends the text to the Edge TTS service and calls the callback for each chunk. The callback receives TTSChunk values in order: interleaved audio data and metadata.

type CommunicateOption

type CommunicateOption func(*Communicate)

CommunicateOption configures a Communicate instance.

func WithConnectTimeout

func WithConnectTimeout(d time.Duration) CommunicateOption

WithConnectTimeout sets the WebSocket connection timeout.

func WithProxy

func WithProxy(proxy string) CommunicateOption

WithProxy sets an HTTP proxy for the WebSocket connection.

func WithReceiveTimeout

func WithReceiveTimeout(d time.Duration) CommunicateOption

WithReceiveTimeout sets the timeout for receiving messages.

type TTSChunk

type TTSChunk struct {
	Type     ChunkType
	Data     []byte        // Audio data (only for ChunkTypeAudio)
	Offset   time.Duration // Time offset (only for metadata chunks)
	Duration time.Duration // Duration (only for metadata chunks)
	Text     string        // Text content (only for metadata chunks)
}

TTSChunk represents a single chunk of TTS output, either audio data or metadata.

type TTSConfig

type TTSConfig struct {
	Voice    string
	Rate     string
	Volume   string
	Pitch    string
	Boundary BoundaryType
}

TTSConfig holds the configuration for a TTS request.

func DefaultConfig

func DefaultConfig() TTSConfig

DefaultConfig returns a TTSConfig with default values.

func (TTSConfig) Validate

func (c TTSConfig) Validate() error

Validate checks the configuration values and returns an error if any are invalid.

type Voice

type Voice struct {
	Name           string   `json:"Name"`
	ShortName      string   `json:"ShortName"`
	Gender         string   `json:"Gender"`
	Locale         string   `json:"Locale"`
	SuggestedCodec string   `json:"SuggestedCodec"`
	FriendlyName   string   `json:"FriendlyName"`
	Status         string   `json:"Status"`
	VoiceTag       VoiceTag `json:"VoiceTag"`
}

Voice represents a single available TTS voice.

func ListVoices

func ListVoices(ctx context.Context, proxy string) ([]Voice, error)

ListVoices fetches the list of available voices from the Edge TTS service.

type VoiceTag

type VoiceTag struct {
	ContentCategories  []string `json:"ContentCategories"`
	VoicePersonalities []string `json:"VoicePersonalities"`
}

VoiceTag contains categorization information for a voice.

Jump to

Keyboard shortcuts

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