pyrubberband

repository·main·Indexed 42 days ago

https://github.com/bmcfee/pyrubberband

A lightweight Python wrapper for the Rubberband command-line tool, providing capabilities for pitch-shifting and time-stretching audio signals via functions like time_stretch().

Tokens
392
Snippets
2
Records
2
Agent score
3%

What's inside pyrubberband

  1. Install Rubberband on OS X

    main

    pyrubberband is a Python wrapper for the rubberband command-line tool. To use it on macOS, you must install the rubberband library via Homebrew using the following command:

    brew install https://gist.githubusercontent.com/faroit/b67c1708cdc1f9c4ddc9/raw/942bbedded22f05abab0d09b52383e7be4aee237/rubberband.rb
  2. Time-stretch audio with time_stretch()

    main

    Use pyrb.time_stretch(y, sr, ratio, rbargs=None) to change the playback speed of an audio signal without changing its pitch.

    • y: The audio signal (numpy array).
    • sr: The sampling rate.
    • ratio: The stretch factor (e.g., 2.0 for double speed).
    • rbargs: A dictionary of command-line arguments supported by the Rubberband CLI. Keys are the flags (e.g., '-c') and values are the argument values (e.g., '5'). For flags without values, use an empty string ''.
    import soundfile as sf
    import pyrubberband as pyrb
    
    # Read mono wav file
    y, sr = sf.read("test.wav")
    
    # Play back at double speed
    y_stretch = pyrb.time_stretch(y, sr, 2.0)
    
    # Use custom Rubberband CLI arguments
    y_stretch = pyrb.time_stretch(y, sr, 2.0, rbargs={'-c':'5', '--no_transients':''})