Class: AssemblyAI::RealtimeClient

Inherits:
Object
  • Object
show all
Defined in:
lib/assemblyai/realtime/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_client:) ⇒ AssemblyAI::RealtimeClient

Parameters:



14
15
16
# File 'lib/assemblyai/realtime/client.rb', line 14

def initialize(request_client:)
  @request_client = request_client
end

Instance Attribute Details

#request_clientAssemblyAI::RequestClient (readonly)



10
11
12
# File 'lib/assemblyai/realtime/client.rb', line 10

def request_client
  @request_client
end

Instance Method Details

#create_temporary_token(expires_in:, request_options: nil) ⇒ AssemblyAI::Realtime::RealtimeTemporaryTokenResponse

Create a temporary authentication token for Streaming Speech-to-Text

Examples:

api = AssemblyAI::Client.new(
  environment: AssemblyAI::Environment::DEFAULT,
  base_url: "https://api.example.com",
  api_key: "YOUR_API_KEY"
)
api.realtime.create_temporary_token(expires_in: 480)

Parameters:

  • expires_in (Integer)

    The amount of time until the token expires in seconds

  • request_options (AssemblyAI::RequestOptions) (defaults to: nil)

Returns:



30
31
32
33
34
35
36
37
38
39
# File 'lib/assemblyai/realtime/client.rb', line 30

def create_temporary_token(expires_in:, request_options: nil)
  response = @request_client.conn.post do |req|
    req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
    req.headers["Authorization"] = request_options.api_key unless request_options&.api_key.nil?
    req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
    req.body = { **(request_options&.additional_body_parameters || {}), expires_in: expires_in }.compact
    req.url "#{@request_client.get_url(request_options: request_options)}/v2/realtime/token"
  end
  AssemblyAI::Realtime::RealtimeTemporaryTokenResponse.from_json(json_object: response.body)
end