Class: Vapi::CustomTranscriber
- Inherits:
-
Object
- Object
- Vapi::CustomTranscriber
- Defined in:
- lib/vapi_server_sdk/types/custom_transcriber.rb
Constant Summary collapse
- OMIT =
Object.new
Instance Attribute Summary collapse
-
#additional_properties ⇒ OpenStruct
readonly
Additional properties unmapped to the current class definition.
-
#fallback_plan ⇒ Vapi::FallbackTranscriberPlan
readonly
This is the plan for voice provider fallbacks in the event that the primary voice provider fails.
-
#server ⇒ Vapi::Server
readonly
This is where the transcription request will be sent.
Class Method Summary collapse
-
.from_json(json_object:) ⇒ Vapi::CustomTranscriber
Deserialize a JSON object to an instance of CustomTranscriber.
-
.validate_raw(obj:) ⇒ Void
Leveraged for Union-type generation, validate_raw attempts to parse the given hash and check each fields type against the current object’s property definitions.
Instance Method Summary collapse
- #initialize(server:, fallback_plan: OMIT, additional_properties: nil) ⇒ Vapi::CustomTranscriber constructor
-
#to_json(*_args) ⇒ String
Serialize an instance of CustomTranscriber to a JSON object.
Constructor Details
#initialize(server:, fallback_plan: OMIT, additional_properties: nil) ⇒ Vapi::CustomTranscriber
92 93 94 95 96 97 98 99 |
# File 'lib/vapi_server_sdk/types/custom_transcriber.rb', line 92 def initialize(server:, fallback_plan: OMIT, additional_properties: nil) @server = server @fallback_plan = fallback_plan if fallback_plan != OMIT @additional_properties = additional_properties @_field_set = { "server": server, "fallbackPlan": fallback_plan }.reject do |_k, v| v == OMIT end end |
Instance Attribute Details
#additional_properties ⇒ OpenStruct (readonly)
Returns Additional properties unmapped to the current class definition.
48 49 50 |
# File 'lib/vapi_server_sdk/types/custom_transcriber.rb', line 48 def additional_properties @additional_properties end |
#fallback_plan ⇒ Vapi::FallbackTranscriberPlan (readonly)
Returns This is the plan for voice provider fallbacks in the event that the primary voice provider fails.
46 47 48 |
# File 'lib/vapi_server_sdk/types/custom_transcriber.rb', line 46 def fallback_plan @fallback_plan end |
#server ⇒ Vapi::Server (readonly)
Returns This is where the transcription request will be sent. Usage:
-
Vapi will initiate a websocket connection with ‘server.url`.
-
Vapi will send an initial text frame with the sample rate. Format:
“‘ { “type”: “start”, “encoding”: “linear16”, // 16-bit raw PCM format “container”: “raw”, “sampleRate”: {sampleRate}, “channels”: 2 // customer is channel 0, assistant is channel 1 } “`
-
Vapi will send the audio data in 16-bit raw PCM format as binary frames.
-
You can read the messages something like this:
“‘ ws.on(’message’, (data, isBinary) => { if (isBinary) { pcmBuffer = Buffer.concat([pcmBuffer, data]); console.log(‘Received PCM data, buffer size: $Vapi::CustomTranscriber.pcmBufferpcmBuffer.length`); } else { console.log(’Received message:‘, JSON.parse(data.toString())); } }); “`
-
You will respond with transcriptions as you have them. Format:
“‘ { “type”: “transcriber-response”, “transcription”: “Hello, world!”, “channel”: “customer” | “assistant” } “`.
43 44 45 |
# File 'lib/vapi_server_sdk/types/custom_transcriber.rb', line 43 def server @server end |
Class Method Details
.from_json(json_object:) ⇒ Vapi::CustomTranscriber
Deserialize a JSON object to an instance of CustomTranscriber
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/vapi_server_sdk/types/custom_transcriber.rb', line 105 def self.from_json(json_object:) struct = JSON.parse(json_object, object_class: OpenStruct) parsed_json = JSON.parse(json_object) if parsed_json["server"].nil? server = nil else server = parsed_json["server"].to_json server = Vapi::Server.from_json(json_object: server) end if parsed_json["fallbackPlan"].nil? fallback_plan = nil else fallback_plan = parsed_json["fallbackPlan"].to_json fallback_plan = Vapi::FallbackTranscriberPlan.from_json(json_object: fallback_plan) end new( server: server, fallback_plan: fallback_plan, additional_properties: struct ) end |
.validate_raw(obj:) ⇒ Void
Leveraged for Union-type generation, validate_raw attempts to parse the given
hash and check each fields type against the current object's property
definitions.
140 141 142 143 |
# File 'lib/vapi_server_sdk/types/custom_transcriber.rb', line 140 def self.validate_raw(obj:) Vapi::Server.validate_raw(obj: obj.server) obj.fallback_plan.nil? || Vapi::FallbackTranscriberPlan.validate_raw(obj: obj.fallback_plan) end |
Instance Method Details
#to_json(*_args) ⇒ String
Serialize an instance of CustomTranscriber to a JSON object
130 131 132 |
# File 'lib/vapi_server_sdk/types/custom_transcriber.rb', line 130 def to_json(*_args) @_field_set&.to_json end |