音频特征提取和傅里叶变换-Python实现

2021-01-14 11:39:33 浏览数 (1)

音频特征提取和傅里叶变换

代码语言:javascript复制
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# __author__ = "errrolyan"
# Date: 18-12-26
# Describe = "读取wav文件进行傅里叶变换获取频率值"

import wave as we
import numpy as np
import matplotlib.pyplot as plt
import sys

def wavread(path):
    wavfile = we.open(path, "rb")
    params = wavfile.getparams()
    nchannels, sampwidth, framesra, frameswav = params[:4]
    print("nchannels:%d" % nchannels)
    print("sampwidth:%d" % sampwidth)
    datawav = wavfile.readframes(frameswav)
    wavfile.close()
    datause = np.fromstring(datawav, dtype=np.short)
    if nchannels == 2:
        datause.shape = -1, 2
    datause = datause.T
    time = np.arange(0, frameswav) * (1.0 / framesra)
    return datause, time, nchannels

def fft(path):
    wavdata, wavtime, nchannels = wavread(path)
    df = 1
    freq = [df * n for n in range(0, len(wavdata))]
    c &

0 人点赞