1

I'm an all-around uber-noob when it comes to Python and Scipy, so bear with me.

I have a piece of code that reads in a wav file (2 second guitar chord recorded on proTools and exported as a 44100 Hz sound file called Dmaj7.wav) and then simply makes a copy of it called checkDmaj7.wav just for verification purposes.

Ideally, the two should sound identical. However, the copy file comes out sounding like pure white noise with no hint of the original sound. Here is the code:

    from numpy import *
    import scipy
    import scipy.io.wavfile as wave
    soundspath = 'C:/Nicks_Projects/DSP/Sounds/'
    def makewav(data, outfile, samplerate): 
            scaled = array(data, dtype = int16) #to coerce the data to int16 datatype
            wave.write(outfile, samplerate, scaled)
    def getwavdata(wavfile):   
            return wave.read(wavfile)[1]
    audio = getwavdata(soundspath + 'Dmaj7.wav')
    makewav(audio, soundspath + 'checkDmaj7.wav', 44100)

The code doesn't throw any errors. How can I solve this ?

Gautam
  • 7,868
  • 12
  • 64
  • 105
Nick
  • 437
  • 4
  • 9
  • 1
    Why did you feed the sampling rate yourself? The first object of the read tuple returns that. I'm not saying this is the problem, but, I think it's better to pass what the predefined functions return. – Sukrit Kalra Apr 29 '13 at 04:28
  • If you don't scale the data type, does it work then? – Lennart Regebro Apr 29 '13 at 04:29
  • [This](http://stackoverflow.com/questions/15595928/issues-with-scipy-io-wave-file-processing-after-applying-fourier-transforms) and [this](http://stackoverflow.com/questions/14574208/ifftfftaudio-is-just-noise) may help. My guess is your trouble is coming from the dtype, check what `audio.dtype` is, and make sure you match it in your output. – Jaime Apr 29 '13 at 06:58
  • Sukrit: true. I'll try using the first object to set the writer's sampling rate, but I already know it's 44100 because I checked that first object. I doubt that's the problem. – Nick Apr 30 '13 at 00:56
  • Lennart: I did try without scaling the data type. In fact, I started out without it, saw the problem, and thought I'd add that in just to see if it would solve it. – Nick Apr 30 '13 at 00:58
  • Jamie: I thought that too, and when I checked audio.dtype, it returned int32. So then, I did this: – Nick Apr 30 '13 at 01:38
  • Jamie: Ok, so audio.dtype is int32. My output is 'checkDmaj.wav'. I use the scipy.io.wavfile.write function to produce it, but that function has no dtype parameter. How do I match to my output to include that. – Nick Apr 30 '13 at 01:45

0 Answers0