I have a sequence generated by an LSTM which I'm trying to save to disk as an audio file. I tried several libraries but none of them seem to produce working audiofiles.
The sequence I'm working with are float values between -1 and 1.
Example: [ 0.1772334 0.1772334 0.1772334 ... -0.1110365 -0.1110365 -0.1110365]
Using sd.play()
works fine (my sequence is just some white noise for now). But the files written to disk do not work, none of these work. And sd.playrec()
throws an error.
import numpy as np
import sounddevice as sd
import soundfile as sf
import librosa
import scipy
seq = np.load("Sequence.npy")
#Works
sd.play(seq, samplerate = 4000, blocking = True)
#Doesn't work
librosa.output.write_wav('LibrosaSequence.wav', seq, sr = 4000, norm = [-1,1])
scipy.io.wavfile.write('ScipySequence.wav', 4000, seq)
file4000 = sd.playrec(seq, samplerate = 4000, channels = 2, blocking = True)
sf.write("file4000.wav", file4000, sampling_frequency = 4000)