Class: AssemblyAI::AsyncRealtimeClient

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::AsyncRealtimeClient

Parameters:



48
49
50
# File 'lib/assemblyai/realtime/client.rb', line 48

def initialize(request_client:)
  @request_client = request_client
end

Instance Attribute Details

#request_clientAssemblyAI::AsyncRequestClient (readonly)



44
45
46
# File 'lib/assemblyai/realtime/client.rb', line 44

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:



64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/assemblyai/realtime/client.rb', line 64

def create_temporary_token(expires_in:, request_options: nil)
  Async do
    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
end