Class: Telnyx::Lib::WebSocket::SpeechToTextStreamParams

Inherits:
Object
  • Object
show all
Defined in:
lib/telnyx/lib/websocket/speech_to_text_stream_params.rb

Overview

Parameters for configuring Speech-to-Text WebSocket streaming.

These parameters are passed as query string parameters when establishing the WebSocket connection.

Example usage:

params = SpeechToTextStreamParams.new(
  transcription_engine: "Deepgram",
  language: "en-US",
  input_format: "wav"
)
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



55
56
57
# File 'lib/telnyx/lib/websocket/speech_to_text_stream_params.rb', line 55

def client_ref
  @client_ref
end

#diarizeBoolean?

Returns Enable speaker diarization.

Returns:

  • (Boolean, nil)

    Enable speaker diarization



43
44
45
# File 'lib/telnyx/lib/websocket/speech_to_text_stream_params.rb', line 43

def diarize
  @diarize
end

#diarize_speakersInteger?

Returns Number of speakers for diarization.

Returns:

  • (Integer, nil)

    Number of speakers for diarization



46
47
48
# File 'lib/telnyx/lib/websocket/speech_to_text_stream_params.rb', line 46

def diarize_speakers
  @diarize_speakers
end

#input_formatString?

Returns The audio input format (e.g., “wav”, “mp3”, “raw”).

Returns:

  • (String, nil)

    The audio input format (e.g., “wav”, “mp3”, “raw”)



28
29
30
# File 'lib/telnyx/lib/websocket/speech_to_text_stream_params.rb', line 28

def input_format
  @input_format
end

#interim_resultsBoolean?

Returns Enable interim/partial results.

Returns:

  • (Boolean, nil)

    Enable interim/partial results



34
35
36
# File 'lib/telnyx/lib/websocket/speech_to_text_stream_params.rb', line 34

def interim_results
  @interim_results
end

#keywordsArray<String>?

Returns Keywords to boost recognition.

Returns:

  • (Array<String>, nil)

    Keywords to boost recognition



52
53
54
# File 'lib/telnyx/lib/websocket/speech_to_text_stream_params.rb', line 52

def keywords
  @keywords
end

#languageString?

Returns The language code (e.g., “en-US”, “es-ES”).

Returns:

  • (String, nil)

    The language code (e.g., “en-US”, “es-ES”)



25
26
27
# File 'lib/telnyx/lib/websocket/speech_to_text_stream_params.rb', line 25

def language
  @language
end

#modelString?

Returns Custom vocabulary or model name.

Returns:

  • (String, nil)

    Custom vocabulary or model name



49
50
51
# File 'lib/telnyx/lib/websocket/speech_to_text_stream_params.rb', line 49

def model
  @model
end

#profanity_filterBoolean?

Returns Enable profanity filtering.

Returns:

  • (Boolean, nil)

    Enable profanity filtering



40
41
42
# File 'lib/telnyx/lib/websocket/speech_to_text_stream_params.rb', line 40

def profanity_filter
  @profanity_filter
end

#punctuateBoolean?

Returns Enable automatic punctuation.

Returns:

  • (Boolean, nil)

    Enable automatic punctuation



37
38
39
# File 'lib/telnyx/lib/websocket/speech_to_text_stream_params.rb', line 37

def punctuate
  @punctuate
end

#sample_rateInteger?

Returns Sample rate in Hz (e.g., 8000, 16000).

Returns:

  • (Integer, nil)

    Sample rate in Hz (e.g., 8000, 16000)



31
32
33
# File 'lib/telnyx/lib/websocket/speech_to_text_stream_params.rb', line 31

def sample_rate
  @sample_rate
end

#transcription_engineString?

Returns The transcription engine to use (e.g., “Deepgram”, “Google”, “Telnyx”).

Returns:

  • (String, nil)

    The transcription engine to use (e.g., “Deepgram”, “Google”, “Telnyx”)



22
23
24
# File 'lib/telnyx/lib/websocket/speech_to_text_stream_params.rb', line 22

def transcription_engine
  @transcription_engine
end

Class Method Details

.from_hash(options) ⇒ SpeechToTextStreamParams

Create params from a hash

Parameters:

  • options (Hash)

    The parameter options

Returns:



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/telnyx/lib/websocket/speech_to_text_stream_params.rb', line 61

def self.from_hash(options)
  params = new
  params.transcription_engine = options[:transcription_engine] || options["transcription_engine"]
  params.language = options[:language] || options["language"]
  params.input_format = options[:input_format] || options["input_format"]
  params.sample_rate = options[:sample_rate] || options["sample_rate"]
  params.interim_results = options[:interim_results] || options["interim_results"]
  params.punctuate = options[:punctuate] || options["punctuate"]
  params.profanity_filter = options[:profanity_filter] || options["profanity_filter"]
  params.diarize = options[:diarize] || options["diarize"]
  params.diarize_speakers = options[:diarize_speakers] || options["diarize_speakers"]
  params.model = options[:model] || options["model"]
  params.keywords = options[:keywords] || options["keywords"]
  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



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/telnyx/lib/websocket/speech_to_text_stream_params.rb', line 81

def to_hash
  hash = {}
  hash["transcription_engine"] = transcription_engine if transcription_engine
  hash["language"] = language if language
  hash["input_format"] = input_format if input_format
  hash["sample_rate"] = sample_rate.to_s if sample_rate
  hash["interim_results"] = interim_results.to_s unless interim_results.nil?
  hash["punctuate"] = punctuate.to_s unless punctuate.nil?
  hash["profanity_filter"] = profanity_filter.to_s unless profanity_filter.nil?
  hash["diarize"] = diarize.to_s unless diarize.nil?
  hash["diarize_speakers"] = diarize_speakers.to_s if diarize_speakers
  hash["model"] = model if model
  hash["keywords"] = keywords.join(",") if keywords && !keywords.empty?
  hash["client_ref"] = client_ref if client_ref
  hash
end

#to_query_stringString

Convert to URL query string

Returns:

  • (String)


101
102
103
104
# File 'lib/telnyx/lib/websocket/speech_to_text_stream_params.rb', line 101

def to_query_string
  require("cgi")
  to_hash.map { |k, v| "#{CGI.escape(k)}=#{CGI.escape(v.to_s)}" }.join("&")
end