Python中音频信号的频率确定

Python中音频信号的频率确定,python,numpy,audio,Python,Numpy,Audio,我有一个音频信号,它有不同频率的音调,这些音调被静音隔开。我必须提取这些音调,然后使用fft找到频率,并将其转换为赫兹,然后将它们保存在一个数组中 我想使用scipy,numpy进行fft计算。下面是我正在尝试的代码。不确定我是否走对了路 任何关于如何进行的建议都会很有帮助,或者您的任何其他想法都将不胜感激 import wave import struct import numpy as np sound_file = wave.open('Audio_1.wav', 'r') ## Ope

我有一个音频信号,它有不同频率的音调,这些音调被静音隔开。我必须提取这些音调,然后使用fft找到频率,并将其转换为赫兹,然后将它们保存在一个数组中

我想使用scipy,numpy进行fft计算。下面是我正在尝试的代码。不确定我是否走对了路

任何关于如何进行的建议都会很有帮助,或者您的任何其他想法都将不胜感激

import wave
import struct
import numpy as np

sound_file = wave.open('Audio_1.wav', 'r') ## Open Audio file
file_length = sound_file.getnframes() ## Find number of frames
print file_length
sound = np.zeros(file_length)
for i in range(file_length):
    data = sound_file.readframes(1)
    data = struct.unpack("<h", data)
    sound[i] = int(data[0])
sound = np.divide(sound, float(2**15))
print sound
Ap = np.pad(sound, (0,int(np.ceil(len(sound) / 11874.)) * 11874 - len(sound)), 'constant', constant_values=0)
Apr = Ap.reshape((len(Ap) // 11874, 11874))
print Apr
Apr.shape
print Apr.shape
array1=(Apr ** 2).sum(axis=1)
print array1
#print len(array1)
threshold =4700
result= np.array(filter(lambda x: x>= threshold, array1))
print result 

print len(result)
print np.where(array1>4700)
#print array1.shape
#print result.shape
#print sound.shape
#print Apr.shape
#fftoutput=np.fft.fft(result)
#print fftoutput
#print np.argsort(fftoutput)
导入波
导入结构
将numpy作为np导入
声音文件=wave.open('Audio_1.wav','r')35;#打开音频文件
file_length=sound_file.getnframes()##查找帧数
打印文件长度
声音=np.0(文件长度)
对于范围内的i(文件长度):
数据=声音文件。读框(1)

data=struct.unpack(“我很久以前做过类似的事情。这可能有助于查看我的,以获得一些线索。我很久以前做过类似的事情。这可能有助于查看我的,以获得一些线索。