|  | 
 
| 
本帖最后由 hxiaoyuan 于 2023-3-22 17:29 编辑
x
马上注册,结交更多好友,享用更多功能^_^您需要 登录 才可以下载或查看,没有账号?立即注册  
 代码:
 
 复制代码import wave
import numpy as np
import matplotlib.pyplot as plt
fw = wave.open('test.wav','r')
soundInfo = fw.readframes(-1)
soundInfo = np.fromstring(soundInfo,np,int16)
f = fw.getframerate()
fw.close()
plt.subplot(211)
plt.plot(soundInfo)
plt.ylabel('Amplitude')
plt.title('wave from and spectrogram of test.wav')
plt.subplot(212)
plt.specgram(soundInfo,Fs = f ,scale_by_freq = True,sides = 'default')
plt.ylabel('Frequency')
plt.xlabel('time(seconds)')
plt.show()
 
 报错:
 
 复制代码Traceback (most recent call last):
  File "C:\Users\ASUS\Desktop\加油加油! !\实验\绘制语谱图\main.py", line 7, in <module>
    soundInfo = np.fromstring(soundInfo,np,int16)
NameError: name 'int16' is not defined
求问有没有方法解决?
 
 
那是 np.int16 你把点打成逗号了
 
 复制代码import wave
import numpy as np
import matplotlib.pyplot as plt
fw = wave.open('test.wav','r')
soundInfo = fw.readframes(-1)
soundInfo = np.fromstring(soundInfo,np.int16)
f = fw.getframerate()
fw.close()
plt.subplot(211)
plt.plot(soundInfo)
plt.ylabel('Amplitude')
plt.title('wave from and spectrogram of test.wav')
plt.subplot(212)
plt.specgram(soundInfo,Fs = f ,scale_by_freq = True,sides = 'default')
plt.ylabel('Frequency')
plt.xlabel('time(seconds)')
plt.show()
 | 
 |