赞
踩
- import librosa
- import matplotlib.pyplot as plt
- import numpy as np
- import pywt
- import librosa.display
- wav, sr_ret = librosa.load('E:\PycharmProjects\pythonProject\AudioClassification-Pytorch-master\dataset/audio/fold1/1_001.wav',sr=48000,duration=0.1)
- # 连续小波变换
- wavename = 'morl'
- totalscal = 4
- fc = pywt.central_frequency(wavename) # 计算小波函数的中心频率
- cparam = 2 * fc * totalscal # 常数c
- scales = cparam / np.arange(totalscal, 1, -1) # 为使转换后的频率序列是一等差序列,尺度序列必须取为这一形式(也即小波尺度)
- [cwtmatr, frequencies] = pywt.cwt(wav, scales, wavename, 1.0 / sr_ret)
- # scatter = Scattering2D(cwtmatr,frequencies)
- # features =(scatter,wav)
- # print(features.shape)
- features = np.array(cwtmatr)
- # frames = np.array(frames)
- # print(features.shape)
- # features = plt.contourf(t, frequencies, abs(cwtmatr))
- # features = librosa.stft(y=wav, n_fft=1024, hop_length=None, win_length=None, window='hann')
- # features = librosa.amplitude_to_db(np.abs(librosa.stft(y=wav,n_fft=1024, hop_length=None, win_length=None, window='hann')), ref=np.max)
- # features = librosa.melspectrogram(y=wav,sr=sr, n_fft=400, n_mels=80, hop_length=160, win_length=400)
- # features = librosa.power_to_db(features, ref=1.0, amin=1e-10, top_db=None)
- # 归一化
- mean = np.mean(features, 0, keepdims=True)
- std = np.std(features, 0, keepdims=True)
- features = (features - mean) / (std + 1e-5)
- features = features.astype('float32')
- print(features)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。