-
Notifications
You must be signed in to change notification settings - Fork 0
/
class_demo.py
30 lines (27 loc) · 1.18 KB
/
class_demo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#coding:utf-8
from pydub.audio_segment import AudioSegment#pydub是python中用户处理音频文件的一个库
from scipy.io import wavfile
from python_speech_features.base import mfcc #傅里叶变换+梅尔倒谱
import pandas as pd
import numpy as np
import sys
#mfcc 包含了两个步骤,一个是傅里叶变换,一个是梅尔倒谱系数
song = AudioSegment.from_mp3('./data/music/当爱已成往事.mp3')#读入歌曲
# song_split = song[-30*1000 :]#切分歌曲
song.export('./data/music/当爱已成往事.wav', format= 'wav')#MP3到wav的转换
rate, data = wavfile.read('./data/music/当爱已成往事.wav')#每秒播放速度及数据
mf_feat = mfcc(data, rate, numcep = 13, nfft = 2048)#傅里叶变换速度每秒多少帧
print(mf_feat)
print(mf_feat.shape)
# df = pd.DataFrame(mf_feat)
# df.to_csv('./mfFeat.csv')
mm = np.mean(mf_feat, axis = 0)#隐含了时域上的相关性
mf = np.transpose(mf_feat)
mc = np.cov(mf) #原mf_feat矩阵列的协方差矩阵
# print(mc)
result = mm
# 举例说明diag矩阵x = np.arange(10, 19).reshape((3, 3))
for k in range(len(mm)):
result = np.append(result, np.diag(mc, k))
# print(result)
print(result)