pedalboard icon indicating copy to clipboard operation
pedalboard copied to clipboard

AudioFile in input of AudioStream

Open adrienpl opened this issue 1 year ago • 2 comments

Hello guys,

I want to have the global latency of an audio stream (pedalbaord & VB-Cable). Is it possible to give a wav file in input of AudioStream instead of microphone ? Since i know the duration of the input wav file and i can hear the output Virtual Microphone , i want to calculate the theorical & real end time.

Is it possible to do something like this with pedalbaord ?

Thanks !

adrienpl avatar Feb 29 '24 12:02 adrienpl

@psobot Maybe this could be done with the use of JUCE’s AudioFormatReader?

Abyz08 avatar Mar 01 '24 13:03 Abyz08

Hi @adrienpl and @Dohg678!

Pedalboard doesn’t have a mechanism for this at the moment. I haven’t thought about a good API design for this just yet, but it should be possible to either put audio playback into the AudioStream class or to add a new class or function just to play a single buffer.

However, I’m not sure if this would solve your problem - what do you mean when you say that you want to measure the “global latency” of an audio stream?

psobot avatar Mar 04 '24 13:03 psobot

Hi again @adrienpl and @Dohg678,

The ability to write to (i.e.: playback) and read from (i.e.: record) audio devices has been added to the AudioStream class in v0.9.12. See the documentation for more details, but in a nutshell:

from pedalboard.io import AudioStream

# Play a chunk of audio to the default audio device:
with AudioFile("my_file.mp3") as f:
    ten_second_chunk = f.read(f.samplerate * 10)
    AudioStream.play(ten_second_chunk, f.samplerate)

...or something like:

# Play an audio file by looping through it in chunks:
with AudioStream(output_device=AudioStream.default_output_device_name) as stream:
    with AudioFile("my_audio_file.mp3") as f:
        while f.tell() < f.frames:
            # Decode and play 512 samples at a time:
            stream.write(f.read(512))

psobot avatar Jul 30 '24 21:07 psobot

Great thanks 👍

adrienpl avatar Jul 30 '24 21:07 adrienpl

Thanks 👍 That is exactly what i needed for one of my upcoming projects!

Abyz08 avatar Sep 11 '24 09:09 Abyz08