Class: Telnyx::Resources::TextToSpeech
- Inherits:
-
Object
- Object
- Telnyx::Resources::TextToSpeech
- Defined in:
- lib/telnyx/resources/text_to_speech.rb
Overview
Text to speech streaming command operations
Instance Method Summary collapse
-
#generate_speech(aws: nil, azure: nil, disable_cache: nil, elevenlabs: nil, language: nil, minimax: nil, output_type: nil, provider: nil, resemble: nil, rime: nil, telnyx: nil, text: nil, text_type: nil, voice: nil, voice_settings: nil, xai: nil, request_options: {}) ⇒ Telnyx::Models::TextToSpeechGenerateSpeechResponse
Some parameter documentations has been truncated, see Models::TextToSpeechGenerateSpeechParams for more details.
-
#initialize(client:) ⇒ TextToSpeech
constructor
private
A new instance of TextToSpeech.
-
#list_voices(api_key: nil, provider: nil, request_options: {}) ⇒ Telnyx::Models::TextToSpeechListVoicesResponse
Retrieve a list of available voices from one or all TTS providers.
-
#retrieve_speech(audio_format: nil, disable_cache: nil, model_id: nil, provider: nil, socket_id: nil, voice: nil, voice_id: nil, request_options: {}) ⇒ nil
Some parameter documentations has been truncated, see Models::TextToSpeechRetrieveSpeechParams for more details.
Constructor Details
#initialize(client:) ⇒ TextToSpeech
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of TextToSpeech.
171 172 173 |
# File 'lib/telnyx/resources/text_to_speech.rb', line 171 def initialize(client:) @client = client end |
Instance Method Details
#generate_speech(aws: nil, azure: nil, disable_cache: nil, elevenlabs: nil, language: nil, minimax: nil, output_type: nil, provider: nil, resemble: nil, rime: nil, telnyx: nil, text: nil, text_type: nil, voice: nil, voice_settings: nil, xai: nil, request_options: {}) ⇒ Telnyx::Models::TextToSpeechGenerateSpeechResponse
Some parameter documentations has been truncated, see Models::TextToSpeechGenerateSpeechParams for more details.
Generate synthesized speech audio from text input. Returns audio in the requested format (binary audio stream, base64-encoded JSON, or an audio URL for later retrieval).
Authentication is provided via the standard ‘Authorization: Bearer <API_KEY>` header.
The ‘voice` parameter provides a convenient shorthand to specify provider, model, and voice in a single string (e.g. `telnyx.NaturalHD.Alloy` or `Telnyx.Ultra.<voice_id>`). Alternatively, specify `provider` explicitly along with provider-specific parameters.
Supported providers: ‘aws`, `telnyx`, `azure`, `elevenlabs`, `minimax`, `rime`, `resemble`, `xai`.
The Telnyx ‘Ultra` model supports 44 languages with emotion control, speed adjustment, and volume control. Use the `telnyx` provider-specific parameters to configure these features.
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/telnyx/resources/text_to_speech.rb', line 68 def generate_speech(params = {}) parsed, = Telnyx::TextToSpeechGenerateSpeechParams.dump_request(params) @client.request( method: :post, path: "text-to-speech/speech", body: parsed, model: Telnyx::Models::TextToSpeechGenerateSpeechResponse, options: ) end |
#list_voices(api_key: nil, provider: nil, request_options: {}) ⇒ Telnyx::Models::TextToSpeechListVoicesResponse
Retrieve a list of available voices from one or all TTS providers. When ‘provider` is specified, returns voices for that provider only. Otherwise, returns voices from all providers.
Some providers (ElevenLabs, Resemble) require an API key to list voices.
96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/telnyx/resources/text_to_speech.rb', line 96 def list_voices(params = {}) parsed, = Telnyx::TextToSpeechListVoicesParams.dump_request(params) query = Telnyx::Internal::Util.encode_query_params(parsed) @client.request( method: :get, path: "text-to-speech/voices", query: query, model: Telnyx::Models::TextToSpeechListVoicesResponse, options: ) end |
#retrieve_speech(audio_format: nil, disable_cache: nil, model_id: nil, provider: nil, socket_id: nil, voice: nil, voice_id: nil, request_options: {}) ⇒ nil
Some parameter documentations has been truncated, see Models::TextToSpeechRetrieveSpeechParams for more details.
Open a WebSocket connection to stream text and receive synthesized audio in real time. Authentication is provided via the standard ‘Authorization: Bearer <API_KEY>` header. Send JSON frames with text to synthesize; receive JSON frames containing base64-encoded audio chunks.
Supported providers: ‘aws`, `telnyx`, `azure`, `murfai`, `minimax`, `rime`, `resemble`, `elevenlabs`, `xai`.
**Connection flow:**
-
Open WebSocket with query parameters specifying provider, voice, and model.
-
Send an initial handshake message ‘“ ”` (single space) with optional `voice_settings` to initialize the session.
-
Send text messages as ‘“Hello world”`.
-
Receive audio chunks as JSON frames with base64-encoded audio.
-
A final frame with ‘isFinal: true` indicates the end of audio for the current text.
To interrupt and restart synthesis mid-stream, send ‘true` — the current worker is stopped and a new one is started.
Note: The Telnyx ‘Ultra` model is not available over WebSocket. Use the HTTP POST `/text-to-speech/speech` endpoint instead.
156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/telnyx/resources/text_to_speech.rb', line 156 def retrieve_speech(params = {}) parsed, = Telnyx::TextToSpeechRetrieveSpeechParams.dump_request(params) query = Telnyx::Internal::Util.encode_query_params(parsed) @client.request( method: :get, path: "text-to-speech/speech", query: query, model: NilClass, options: ) end |