bmcfee / pyrubberband Goto Github PK
View Code? Open in Web Editor NEWpython wrapper for rubberband
License: ISC License
python wrapper for rubberband
License: ISC License
I followed this example that I found on Medium but it doesn't seem to work. When the playbackRate is increased, how can I correct the pitch so that it is the same as the original audio?
I have also tried the following by passing the output of time_stretch to the input of pitch_shift
# Play back at 1.5X speed
y_stretch = pyrb.time_stretch(audioData, sampleRate, audioSpeed)
# Play back two 1.5x tones
y_shift = pyrb.pitch_shift(y_stretch, sampleRate, audioSpeed)
soundfile.write(f'{tmp_name}.wav', y_shift, sampleRate, format='wav')
We currently route all output to DEVNULL
, but this isn't helpful when things break.
Instead, we should route to a logging file descriptor, and return the log when a runtime exception occurs.
After merging #4, this breaks api so we need to go up one.
I am new to this project and have been searching for time-stretching and pitch-shifting functionalities in python when I found this so, to test its working, I ran the "Example Usage" code from the pyrubberband github with one of my file but I got this error (image below).
I tried finding the solution to this on web, but had no leads as of now.
Windows-10-10.0.17134-SP0
Python 3.7.3 (default, Apr 24 2019, 15:29:51) [MSC v.1915 64 bit (AMD64)]
NumPy 1.16.4
SoundFile 0.9.0
I think the problem is with the OS (I'm using windows, but found OS X codes around the web), and by the way I also tried pip install rubberband-cli in the prompt, cuz the error said "rubberband-cli not installed" but that generated another error :-
Collecting rubberband-cli
ERROR: Could not find a version that satisfies the requirement rubberband-cli (from versions: none)
ERROR: No matching distribution found for rubberband-cli
Later, I downloaded rubberband cli from here and tried installing that as well but that too didn't help.
So finally I am here, hoping to get some positive response from the community. Thanks !
I've noticed that when you try to use rubberband on very low-samplerate signals (anything 210Hz and below) rubberband will hang.
These both hang:
y = np.random.rand(1024)
shifted = pyrubberband.pitch_shift(y=y, sr=210, n_steps=2)
stretched = pyrubberband.time_stretch(y=y, sr=210, rate=0.5)
These both work
y = np.random.rand(1024)
shifted = pyrubberband.pitch_shift(y=y, sr=211, n_steps=2)
stretched = pyrubberband.time_stretch(y=y, sr=211, rate=0.5)
The rubberband CLI has the same behavior; it hangs during the first studying pass at 99% CPU until you send it a break:
$ rubberband -d3 -t 2.0 /tmp/tmpzGl2Zt.wav /tmp/tmpzGl2Zt_2.wav
Using crispness level: 5 (Crisp monophonic instrumental)
Using time ratio 2 and frequency ratio 1
RubberBandStretcher::Impl::Impl: rate = 125, options = 16
configure: effective ratio = 2
configure: analysis window size = 8, synthesis window size = 8, fft size = 8, increment = 0 (approx output increment = 0)
configure: outbuf size = 8192
Window area: 0.5; synthesis window area: 0.5
FFT::FFT(8): using implementation: fftw
Not real time mode: prefilling
configure: effective ratio = 2
configure: analysis window size = 8, synthesis window size = 8, fft size = 8, increment = 0 (approx output increment = 0)
configure: outbuf size = 8192
Not real time mode: prefilling
configure: effective ratio = 2
configure: analysis window size = 8, synthesis window size = 8, fft size = 8, increment = 0 (approx output increment = 0)
configure: outbuf size = 8192
Pass 1: Studying...
Interestingly, this only seems to be an issue when rate
for time_stretch
< 1 or when n_steps
for pitch_shift
> 0, otherwise it runs fine.
I haven't had time to dig into the rubberband source and likely will not any time soon but I've noticed that passing the --window-long
flag will allow it to run to completion. IE these both run fine:
y = np.random.rand(1024)
shifted = pyrubberband.pitch_shift(y=y, sr=210, n_steps=2, rbargs={"-q":"--window-long"})
stretched = pyrubberband.time_stretch(y=y, sr=210, rate=0.5, rbargs={"-q":"--window-long"})
It's hacky, but would it make sense to simply add a conditional that would add the --window-long
flag to any sr
<= 210?
There's a lot of spam on the output whenever rubberband executes. We should stop this.
extras_require
for testsSome 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.
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
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.
---------------------------------------------------------------------------
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
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
See this thread
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.