Text-to-Speech
StreamConvert (WebSocket)
`TextToSpeech.StreamConvert` for incremental, low-latency TTS.
Signature
func (c *TTSClient) StreamConvert(ctx context.Context, targetLanguage LanguageCode, opts ...streamOption) (*AudioStream, error)Options
| Option | Type |
|---|---|
WithStreamModel | BulbulV2|BulbulV3Beta |
WithStreamSpeaker | SpeakerVoice (required) |
WithStreamSendCompletionEvent | bool |
WithStreamPitch | float64 |
WithStreamPace | float64 |
WithStreamLoudness | float64 |
WithStreamTemperature | float64 |
WithStreamSampleRate | SpeechSampleRate |
WithStreamEnablePreprocessing | bool |
WithStreamAudioCodec | AudioCodec |
WithStreamBitrate | Bitrate |
WithMinBufferSize | int (30..200) |
WithMaxChunkSize | int (50..500) |
Global validation
target_language_codemust be supported.speakeris required.BulbulV3(non-beta) is rejected for streaming.- speaker must belong to model-specific voice list.
min_buffer_sizemust be30..200when set.max_chunk_lengthmust be50..500when set.
Model-specific valid / invalid combinations
| Combination | Result |
|---|---|
BulbulV2 + WithStreamTemperature(...) | Validation error |
BulbulV2 + WithStreamPitch(-0.75..0.75) | Valid |
BulbulV2 + WithStreamLoudness(0.3..3.0) | Valid |
BulbulV2 + WithStreamPace(0.3..3.0) | Valid |
BulbulV2 + sample rate in {8000,16000,22050,24000} | Valid |
BulbulV3Beta + WithStreamPitch(...) | Validation error |
BulbulV3Beta + WithStreamLoudness(...) | Validation error |
BulbulV3Beta + WithStreamTemperature(0.01..1.0) | Valid |
BulbulV3Beta + WithStreamPace(0.5..2.0) | Valid |
BulbulV3Beta + sample rate in {8000,16000,22050,24000} | Valid |
Streaming protocol behavior
- SDK sends
send_completion_event=trueby default unless overridden. - after socket connect, SDK sends a
configmessage. - text input is sent via
SendText, thenFlush.
AudioStream methods
Next() boolCurrent() AudioDataErr() errorClose() errorSendText(string) errorFlush() errorPing() errorEvents() <-chan EventData
Example
stream, err := client.TextToSpeech.StreamConvert(
ctx,
tts.LanguageHiIN,
tts.WithStreamModel(tts.BulbulV2),
tts.WithStreamSpeaker(tts.SpeakerAnushka),
tts.WithStreamPace(1.1),
)
if err != nil {
panic(err)
}
defer stream.Close()
if err := stream.SendText("Namaste, yeh streaming TTS test hai."); err != nil {
panic(err)
}
if err := stream.Flush(); err != nil {
panic(err)
}
for stream.Next() {
chunk := stream.Current()
_ = chunk
}
if err := stream.Err(); err != nil {
panic(err)
}