diart.sources#
Module Contents#
Classes#
Represents a source of audio that can start streaming via the stream property. |
|
Represents an audio source tied to a file. |
|
Audio source tied to a local microphone. |
|
Represents a source of audio coming from the network using the WebSocket protocol. |
|
Represents a source of audio that can start streaming via the stream property. |
|
Represents a source of audio that can start streaming via the stream property. |
- class diart.sources.AudioSource(uri, sample_rate)#
Bases:
abc.ABCRepresents a source of audio that can start streaming via the stream property.
- Parameters:
uri (Text) – Unique identifier of the audio source.
sample_rate (int) – Sample rate of the audio source.
- property duration: float | None#
The duration of the stream if known. Defaults to None (unknown duration).
- Return type:
Optional[float]
- abstract read()#
Start reading the source and yielding samples through the stream.
- abstract close()#
Stop reading the source and close all open streams.
- class diart.sources.FileAudioSource(file, sample_rate, padding=(0, 0), block_duration=0.5)#
Bases:
AudioSourceRepresents an audio source tied to a file.
- Parameters:
file (FilePath) – Path to the file to stream.
sample_rate (int) – Sample rate of the chunks emitted.
padding ((float, float)) – Left and right padding to add to the file (in seconds). Defaults to (0, 0).
block_duration (int) – Duration of each emitted chunk in seconds. Defaults to 0.5 seconds.
- property duration: float | None#
The duration of the stream if known. Defaults to None (unknown duration).
- Return type:
Optional[float]
- read()#
Send each chunk of samples through the stream
- close()#
Stop reading the source and close all open streams.
- class diart.sources.MicrophoneAudioSource(block_duration=0.5, device=None)#
Bases:
AudioSourceAudio source tied to a local microphone.
- Parameters:
block_duration (int) – Duration of each emitted chunk in seconds. Defaults to 0.5 seconds.
device (int | str | (int, str) | None) – Device identifier compatible for the sounddevice stream. If None, use the default device. Defaults to None.
- _read_callback(samples, *args)#
- read()#
Start reading the source and yielding samples through the stream.
- close()#
Stop reading the source and close all open streams.
- class diart.sources.WebSocketAudioSource(sample_rate, host='127.0.0.1', port=7007, key=None, certificate=None)#
Bases:
AudioSourceRepresents a source of audio coming from the network using the WebSocket protocol.
- Parameters:
sample_rate (int) – Sample rate of the chunks emitted.
host (Text) – The host to run the websocket server. Defaults to 127.0.0.1.
port (int) – The port to run the websocket server. Defaults to 7007.
key (Text | Path | None) – Path to a key if using SSL. Defaults to no key.
certificate (Text | Path | None) – Path to a certificate if using SSL. Defaults to no certificate.
- _on_message_received(client, server, message)#
- Parameters:
client (Dict[Text, Any]) –
server (websocket_server.WebsocketServer) –
message (AnyStr) –
- read()#
Starts running the websocket server and listening for audio chunks
- close()#
Close the websocket server
- send(message)#
Send a message through the current websocket.
- Parameters:
message (AnyStr) – Bytes or string to send.
- class diart.sources.TorchStreamAudioSource(uri, sample_rate, streamer, stream_index=None, block_duration=0.5)#
Bases:
AudioSourceRepresents a source of audio that can start streaming via the stream property.
- Parameters:
uri (Text) – Unique identifier of the audio source.
sample_rate (int) – Sample rate of the audio source.
streamer (torchaudio.io.StreamReader) –
stream_index (Optional[int]) –
block_duration (float) –
- read()#
Start reading the source and yielding samples through the stream.
- close()#
Stop reading the source and close all open streams.
- class diart.sources.AppleDeviceAudioSource(sample_rate, device='0:0', stream_index=0, block_duration=0.5)#
Bases:
TorchStreamAudioSourceRepresents a source of audio that can start streaming via the stream property.
- Parameters:
uri (Text) – Unique identifier of the audio source.
sample_rate (int) – Sample rate of the audio source.
device (str) –
stream_index (int) –
block_duration (float) –