Class: Vapi::CustomTranscriber

Inherits:
Object
  • Object
show all
Defined in:
lib/vapi_server_sdk/types/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:, fallback_plan: OMIT, additional_properties: nil) ⇒ Vapi::CustomTranscriber

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::CustomTranscriber.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” } “`

  • fallback_plan (Vapi::FallbackTranscriberPlan) (defaults to: OMIT)

    This is the plan for voice provider fallbacks in the event that the primary voice provider fails.

  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



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_propertiesOpenStruct (readonly)

Returns Additional properties unmapped to the current class definition.

Returns:

  • (OpenStruct)

    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_planVapi::FallbackTranscriberPlan (readonly)

Returns This is the plan for voice provider fallbacks in the event that the primary voice provider fails.

Returns:



46
47
48
# File 'lib/vapi_server_sdk/types/custom_transcriber.rb', line 46

def fallback_plan
  @fallback_plan
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::CustomTranscriber.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::CustomTranscriber.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” } “`



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

Parameters:

  • json_object (String)

Returns:



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.

Parameters:

  • obj (Object)

Returns:

  • (Void)


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

Returns:

  • (String)


130
131
132
# File 'lib/vapi_server_sdk/types/custom_transcriber.rb', line 130

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