Title: Python, working with sound: librosa and pyrubberband conflict
Tags: python,librosa

Question: I have the following script that I was using to manipulate an mp3:
import librosa
import soundfile as sf
from playsound import playsound
from direct.showbase.ShowBase import ShowBase
#import pyrubberband as pyrb


filename = "music.mp3"
y, sr = librosa.load(filename)
tempo, beat_frames = librosa.beat.beat_track(y=y, sr=sr)

bars = []
bar_dif=[]
initial_beat = beat_frames[0]

for i in range(0,len(beat_frames)):
    if i != 0:
        bar_dif.append(beat_frames[i]-beat_frames[i-1])
    if i % 16 == 0:
        bars.append(beat_frames[i])

for i in range(0,len(bars)):
    if i != len(bars) - 1:
        start = bars[i]
        end = bars[i+1]+1
        start_sample = librosa.frames_to_samples(start)
        end_sample = librosa.frames_to_samples(end)
        y_cut = y[start_sample:end_sample]
        sf.write(f"bar_{i}.wav", y_cut, sr)
base = ShowBase()

#Section A
#sound = base.loader.loadSfx("bar_27.wav")
#sound.setLoop(True)
#sound.setPlayRate(1.5)
#sound.play()
#base.run()

#Section B
#stretched_samples, _ = sf.read("bar_27.wav")
#tempo_factor = 1.5
#stretched_samples = pyrb.time_stretch(stretched_samples, sr, tempo_factor)
#stretched_sound = base.loader.loadSfxData(stretched_samples.tobytes())
#stretched_sound.setLoop(True)
#stretched_sound.setLoop(True)
#stretched_sound.play()
#base.run()

Originally I just had section A up and running with no pyrubberband. The script at this stage split the song bar bars of 4. It would then play a loop of a specific bar. It would then speed the loop up. The issue with this is that it pitched my sample up, which I did not want.
I then decided to install pyrubberband to try to pitch shift the sample. Now I receive errors on the line y, sr = librosa.load(filename) (See below) I then decided to uninstall/delete pyrubberband / section B, put the problem still persists. I then uninstalled and reinstalled librosa and re-downloaded the mp3, but he problem still persists.
Have I broken my computer?
Traceback (most recent call last):
  File "C:\Users\Charlie\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\librosa\core\audio.py", line 176, in load
    y, sr_native = __soundfile_load(path, offset, duration, dtype)
  File "C:\Users\Charlie\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\librosa\core\audio.py", line 209, in __soundfile_load
    context = sf.SoundFile(path)
  File "C:\Users\Charlie\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\soundfile.py", line 740, in __init__
    self._file = self._open(file, mode_int, closefd)
  File "C:\Users\Charlie\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\soundfile.py", line 1264, in _open
    _error_check(_snd.sf_error(file_ptr),
  File "C:\Users\Charlie\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\soundfile.py", line 1455, in _error_check
    raise RuntimeError(prefix + _ffi.string(err_str).decode('utf-8', 'replace'))
RuntimeError: Error opening 'music.mp3': File contains data in an unknown format.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\Users\Charlie\Desktop\BeatMaker\beatmaker.py", line 12, in <module>
    y, sr = librosa.load(filename)
  File "C:\Users\Charlie\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\librosa\core\audio.py", line 178, in load
    except sf.SoundFileRuntimeError as exc:
AttributeError: module 'soundfile' has no attribute 'SoundFileRuntimeError'

Answer: I ended up fixing my script by reinstalling Python!