Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 1 addition & 14 deletions src/anam/_streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,20 +669,7 @@ def send_user_audio(
sample_rate: int,
num_channels: int,
) -> None:
"""Send raw user audio samples to Anam for processing.

This method accepts 16-bit PCM samples and adds them to the audio buffer for transmission via WebRTC.
The audio track is created lazily when first audio arrives.
Audio is only added to the buffer after the connection is established, to avoid accumulating stale audio.

Args:
audio_bytes: Raw audio data (16-bit PCM).
sample_rate: Sample rate of the input audio (Hz).
num_channels: Number of channels in the input audio (1=mono, 2=stereo).

Raises:
RuntimeError: If peer connection is not initialized.
"""
"""Send raw user audio samples to Anam for processing."""
if not self._peer_connection:
raise RuntimeError("Peer connection not initialized. Call connect() first.")
if num_channels != 1 and num_channels != 2:
Expand Down
29 changes: 29 additions & 0 deletions src/anam/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,35 @@ def create_agent_audio_input_stream(
raise SessionError("Not connected")
return self._client._streaming_client.create_agent_audio_input_stream(config)

def send_user_audio(
self,
audio_bytes: bytes,
sample_rate: int,
num_channels: int,
) -> None:
"""Send raw user audio samples to Anam for processing.

This method accepts 16-bit PCM samples and adds them to the audio buffer
for transmission via WebRTC. The audio track is created lazily when first
audio arrives. Audio is only added to the buffer after the connection is
established, to avoid accumulating stale audio.

Args:
audio_bytes: Raw audio data (16-bit PCM).
sample_rate: Sample rate of the input audio (Hz).
num_channels: Number of channels in the input audio (1=mono, 2=stereo).

Raises:
SessionError: If not connected.
"""
if not self._client._streaming_client:
raise SessionError("Not connected")
self._client._streaming_client.send_user_audio(
audio_bytes=audio_bytes,
sample_rate=sample_rate,
num_channels=num_channels,
)

def video_frames(self) -> AsyncIterator[VideoFrame]:
"""Get video frames as an async iterator.

Expand Down
Loading