strands.experimental.bidi.io.audio
Send and receive audio data from devices.
Reads user audio from input device and sends agent audio to output device using PyAudio. If a user interrupts the agent, the output buffer is cleared to stop playback.
Audio configuration is provided by the model via agent.model.config[“audio”].
_BidiAudioBuffer
Section titled “_BidiAudioBuffer”class _BidiAudioBuffer()Defined in: src/strands/experimental/bidi/io/audio.py:26
Buffer chunks of audio data between agent and PyAudio.
__init__
Section titled “__init__”def __init__(size: int | None = None)Defined in: src/strands/experimental/bidi/io/audio.py:32
Initialize buffer settings.
Arguments:
size- Size of the buffer (default: unbounded).
def start() -> NoneDefined in: src/strands/experimental/bidi/io/audio.py:40
Setup buffer.
def stop() -> NoneDefined in: src/strands/experimental/bidi/io/audio.py:45
Tear down buffer.
def put(chunk: bytes) -> NoneDefined in: src/strands/experimental/bidi/io/audio.py:56
Put data chunk into buffer.
If full, removes the oldest chunk.
def get(byte_count: int | None = None) -> bytesDefined in: src/strands/experimental/bidi/io/audio.py:71
Get the number of bytes specified from the buffer.
Arguments:
-
byte_count- Number of bytes to get from buffer.- If the number of bytes specified is not available, the return is padded with silence.
- If the number of bytes is not specified, get the first chunk put in the buffer.
Returns:
Specified number of bytes.
def clear() -> NoneDefined in: src/strands/experimental/bidi/io/audio.py:101
Clear the buffer.
_BidiAudioInput
Section titled “_BidiAudioInput”class _BidiAudioInput(BidiInput)Defined in: src/strands/experimental/bidi/io/audio.py:110
Handle audio input from user.
Attributes:
_audio- PyAudio instance for audio system access._stream- Audio input stream._buffer- Buffer for sharing audio data between agent and PyAudio.
__init__
Section titled “__init__”def __init__(config: dict[str, Any]) -> NoneDefined in: src/strands/experimental/bidi/io/audio.py:126
Extract configs.
async def start(agent: "BidiAgent") -> NoneDefined in: src/strands/experimental/bidi/io/audio.py:134
Start input stream.
Arguments:
agent- The BidiAgent instance, providing access to model configuration.
async def stop() -> NoneDefined in: src/strands/experimental/bidi/io/audio.py:160
Stop input stream.
__call__
Section titled “__call__”async def __call__() -> BidiAudioInputEventDefined in: src/strands/experimental/bidi/io/audio.py:173
Read audio from input stream.
_BidiAudioOutput
Section titled “_BidiAudioOutput”class _BidiAudioOutput(BidiOutput)Defined in: src/strands/experimental/bidi/io/audio.py:190
Handle audio output from bidi agent.
Attributes:
_audio- PyAudio instance for audio system access._stream- Audio output stream._buffer- Buffer for sharing audio data between agent and PyAudio.
__init__
Section titled “__init__”def __init__(config: dict[str, Any]) -> NoneDefined in: src/strands/experimental/bidi/io/audio.py:206
Extract configs.
async def start(agent: "BidiAgent") -> NoneDefined in: src/strands/experimental/bidi/io/audio.py:214
Start output stream.
Arguments:
agent- The BidiAgent instance, providing access to model configuration.
async def stop() -> NoneDefined in: src/strands/experimental/bidi/io/audio.py:239
Stop output stream.
__call__
Section titled “__call__”async def __call__(event: BidiOutputEvent) -> NoneDefined in: src/strands/experimental/bidi/io/audio.py:252
Send audio to output stream.
BidiAudioIO
Section titled “BidiAudioIO”class BidiAudioIO()Defined in: src/strands/experimental/bidi/io/audio.py:270
Send and receive audio data from devices.
__init__
Section titled “__init__”def __init__(**config: Any) -> NoneDefined in: src/strands/experimental/bidi/io/audio.py:273
Initialize audio devices.
Arguments:
-
**config- Optional device configuration:- input_buffer_size (int): Maximum input buffer size (default: None)
- input_device_index (int): Specific input device (default: None = system default)
- input_frames_per_buffer (int): Input buffer size (default: 512)
- output_buffer_size (int): Maximum output buffer size (default: None)
- output_device_index (int): Specific output device (default: None = system default)
- output_frames_per_buffer (int): Output buffer size (default: 512)
def input() -> _BidiAudioInputDefined in: src/strands/experimental/bidi/io/audio.py:288
Return audio processing BidiInput.
output
Section titled “output”def output() -> _BidiAudioOutputDefined in: src/strands/experimental/bidi/io/audio.py:292
Return audio processing BidiOutput.