I have a problem in importing a wavefile into the Jupyter Notebook. I want to take the audio file from my desktop and perform fft on it. Does anyone know how to do this?
Asked
Active
Viewed 854 times
0
-
Take a look here: https://stackoverflow.com/questions/46972225/how-to-open-local-file-on-jupyter to see options on how to grab a file from your home dir. – Koshinae Apr 15 '19 at 11:51
1 Answers
1
You can follow the examples at http://people.csail.mit.edu/hubert/pyaudio/docs/.
I also want to do FFT analyses on WAV files and use this approach (only the essential bits shown): NOTE: this is a 16bit stereo WAV file, the "unpack" doesn't work with 24bit
import pyaudio
import wave
import numpy as np
import struct
wf = wave.open(sound_file_name, 'r')
n_frames = wf.getnframes()
all_frames = wf.readframes(n_frames)
wf.close()
value_list = []
for x in range(0, len(all_frames), 2):
value_list += struct.unpack('<h', all_frames[x:x+2])
two_channel_values = np.transpose(np.reshape(np.asanyarray(value_list), (int(len(value_list)/2), 2)))
Now you have an array of two vectors, each containing the amplitude values of one stereo channel.

HaraldCoder
- 71
- 3