Class: Telnyx::Lib::WebSocket::SpeechToTextStreamParams
- Inherits:
-
Object
- Object
- Telnyx::Lib::WebSocket::SpeechToTextStreamParams
- 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
-
#client_ref ⇒ String?
Client reference identifier.
-
#diarize ⇒ Boolean?
Enable speaker diarization.
-
#diarize_speakers ⇒ Integer?
Number of speakers for diarization.
-
#input_format ⇒ String?
The audio input format (e.g., “wav”, “mp3”, “raw”).
-
#interim_results ⇒ Boolean?
Enable interim/partial results.
-
#keywords ⇒ Array<String>?
Keywords to boost recognition.
-
#language ⇒ String?
The language code (e.g., “en-US”, “es-ES”).
-
#model ⇒ String?
Custom vocabulary or model name.
-
#profanity_filter ⇒ Boolean?
Enable profanity filtering.
-
#punctuate ⇒ Boolean?
Enable automatic punctuation.
-
#sample_rate ⇒ Integer?
Sample rate in Hz (e.g., 8000, 16000).
-
#transcription_engine ⇒ String?
The transcription engine to use (e.g., “Deepgram”, “Google”, “Telnyx”).
Class Method Summary collapse
-
.from_hash(options) ⇒ SpeechToTextStreamParams
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.
55 56 57 |
# File 'lib/telnyx/lib/websocket/speech_to_text_stream_params.rb', line 55 def client_ref @client_ref end |
#diarize ⇒ Boolean?
Returns Enable speaker diarization.
43 44 45 |
# File 'lib/telnyx/lib/websocket/speech_to_text_stream_params.rb', line 43 def diarize @diarize end |
#diarize_speakers ⇒ Integer?
Returns 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_format ⇒ String?
Returns 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_results ⇒ Boolean?
Returns 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 |
#keywords ⇒ Array<String>?
Returns Keywords to boost recognition.
52 53 54 |
# File 'lib/telnyx/lib/websocket/speech_to_text_stream_params.rb', line 52 def keywords @keywords end |
#language ⇒ String?
Returns 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 |
#model ⇒ String?
Returns 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_filter ⇒ Boolean?
Returns 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 |
#punctuate ⇒ Boolean?
Returns Enable automatic punctuation.
37 38 39 |
# File 'lib/telnyx/lib/websocket/speech_to_text_stream_params.rb', line 37 def punctuate @punctuate end |
#sample_rate ⇒ Integer?
Returns 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_engine ⇒ String?
Returns 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
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() params = new params.transcription_engine = [:transcription_engine] || ["transcription_engine"] params.language = [:language] || ["language"] params.input_format = [:input_format] || ["input_format"] params.sample_rate = [:sample_rate] || ["sample_rate"] params.interim_results = [:interim_results] || ["interim_results"] params.punctuate = [:punctuate] || ["punctuate"] params.profanity_filter = [:profanity_filter] || ["profanity_filter"] params.diarize = [:diarize] || ["diarize"] params.diarize_speakers = [:diarize_speakers] || ["diarize_speakers"] params.model = [:model] || ["model"] params.keywords = [:keywords] || ["keywords"] params.client_ref = [:client_ref] || ["client_ref"] params end |
Instance Method Details
#to_hash ⇒ Hash
Convert to a hash for URL encoding
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_string ⇒ String
Convert to URL query 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 |