helpers#
- class voice_stream.AudioWithText(*, audio: bytes, text: str, audio_format: AudioFormat)#
Bases:
BaseModelRepresenting audio data along with its corresponding text. Used as the output of a text-to-speech step.
- audio: bytes#
The audio data.
- audio_format: AudioFormat#
The format of the audio.
- model_config: ClassVar[ConfigDict] = {}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_fields: ClassVar[dict[str, FieldInfo]] = {'audio': FieldInfo(annotation=bytes, required=True), 'audio_format': FieldInfo(annotation=AudioFormat, required=True), 'text': FieldInfo(annotation=str, required=True)}#
Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].
This replaces Model.__fields__ from Pydantic V1.
- text: str#
The corresponding text for the audio.
- class voice_stream.QueueAsyncIterator#
Bases:
objectAn asynchronous iterator that operates on its own queue.
This class implements an async iterator which allows asynchronous iteration over queued items. It uses an asyncio.Queue for storing items and provides a put method to add items to this queue. The iterator retrieves items from the queue in the order they were added.
Examples
>>> queue = queue_source() # With no input arguments, this returns a QueueAsyncIterator. >>> stream = queue >>> done = array_sink() >>> await queue_iter.put(1) >>> await queue_iter.put(2) >>> await queue_iter.put(EndOfStreaMarker) >>> out = await done >>> assert out == [1, 2]
- async put(item)#
Adds an item to the queue managed by this iterator.
- Parameters:
item (any type) – The item to be added to the queue.
- class voice_stream.QueueWithException#
Bases:
QueueA specialized asyncio.Queue that propagates exceptions to the consumers.
This queue enhances the standard asyncio.Queue by handling exceptions. When an exception is set in the queue via set_exception(), it is propagated to the consumers either when they call get() or get_nowait().
Examples
>>> queue = queue_source() >>> queue.put(1) >>> queue.put(2) >>> queue.set_exception(RuntimeError("Test Error")) >>> await array_sink(queue) Caught exception: Test Error
Notes
If an exception is set, it maintains its place in the queue. If there are existing items in the queue, those will be returned in calls to get() until all items in the queue when set_exception was called have been exhausted.
- async enqueue_iterator(async_iter: AsyncIterator)#
Enqueues items from an asynchronous iterator to the queue.
Parameters:#
- async_iterAsyncIterator
An asynchronous iterator whose items will be enqueued.
- async get()#
Remove and return an item from the queue.
If queue is empty, wait until an item is available.
- get_nowait()#
Remove and return an item from the queue.
Return an item if one is immediately available, else raise QueueEmpty.
- set_exception(exception: Exception)#
Sets an exception to be propagated to consumers.
When an exception is set, the EndOfStreamMarker is enqueued and when that marker is removed from the queue, the exception will be raised.