29-语音识别与图像识别的基础
-- coding: utf-8 --
from future import unicode_literals
import numpy as np
import numpy.fft as nf
import scipy.io.wavfile as wf
import matplotlib.pyplot as mp
读取音频文件
sample_rate, sigs = wf.read('../data/freq.wav')
sigs = sigs / 2 ** 15
times = np.arange(len(sigs)) / sample_rate
计算频率
freqs = nf.fftfreq(sigs.size, 1 / sample_rate)
ffts = nf.fft(sigs)
pows = np.abs(ffts)
绘图展示
mp.figure('Audio', facecolor='lightgray')
mp.subplot(121)
mp.title('时间域')
mp.subplot(122)
mp.title('频率域')
用户评论