Class: Telnyx::Lib::WebSocket::TextToSpeechStreamParams

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#client_refString?

Returns Client reference identifier.

Returns:

  • (String, nil)

    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

#languageString?

Returns Language code (e.g., “en-US”).

Returns:

  • (String, nil)

    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

#modelString?

Returns TTS model to use.

Returns:

  • (String, nil)

    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_formatString?

Returns The audio output format (e.g., “mp3”, “pcm”, “wav”).

Returns:

  • (String, nil)

    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

#pitchFloat?

Returns Pitch adjustment (-20.0 to 20.0).

Returns:

  • (Float, nil)

    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_rateInteger?

Returns Sample rate in Hz (e.g., 22050, 24000).

Returns:

  • (Integer, nil)

    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

#speedFloat?

Returns Speaking rate/speed multiplier (0.5 to 2.0).

Returns:

  • (Float, nil)

    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

#voiceString?

Returns The voice to use (e.g., “telnyx.NaturalHD.Alloy”).

Returns:

  • (String, nil)

    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

Parameters:

  • options (Hash)

    The parameter options

Returns:



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(options)
  params = new
  params.voice = options[:voice] || options["voice"]
  params.output_format = options[:output_format] || options["output_format"]
  params.sample_rate = options[:sample_rate] || options["sample_rate"]
  params.language = options[:language] || options["language"]
  params.speed = options[:speed] || options["speed"]
  params.pitch = options[:pitch] || options["pitch"]
  params.model = options[:model] || options["model"]
  params.client_ref = options[:client_ref] || options["client_ref"]
  params
end

Instance Method Details

#to_hashHash

Convert to a hash for URL encoding

Returns:

  • (Hash)

    The params as a hash with string keys



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_stringString

Convert to URL query string

Returns:

  • (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