Appearance
modules.audio.streaming.audio
Classes Diagram
Classes
SourceInterface
Inherits from: ABC
Abstract base class representing any audio source.
This interface defines the required methods for any audio source,
such as a file, GStreamer pipeline, or microphone, allowing the
application to receive channel-aligned audio frames via a callback.
Constructor
SourceInterface(self)
Members
_callback: Callable[[list], None] | None
Methods
set_callback(self, callback: Callable[[list], None])
Register a callback to receive audio frames.
Args:
callback (Callable[[list], None]): A function that accepts a list
of channel-aligned audio frames. This function will be called
whenever new audio data is available.
start(self)
Start producing audio data.
Subclasses must implement this method to begin streaming or generating
audio frames. Audio data should be delivered by calling _emit(data).
stop(self)
Stop producing audio data and release any resources.
Subclasses must implement this method to cleanly stop the audio source,
ensuring that no further callbacks are invoked.
_emit(self, data: list)
Deliver audio data to the registered callback.
This helper should be used by subclasses to send new audio frames
to the consumer.
Args:
data (list): A list of channel-aligned audio frames.
pts (int): The presentation timestamp associated with the audio data.
Source
Inherits from: SourceInterface
Threaded implementation base class for continuous audio sources.
Provides a background thread mechanism to poll or generate audio frames
in a loop, delivering them through the _callback mechanism.
Constructor
Source(self)
Members
_thread
_continue
Methods
start(self)
@override
Start the audio source background thread.
Launches the internal thread that runs _run in a loop. Subsequent
calls have no effect if the thread is already running.
_run(self)
Background thread loop to continuously produce or poll audio frames.
Subclasses must implement this method to: \
- Continuously generate or retrieve audio frames. \
- Call
self._emit(data)whenever new frames are ready.
This method runs in a separate thread whenstart()is called.
stop(self)
@override
Stop the background audio thread.