Giter VIP home page Giter VIP logo

Comments (2)

psobot avatar psobot commented on May 23, 2024

Hi @psytron!

Pedalboard has its own AudioStream class that streams audio from an input device to an output device without passing the audio data through Python itself:

input_device_name = AudioStream.input_device_names[0]
output_device_name = AudioStream.output_device_names[0]
with AudioStream(input_device_name, output_device_name) as stream:
    # In this block, audio is streaming through `stream`!
    # Audio will be coming out of your speakers at this point.

    # Add plugins to the live audio stream:
    reverb = Reverb()
    stream.plugins.append(reverb)

    # Change plugin properties as the stream is running:
    reverb.wet_level = 1.0

    # Delete plugins:
    del stream.plugins[0]

It is technically possible to apply Pedalboard effects to live audio streams from other libraries like PyAudio, but I would strongly recommend against doing so: to pass the audio between any other library and Pedalboard, your code will implicitly take Python's Global Interpreter Lock, which will almost definitely cause dropped audio buffers, stuttering, or other audible errors at some point.

If you want to do so anyways, you'll have to:

  • Read the audio from PyAudio in a loop (or callback)
  • Convert the audio into 32-bit floating point on the range [-1, 1]
  • Pass that audio into your Pedalboard effect(s) as a numpy array, of shape (num_channels, num_samples), while also setting reset=False to ensure the audio stream is unbroken
  • Convert the resulting array back into whichever format PyAudio requires
  • Pass the resulting audio back into PyAudio

(But again; this will almost definitely stutter at some point, just due to how Python works under-the-hood.)

from pedalboard.

psytron avatar psytron commented on May 23, 2024

Thanks @psobot !!

Is there a way to solve the GIL issue you described by keeping the pedalboard on separate process?
Is there also another way to route the output stream of another process as virtual audio device or another method?

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.