0

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)

11
  • what is the error ? Commented Jun 17, 2019 at 6:15
  • did you check this: stackoverflow.com/questions/10357992/… ? Commented Jun 17, 2019 at 6:15
  • @PV8 So I should scale the floats to integers? since the scipy function only works for integers? What If I don't want to lose precision? The error is: sounddevice.PortAudioError: Error querying device -1 Commented Jun 17, 2019 at 6:17
  • 1
    for this you can try: scikits.audiolab,it is also in the post Commented Jun 17, 2019 at 6:18
  • Alright! Thank you, I'll try it and if it works I'll delete my question. Commented Jun 17, 2019 at 6:19

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.