Deepgram.Listen.WebSocket (Deepgram v0.1.0)

View Source

WebSocket client for live speech-to-text transcription.

This module provides a WebSocket client that can connect to Deepgram's live transcription service for real-time speech-to-text processing.

Summary

Functions

Builds query parameters for WebSocket URL.

Builds WebSocket headers for authentication.

Builds the WebSocket URL for live transcription.

Closes the WebSocket connection.

Finishes the transcription session.

Sends audio data to the WebSocket.

Sends a keepalive message to the WebSocket.

Starts a WebSocket connection for live transcription.

Types

state()

@type state() :: %{
  client: Deepgram.Client.t(),
  options: Deepgram.Types.Listen.live_options(),
  callback_pid: pid() | nil,
  connected: boolean(),
  keepalive_ref: reference() | nil
}

Functions

build_query_params(options)

Builds query parameters for WebSocket URL.

build_websocket_headers(client)

Builds WebSocket headers for authentication.

build_websocket_url(client, options)

Builds the WebSocket URL for live transcription.

close(websocket)

@spec close(pid()) :: :ok

Closes the WebSocket connection.

Parameters

  • websocket - The WebSocket process PID

Examples

iex> Deepgram.Listen.WebSocket.close(websocket)
:ok

finish(websocket)

@spec finish(pid()) :: :ok

Finishes the transcription session.

Parameters

  • websocket - The WebSocket process PID

Examples

iex> Deepgram.Listen.WebSocket.finish(websocket)
:ok

send_audio(websocket, audio_data)

@spec send_audio(pid(), binary()) :: :ok

Sends audio data to the WebSocket.

Parameters

  • websocket - The WebSocket process PID
  • audio_data - Binary audio data to send

Examples

iex> Deepgram.Listen.WebSocket.send_audio(websocket, audio_data)
:ok

send_keepalive(websocket)

@spec send_keepalive(pid()) :: :ok

Sends a keepalive message to the WebSocket.

Parameters

  • websocket - The WebSocket process PID

Examples

iex> Deepgram.Listen.WebSocket.send_keepalive(websocket)
:ok

start_link(client, options \\ %{}, callback_pid \\ nil)

@spec start_link(
  Deepgram.Client.t(),
  Deepgram.Types.Listen.live_options(),
  pid() | nil
) ::
  {:ok, pid()} | {:error, any()}

Starts a WebSocket connection for live transcription.

Parameters

  • client - A Deepgram.Client struct
  • options - Live transcription options
  • callback_pid - Optional PID to receive messages (defaults to caller)

Examples

iex> client = Deepgram.new(api_key: "your-api-key")
iex> options = %{model: "nova-2", interim_results: true}
iex> {:ok, websocket} = Deepgram.Listen.WebSocket.start_link(client, options)
{:ok, #PID<...>}