Deepgram.Listen.WebSocket (Deepgram v0.1.0)
View SourceWebSocket 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
@type state() :: %{ client: Deepgram.Client.t(), options: Deepgram.Types.Listen.live_options(), callback_pid: pid() | nil, connected: boolean(), keepalive_ref: reference() | nil }
Functions
Builds query parameters for WebSocket URL.
Builds WebSocket headers for authentication.
Builds the WebSocket URL for live transcription.
@spec close(pid()) :: :ok
Closes the WebSocket connection.
Parameters
websocket
- The WebSocket process PID
Examples
iex> Deepgram.Listen.WebSocket.close(websocket)
:ok
@spec finish(pid()) :: :ok
Finishes the transcription session.
Parameters
websocket
- The WebSocket process PID
Examples
iex> Deepgram.Listen.WebSocket.finish(websocket)
:ok
Sends audio data to the WebSocket.
Parameters
websocket
- The WebSocket process PIDaudio_data
- Binary audio data to send
Examples
iex> Deepgram.Listen.WebSocket.send_audio(websocket, audio_data)
:ok
@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
@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
- ADeepgram.Client
structoptions
- Live transcription optionscallback_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<...>}