Class: Telnyx::Resources::TextToSpeech
- Inherits:
-
Object
- Object
- Telnyx::Resources::TextToSpeech
- Defined in:
- lib/telnyx/resources/text_to_speech.rb
Instance Method Summary collapse
-
#generate(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, request_options: {}) ⇒ Telnyx::Models::TextToSpeechGenerateResponse
Some parameter documentations has been truncated, see Models::TextToSpeechGenerateParams 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.
-
#stream(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::TextToSpeechStreamParams 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.
161 162 163 |
# File 'lib/telnyx/resources/text_to_speech.rb', line 161 def initialize(client:) @client = client end |
Instance Method Details
#generate(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, request_options: {}) ⇒ Telnyx::Models::TextToSpeechGenerateResponse
Some parameter documentations has been truncated, see Models::TextToSpeechGenerateParams 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`). Alternatively, specify `provider` explicitly along with provider-specific parameters.
Supported providers: ‘aws`, `telnyx`, `azure`, `elevenlabs`, `minimax`, `rime`, `resemble`.
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/telnyx/resources/text_to_speech.rb', line 61 def generate(params = {}) parsed, = Telnyx::TextToSpeechGenerateParams.dump_request(params) @client.request( method: :post, path: "text-to-speech/speech", body: parsed, model: Telnyx::Models::TextToSpeechGenerateResponse, 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.
89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/telnyx/resources/text_to_speech.rb', line 89 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 |
#stream(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::TextToSpeechStreamParams 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`.
**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.
146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/telnyx/resources/text_to_speech.rb', line 146 def stream(params = {}) parsed, = Telnyx::TextToSpeechStreamParams.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 |