Giter VIP home page Giter VIP logo

Comments (3)

psobot avatar psobot commented on July 21, 2024

Hi @rohancherukuri14!

You're correct, there isn't currently a way to do this with Pedalboard alone. I've proposed a potential change to the AudioStream class (see #317 (comment)) that would allow AudioStream to buffer audio in-memory, which could then be written to a file; but this hasn't been built yet.

If you need this functionality, I'd recommend using pyAudio and streaming the results into a buffer that you can then write with AudioFile.

from pedalboard.

rohancherukuri14 avatar rohancherukuri14 commented on July 21, 2024

Hi! Thank you for the quick response! How exactly would I do this? Would I specify the audio buffer as the output to the buffer? Or just append stream to the buffer?

For context, I'm using a pretty simple example:

input_device_name = 'External Microphone'
output_device_name = 'External Headphones'
start_time = time.time()

while True:
    with AudioStream(input_device_name, output_device_name, allow_feedback=True) as stream:

        stream.plugins.append(Chorus())
        stream.plugins.append(Distortion())
        stream.plugins.append(Reverb())
        
        while len(stream.plugins) > 0:
            del stream.plugins[0]

from pedalboard.

rohancherukuri14 avatar rohancherukuri14 commented on July 21, 2024

I also tried using the .process() method to write to an ndarray, but the buffer still has all zeroes after recording:

from pedalboard.io import AudioStream
from pedalboard import Reverb, Chorus, Distortion
import soundcard as sc
import soundfile as sf
import time
import pyaudio
import numpy as np

input_device_name = 'External Microphone'
output_device_name = 'External Headphones'
start_time = time.time()

SAMPLE_RATE = 48000  # Hz
DURATION = 10  # seconds

start_time = time.time()
# Calculate the total number of samples
total_samples = int(SAMPLE_RATE * DURATION)

# Initialize a 32-bit floating point audio buffer for stereo (2 channels)
audio_buffer = np.zeros((total_samples, 2), dtype=np.float32)


while time.time() - start_time < DURATION:
    with AudioStream(input_device_name, output_device_name, allow_feedback=True) as stream:

        stream.plugins.append(Chorus())
        stream.plugins.append(Distortion())
        stream.plugins.append(Reverb())

        audio_buffer = stream.plugins.process(audio_buffer, SAMPLE_RATE, buffer_size=len(audio_buffer), reset=False)

        while len(stream.plugins) > 0:
            del stream.plugins[0]



print(audio_buffer[audio_buffer != 0])

from pedalboard.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.