资源简介
对中科大发布的中文语音情感数据库CASIA,提取了MFCC特征,过零率等特征,采用SVM分类,识别率很低,只适合初学者了解语音情感识别过程
代码片段和文件信息
import librosa
import os
from random import shuffle
import numpy as np
from sklearn import svm
import sklearn
path = r‘I:\CFL\cfl_python_speech_emotion\casia‘
EMOTION_LABEL = {‘angry‘: ‘1‘ ‘fear‘: ‘2‘ ‘happy‘: ‘3‘ ‘neutral‘: ‘4‘ ‘sad‘: ‘5‘ ‘surprise‘: ‘6‘}
def getData(mfcc_feature_num=16):
wav_file_path = []
person_dirs = os.listdir(path)
for person in person_dirs:
if person.endswith(‘.txt‘):
continue
emotion_dir_path = os.path.join(path person)
emotion_dirs = os.listdir(emotion_dir_path)
for emotion_dir in emotion_dirs:
if emotion_dir.endswith(‘ini‘):
continue
emotion_file_path = os.path.join(emotion_dir_path emotion_dir)
emotion_files = os.listdir(emotion_file_path)
for file in emotion_files:
if not file.endswith(‘wav‘):
continue
wav_path = os.path.join(emotion_file_path file)
wav_file_path.append(wav_path)
shuffle(wav_file_path)#将语音文件随机排列
data_feature = []
data_labels = []
for wav_file in wav_file_path:
y sr = librosa.load(wav_file)
mfcc_feature = librosa.feature.mfcc(y sr n_mfcc=16)
zcr_feature = librosa.feature.zero_crossing_rate(y)
energy_feature = librosa.feature.rmse(y)
rms_feature=librosa.feature.rmse(y)
mfcc_feature = mfcc_feature.T.flatten()[:mfcc_feature_num]
zcr_feature = zcr_feature.flatten()
energy_feature = energy_feature.flatten()
rms_feature=rms_feature.flatten()
zcr_feature = np.array([np.mean(zcr_feature)])
energy_feature = np.array([np.mean(energy_feature)])
rms_feature=np.array([np.mean(rms_feature)])
data_feature.append(np.concatenate((mfcc_feature zcr_feature energy_featurerms_feature)))
data_labels.append(int(EMOTION_LABEL[wav_file.split(‘\\‘)[-2]]))
return np.array(data_feature) np.array(data_labels)
def test():
best_acc = 0
best_mfcc_feature_num = 0
for i in range(100 200):
相关资源
- 语音情感识别matlab源代码.zip
- python37_d.lib
- 基于python实现巴特沃斯低通滤波
- Python3+Opencv343环境搭建 dll load failed问
- 引导滤波_Cpp_Python.rar
- VS2010C++调用python报错无法打开包括文
- python wordcloud whl包
- linux 下 python调用c或者c++编写的代码使
- python35_d.lib
- python版本获取百度搜索结果页面的信
- 节点大小平衡树(Size Balanced Tree c++和
- pymssql-2.1.4-cp38-cp38-win_amd64.whl
- Python基础教程第3版中英文版+源码_超
- grpc-x86_64-1.27.2-2-any.zip
- 一种多尺度检测的KCF的python实现代码
- visualcppbuildtools_full.exe安装包
- 新编Windows API参考大全全中文、win32
- Microsoft Visual C++ 14.0
- 从C++导出类到Python
- Linux下C++ 与python人脸检测
- 讯飞TTS语音合成Python封装
- json-rpc协议C语言版
- 重排九宫广度优先
- c语言编译器python版)
评论
共有 条评论