Skip to content

Audio sources

Juan Coria edited this page Sep 2, 2022 · 2 revisions

Audio sources represent different ways in which audio chunks can be streamed. For example, audio may be received through a wav file, a microphone, a websocket, a YouTube video, etc.

In diart we chose to use ReactiveX (rx for short) and RxPY to implement streaming. However, diart aims to be fully compatible with any streaming library.

All audio sources are located under diart.sources and inherit from the abstract class AudioSource. They must implement a read() method that starts streaming audio chunks through the stream attribute, which is an rx subject. Keep in mind that read() is blocking, so you won't recover the control of execution until all chunks are emitted through the stream.

In the rest of this page we'll take a look at the available sources that you can use out-of-the-box.

Local files

TODO: This will change in version 0.6.

Audio files stored in your computer can be streamed with FileAudioSource. This source also does the chunking for you so it needs to know the chunk duration and the step between chunks.

Here we create an audio source for a file "recording.wav" and start streaming audio chunks of 5s with a step of 500ms:

from diart.sources import FileAudioSource

file_source = FileAudioSource(
    file="recording.wav",
    sample_rate=16000,
    chunk_duration=5,
    step_duration=0.5,
)

file_source.read()

Local microphone

Remote audio

Custom sources

Clone this wiki locally