Class: Telnyx::Lib::WebSocket::TextToSpeechStreamParams
- Inherits:
-
Object
- Object
- Telnyx::Lib::WebSocket::TextToSpeechStreamParams
- Defined in:
- lib/telnyx/lib/websocket/text_to_speech_stream_params.rb
Overview
Parameters for configuring Text-to-Speech WebSocket streaming.
These parameters are passed as query string parameters when establishing the WebSocket connection.
Example usage:
params = TextToSpeechStreamParams.new(
voice: "telnyx.NaturalHD.Alloy",
output_format: "mp3"
)
url = params.to_query_string
Instance Attribute Summary collapse
-
#client_ref ⇒ String?
Client reference identifier.
-
#language ⇒ String?
Language code (e.g., “en-US”).
-
#model ⇒ String?
TTS model to use.
-
#output_format ⇒ String?
The audio output format (e.g., “mp3”, “pcm”, “wav”).
-
#pitch ⇒ Float?
Pitch adjustment (-20.0 to 20.0).
-
#sample_rate ⇒ Integer?
Sample rate in Hz (e.g., 22050, 24000).
-
#speed ⇒ Float?
Speaking rate/speed multiplier (0.5 to 2.0).
-
#voice ⇒ String?
The voice to use (e.g., “telnyx.NaturalHD.Alloy”).
Class Method Summary collapse
-
.from_hash(options) ⇒ TextToSpeechStreamParams
Create params from a hash.
Instance Method Summary collapse
-
#to_hash ⇒ Hash
Convert to a hash for URL encoding.
-
#to_query_string ⇒ String
Convert to URL query string.
Instance Attribute Details
#client_ref ⇒ String?
Returns Client reference identifier.
42 43 44 |
# File 'lib/telnyx/lib/websocket/text_to_speech_stream_params.rb', line 42 def client_ref @client_ref end |
#language ⇒ String?
Returns Language code (e.g., “en-US”).
30 31 32 |
# File 'lib/telnyx/lib/websocket/text_to_speech_stream_params.rb', line 30 def language @language end |
#model ⇒ String?
Returns TTS model to use.
39 40 41 |
# File 'lib/telnyx/lib/websocket/text_to_speech_stream_params.rb', line 39 def model @model end |
#output_format ⇒ String?
Returns The audio output format (e.g., “mp3”, “pcm”, “wav”).
24 25 26 |
# File 'lib/telnyx/lib/websocket/text_to_speech_stream_params.rb', line 24 def output_format @output_format end |
#pitch ⇒ Float?
Returns Pitch adjustment (-20.0 to 20.0).
36 37 38 |
# File 'lib/telnyx/lib/websocket/text_to_speech_stream_params.rb', line 36 def pitch @pitch end |
#sample_rate ⇒ Integer?
Returns Sample rate in Hz (e.g., 22050, 24000).
27 28 29 |
# File 'lib/telnyx/lib/websocket/text_to_speech_stream_params.rb', line 27 def sample_rate @sample_rate end |
#speed ⇒ Float?
Returns Speaking rate/speed multiplier (0.5 to 2.0).
33 34 35 |
# File 'lib/telnyx/lib/websocket/text_to_speech_stream_params.rb', line 33 def speed @speed end |
#voice ⇒ String?
Returns The voice to use (e.g., “telnyx.NaturalHD.Alloy”).
21 22 23 |
# File 'lib/telnyx/lib/websocket/text_to_speech_stream_params.rb', line 21 def voice @voice end |
Class Method Details
.from_hash(options) ⇒ TextToSpeechStreamParams
Create params from a hash
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/telnyx/lib/websocket/text_to_speech_stream_params.rb', line 48 def self.from_hash() params = new params.voice = [:voice] || ["voice"] params.output_format = [:output_format] || ["output_format"] params.sample_rate = [:sample_rate] || ["sample_rate"] params.language = [:language] || ["language"] params.speed = [:speed] || ["speed"] params.pitch = [:pitch] || ["pitch"] params.model = [:model] || ["model"] params.client_ref = [:client_ref] || ["client_ref"] params end |
Instance Method Details
#to_hash ⇒ Hash
Convert to a hash for URL encoding
64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/telnyx/lib/websocket/text_to_speech_stream_params.rb', line 64 def to_hash hash = {} hash["voice"] = voice if voice hash["output_format"] = output_format if output_format hash["sample_rate"] = sample_rate.to_s if sample_rate hash["language"] = language if language hash["speed"] = speed.to_s if speed hash["pitch"] = pitch.to_s if pitch hash["model"] = model if model hash["client_ref"] = client_ref if client_ref hash end |
#to_query_string ⇒ String
Convert to URL query string
80 81 82 83 |
# File 'lib/telnyx/lib/websocket/text_to_speech_stream_params.rb', line 80 def to_query_string require("cgi") to_hash.map { |k, v| "#{CGI.escape(k)}=#{CGI.escape(v.to_s)}" }.join("&") end |