python - Noisy Scipy Wavfile Output Issue -


i'm trying create .wav file using scipy.io.wavfile.write(), result noisy wav file, have tryed inotebook same result, here code:

import numpy np scipy.io import wavfile  x= np.arange(25600.0) sig= np.sin(2*np.pi*(1250.0/10000.0)*x)   def makewav(data,outfile,samplerate):     wavfile.write(outfile,samplerate,data)  makewav(sig,'foo.wav',44100) 

it happens when try generate pure tones. problem when reading .wav whith scipy.io.wavfile.read() , writing again scipy.io.wavfile.write().

according this documentation should output integer values, , have floating point data should have convert them first.

the method:     scipy.io.wavfile.write(filename, rate, data)[source]  argument:     data ndarray 1-d or 2-d numpy array of integer data-type. 

to convert data, try use code:

data=np.int16(sig/np.max(np.abs(sig)) * 32767) 

check out more in answer.


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -