Class: Vapi::FallbackCustomTranscriber

Inherits:
Object
  • Object
show all
Defined in:
lib/vapi_server_sdk/types/fallback_custom_transcriber.rb

Constant Summary collapse

OMIT =
Object.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server:, additional_properties: nil) ⇒ Vapi::FallbackCustomTranscriber

Parameters:

  • server (Vapi::Server)

    This is where the transcription request will be sent. Usage:

    1. Vapi will initiate a websocket connection with ‘server.url`.

    2. 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 } “`

    1. Vapi will send the audio data in 16-bit raw PCM format as binary frames.

    2. 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::FallbackCustomTranscriber.pcmBufferpcmBuffer.length`); } else { console.log(’Received message:‘, JSON.parse(data.toString())); } }); “`

    1. You will respond with transcriptions as you have them. Format:

    “‘ { “type”: “transcriber-response”, “transcription”: “Hello, world!”, “channel”: “customer” | “assistant” } “`

  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



86
87
88
89
90
# File 'lib/vapi_server_sdk/types/fallback_custom_transcriber.rb', line 86

def initialize(server:, additional_properties: nil)
  @server = server
  @additional_properties = additional_properties
  @_field_set = { "server": server }
end

Instance Attribute Details

#additional_propertiesOpenStruct (readonly)

Returns Additional properties unmapped to the current class definition.

Returns:

  • (OpenStruct)

    Additional properties unmapped to the current class definition



44
45
46
# File 'lib/vapi_server_sdk/types/fallback_custom_transcriber.rb', line 44

def additional_properties
  @additional_properties
end

#serverVapi::Server (readonly)

Returns This is where the transcription request will be sent. Usage:

  1. Vapi will initiate a websocket connection with ‘server.url`.

  2. 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 } “`

  1. Vapi will send the audio data in 16-bit raw PCM format as binary frames.

  2. 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::FallbackCustomTranscriber.pcmBufferpcmBuffer.length`); } else { console.log(’Received message:‘, JSON.parse(data.toString())); } }); “`

  1. You will respond with transcriptions as you have them. Format:

“‘ { “type”: “transcriber-response”, “transcription”: “Hello, world!”, “channel”: “customer” | “assistant” } “`.

Returns:

  • (Vapi::Server)

    This is where the transcription request will be sent. Usage:

    1. Vapi will initiate a websocket connection with ‘server.url`.

    2. 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 } “`

    1. Vapi will send the audio data in 16-bit raw PCM format as binary frames.

    2. 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::FallbackCustomTranscriber.pcmBufferpcmBuffer.length`); } else { console.log(’Received message:‘, JSON.parse(data.toString())); } }); “`

    1. You will respond with transcriptions as you have them. Format:

    “‘ { “type”: “transcriber-response”, “transcription”: “Hello, world!”, “channel”: “customer” | “assistant” } “`



42
43
44
# File 'lib/vapi_server_sdk/types/fallback_custom_transcriber.rb', line 42

def server
  @server
end

Class Method Details

.from_json(json_object:) ⇒ Vapi::FallbackCustomTranscriber

Deserialize a JSON object to an instance of FallbackCustomTranscriber

Parameters:

  • json_object (String)

Returns:



96
97
98
99
100
101
102
103
104
105
106
# File 'lib/vapi_server_sdk/types/fallback_custom_transcriber.rb', line 96

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
  new(server: server, 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.

Parameters:

  • obj (Object)

Returns:

  • (Void)


121
122
123
# File 'lib/vapi_server_sdk/types/fallback_custom_transcriber.rb', line 121

def self.validate_raw(obj:)
  Vapi::Server.validate_raw(obj: obj.server)
end

Instance Method Details

#to_json(*_args) ⇒ String

Serialize an instance of FallbackCustomTranscriber to a JSON object

Returns:

  • (String)


111
112
113
# File 'lib/vapi_server_sdk/types/fallback_custom_transcriber.rb', line 111

def to_json(*_args)
  @_field_set&.to_json
end