I was attempting to create a graph of frequencies in audio data using Matplotlib with the following code (not yet completed) in Google Colaboratory. I imported the numpy, matplotlib, and wave libraries (not shown).
obj = wave.open("(name).wav", "rb")
sample_freq = obj.getframerate()
n_samples = obj.getnframes()
signal_wave = obj.readframes(-1)
obj.close()
time_audio = int(n_samples / sample_freq)
print(time_audio) # time audio
print(n_samples)
signal_array = np.frombuffer(signal_wave, dtype=np.int16)
times = np.linspace(0, time_audio, num=n_samples)
print(times)
plt.figure(figsize=(15,5))
plt.plot(times, signal_array)
and then some labeling of the axes etc. However, when I ran this code, I kept getting a syntax error. I'm not sure why, and I spent quite a bit of time trying to debug but couldn't find the obvious place of the syntax error. What am I doing wrong?