API Reference¶
This page provides an auto-generated summary of the KitchenSink Audio library’s public API.
Sources¶
Sources are responsible for acquiring audio data.
- class kitchensink.sources.base_source.BaseAudioSource[source]¶
Bases:
object
Abstract base class for audio sources.
An audio source is responsible for acquiring audio data from some origin (e.g., a network stream, a microphone) and forwarding it to a callable ‘sink’.
- __init__(sink, disconnect_callback=None, blocksize=None)[source]¶
Initializes the BaseAudioSource.
- Parameters:
sink (callable) – A callable (function or method) that will receive the audio chunks. It must accept one argument: a NumPy array of audio data.
disconnect_callback (callable, optional) – A callable that is invoked when the source is disconnected or stops. Defaults to None.
blocksize (int, optional) – The number of frames per chunk for the source to generate. If
None
, the source may attempt to use the sink’s preferred blocksize.
- class kitchensink.sources.network_audio_source.TCPServerAudioSource[source]¶
Bases:
BaseAudioSource
An audio source that listens for a single incoming TCP connection, receives audio data, processes it, and pushes it to a provided sink.
- __init__(sink, disconnect_callback=None, host='0.0.0.0', port=8123, gain_factor=1.0, blocksize=960)[source]¶
Initializes the TCPServerAudioSource.
- Parameters:
sink – A callable that accepts one argument (the audio chunk as a NumPy array).
disconnect_callback (callable, optional) – A callable that is invoked when a client disconnects.
host (str) – The host address to listen on.
port (int) – The port to listen on.
gain_factor (float) – Factor to amplify the incoming audio.
blocksize (int) – The number of frames per audio chunk.
- class kitchensink.sources.raw_websocket_audio_source.RawWebSocketServerAudioSource[source]¶
Bases:
BaseAudioSource
An audio source that listens for a single WebSocket client, receives raw binary audio messages, and forwards them to a sink. This component is optimized for performance and expects only audio data.
- __init__(sink, disconnect_callback=None, host='0.0.0.0', port=8765, blocksize=None)[source]¶
Initializes the RawWebSocketServerAudioSource.
- Parameters:
sink – Passed to BaseAudioSource.
disconnect_callback – Passed to BaseAudioSource.
host (str) – The host address to listen on.
port (int) – The port to listen on.
blocksize (int, optional) – The preferred blocksize for audio chunks. Note: This source processes whatever it receives.
- class kitchensink.sources.typed_websocket_audio_source.TypedWebSocketServerAudioSource[source]¶
Bases:
BaseAudioSource
An audio source that listens for a WebSocket client and handles typed JSON messages. It can process both audio streams and other message types like text or events.
Expected message format (JSON string): {
“type”: “audio” | “text” | “custom_event”, “payload”: “…”
} For “audio”, the payload should be a Base64-encoded string of the raw audio bytes.
- __init__(sink, disconnect_callback=None, on_message_callback=None, host='0.0.0.0', port=8765, blocksize=None)[source]¶
Initializes the TypedWebSocketServerAudioSource.
- Parameters:
sink – Passed to BaseAudioSource.
disconnect_callback – Passed to BaseAudioSource.
on_message_callback (callable, optional) – A function to call for non-audio messages. It receives two arguments: the message type (str) and the message payload (dict/str).
host (str) – The host address to listen on.
port (int) – The port to listen on.
blocksize (int, optional) – The preferred blocksize for audio chunks. Note: This source processes whatever it receives.
Sinks¶
Sinks are the destination for audio data.
- class kitchensink.sinks.base_sink.BaseAudioSink[source]¶
Bases:
object
Abstract base class for audio sinks.
An audio sink is a destination for audio data. It takes audio chunks (as NumPy arrays) and performs an action, such as playing them through speakers, writing them to a file, or broadcasting them over a network.
- __init__(sample_rate=16000, channels=1, dtype='int16', blocksize=None)[source]¶
Initializes the BaseAudioSink.
- Parameters:
sample_rate (int) – The sample rate of the audio (e.g., 16000 for speech).
channels (int) – The number of audio channels (e.g., 1 for mono).
dtype (str) – The data type of the audio samples (e.g., ‘int16’).
blocksize (int, optional) – The preferred number of frames per chunk
flow. (for this sink. A source can use this to optimize the data)
None (Defaults to)
- close()[source]¶
Signals the sink to gracefully stop its operations and clean up any resources. Sets an event that should be respected by any background processing loops.
- class kitchensink.sinks.network_audio_sink.TCPClientAudioSink[source]¶
Bases:
BaseAudioSink
An audio sink that connects to a TCP server and sends audio chunks.
- __init__(host, port, sample_rate=16000, channels=1, dtype='int16', blocksize=None)[source]¶
Initializes the TCPClientAudioSink.
- Parameters:
host (str) – The hostname or IP address of the server to connect to.
port (int) – The port of the server.
sample_rate – Passed to BaseAudioSink.
channels – Passed to BaseAudioSink.
dtype – Passed to BaseAudioSink.
blocksize – Passed to BaseAudioSink.
- class kitchensink.sinks.raw_websocket_audio_sink.RawWebSocketClientAudioSink[source]¶
Bases:
BaseAudioSink
An audio sink that connects to a WebSocket server and sends raw audio chunks as binary messages. This component is optimized for performance.
- __init__(uri, sample_rate=16000, channels=1, dtype='int16', blocksize=None)[source]¶
Initializes the RawWebSocketClientAudioSink.
- Parameters:
uri (str) – The WebSocket URI to connect to (e.g., “ws://localhost:8765”).
sample_rate – Passed to BaseAudioSink.
channels – Passed to BaseAudioSink.
dtype – Passed to BaseAudioSink.
blocksize – Passed to BaseAudioSink.
- class kitchensink.sinks.typed_websocket_audio_sink.TypedWebSocketClientAudioSink[source]¶
Bases:
BaseAudioSink
An audio sink that connects to a typed WebSocket server and sends both audio (as Base64 JSON) and other message types.
- __init__(uri, sample_rate=16000, channels=1, dtype='int16', blocksize=None)[source]¶
Initializes the TypedWebSocketClientAudioSink.
- Parameters:
uri (str) – The WebSocket URI to connect to (e.g., “ws://localhost:8765”).
sample_rate – Passed to BaseAudioSink.
channels – Passed to BaseAudioSink.
dtype – Passed to BaseAudioSink.
blocksize – Passed to BaseAudioSink.
- push_chunk(chunk)[source]¶
Receives an audio chunk, encodes it, and schedules it to be sent. This is designed to be called from a non-async (e.g., audio callback) thread.
- Parameters:
chunk (ndarray)