Deepgram.Speak.WebSocket (Deepgram v0.1.0)

View Source

WebSocket client for live text-to-speech synthesis.

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

Summary

Functions

Builds query parameters for WebSocket URL.

Builds WebSocket headers for authentication.

Builds the WebSocket URL for live text-to-speech.

Clears the current synthesis buffer.

Closes the WebSocket connection.

Flushes the current synthesis buffer.

Sends text to be synthesized to the WebSocket.

Starts a WebSocket connection for live text-to-speech synthesis.

Types

state()

@type state() :: %{
  client: Deepgram.Client.t(),
  options: Deepgram.Types.Speak.speak_ws_options(),
  callback_pid: pid() | nil,
  connected: boolean()
}

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 text-to-speech.

clear(websocket)

@spec clear(pid()) :: :ok

Clears the current synthesis buffer.

Parameters

  • websocket - The WebSocket process PID

Examples

iex> Deepgram.Speak.WebSocket.clear(websocket)
:ok

close(websocket)

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

Closes the WebSocket connection.

Parameters

  • websocket - The WebSocket process PID

Examples

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

flush(websocket)

@spec flush(pid()) :: :ok

Flushes the current synthesis buffer.

Parameters

  • websocket - The WebSocket process PID

Examples

iex> Deepgram.Speak.WebSocket.flush(websocket)
:ok

send_text(websocket, text)

@spec send_text(pid(), String.t()) :: :ok

Sends text to be synthesized to the WebSocket.

Parameters

  • websocket - The WebSocket process PID
  • text - Text to synthesize to speech

Examples

iex> Deepgram.Speak.WebSocket.send_text(websocket, "Hello, world!")
:ok

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

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

Starts a WebSocket connection for live text-to-speech synthesis.

Parameters

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

Examples

iex> client = Deepgram.new(api_key: "your-api-key")
iex> options = %{model: "aura-2-thalia-en", encoding: "linear16"}
iex> {:ok, websocket} = Deepgram.Speak.WebSocket.start_link(client, options)
{:ok, #PID<...>}