Deepgram.Speak.WebSocket (Deepgram v0.1.0)
View SourceWebSocket 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
@type state() :: %{ client: Deepgram.Client.t(), options: Deepgram.Types.Speak.speak_ws_options(), callback_pid: pid() | nil, connected: boolean() }
Functions
Builds query parameters for WebSocket URL.
Builds WebSocket headers for authentication.
Builds the WebSocket URL for live text-to-speech.
@spec clear(pid()) :: :ok
Clears the current synthesis buffer.
Parameters
websocket
- The WebSocket process PID
Examples
iex> Deepgram.Speak.WebSocket.clear(websocket)
:ok
@spec close(pid()) :: :ok
Closes the WebSocket connection.
Parameters
websocket
- The WebSocket process PID
Examples
iex> Deepgram.Speak.WebSocket.close(websocket)
:ok
@spec flush(pid()) :: :ok
Flushes the current synthesis buffer.
Parameters
websocket
- The WebSocket process PID
Examples
iex> Deepgram.Speak.WebSocket.flush(websocket)
:ok
Sends text to be synthesized to the WebSocket.
Parameters
websocket
- The WebSocket process PIDtext
- Text to synthesize to speech
Examples
iex> Deepgram.Speak.WebSocket.send_text(websocket, "Hello, world!")
:ok
@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
- ADeepgram.Client
structoptions
- Live synthesis optionscallback_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<...>}