Documentation
¶
Index ¶
Constants ¶
const (
// DefaultVoice is the default voice used for TTS.
DefaultVoice = "en-US-EmmaMultilingualNeural"
)
Variables ¶
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.
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.
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.