pyrubberband icon indicating copy to clipboard operation
pyrubberband copied to clipboard

Can't pass flags (rbargs) with keyword but no value

Open justinsalamon opened this issue 4 years ago • 1 comments

Description

Some flags in rubberband are not followed by a value, e.g. --no-lamination or --pitch-hq. The current implementation always expects rbargs as pairs of keyword and argument (in dict format), making it impossible to use flags that don't take values.

Steps/Code to Reproduce

import pyrubberband

# Generate a random signal and time-stretch it
sr = 22050
y = np.random.randn(5 * sr)

y_stretch = pyrubberband.time_stretch(y, sr, rate=1.5, rbargs={"-c": "6"})  # works
y_stretch = pyrubberband.time_stretch(y, sr, rate=1.5, rbargs={"--pitch-hq": ""})  # fails
y_stretch = pyrubberband.time_stretch(y, sr, rate=1.5, rbargs={"--pitch-hq": " "})  # fails
y_stretch = pyrubberband.time_stretch(y, sr, rate=1.5, rbargs={"--pitch-hq": None})  # fails

Expected Results

Should be possible to call no-value flags such as --pitch-hq. Included some examples above of syntax that could be supported with dicts (e.g. None). Alternative dict could be replaced with e.g. tuple that can have either 1 or 2 elements.

Actual Results

---------------------------------------------------------------------------
CalledProcessError                        Traceback (most recent call last)
<ipython-input-45-8758af91c0ad> in <module>
      5 filename = '/Users/salamon/dev/scaper/tests/data/audio/foreground/human_voice/42-Human-Vocal-Voice-all-aboard_edit.wav'
      6 audio, sr = soundfile.read(filename)
----> 7 audio_pitch = pyrubberband.pitch_shift(audio, sr, 1, rbargs=params)
      8 Audio(data=audio_pitch.T, rate=sr)

~/dev/miniconda3/envs/scaper35/lib/python3.5/site-packages/pyrubberband/pyrb.py in pitch_shift(y, sr, n_steps, rbargs)
    255     rbargs.setdefault('--pitch', n_steps)
    256 
--> 257     return __rubberband(y, sr, **rbargs)

~/dev/miniconda3/envs/scaper35/lib/python3.5/site-packages/pyrubberband/pyrb.py in __rubberband(y, sr, **kwargs)
     72         arguments.extend([infile, outfile])
     73 
---> 74         subprocess.check_call(arguments, stdout=DEVNULL, stderr=DEVNULL)
     75 
     76         # Load the processed audio.

~/dev/miniconda3/envs/scaper35/lib/python3.5/subprocess.py in check_call(*popenargs, **kwargs)
    269         if cmd is None:
    270             cmd = popenargs[0]
--> 271         raise CalledProcessError(retcode, cmd)
    272     return 0
    273 

CalledProcessError: Command '['rubberband', '-q', '-c', '6', '--pitch-hq', ' ', '--pitch', '1', '/var/folders/j4/2cgkdym179b76zljmlm1d6yc0000gn/T/tmpu311s4a2.wav', '/var/folders/j4/2cgkdym179b76zljmlm1d6yc0000gn/T/tmpermm7whf.wav']' returned non-zero exit status 2

Versions

Darwin-18.2.0-x86_64-i386-64bit Python 3.5.6 |Anaconda, Inc.| (default, Aug 26 2018, 16:30:03) [GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] NumPy 1.18.2 SoundFile 0.9.0

justinsalamon avatar May 01 '20 17:05 justinsalamon

in the mean time you can just pass e.g. rbargs={'--realtime': '--realtime'}

eyaler avatar Oct 22 '21 07:10 eyaler