emotion2vec语音情感识别。

该模型准确性有待提高。

脚本具体实现如下:

from modelscope.pipelines import pipeline
from modelscope.utils.constant import Tasks
import os
import shutil
inference_pipeline = pipeline(
    task=Tasks.emotion_recognition,
    model="iic/emotion2vec_base_finetuned")

if True:
    file_ = 'emo/happy.mp3'
    rec_result = inference_pipeline(file_, granularity="utterance", extract_embedding=False)
    rec_result = rec_result[0]

    print("情绪识别音频文件:",file_)
    for  i in range(len(rec_result["labels"])):
        print("[{}] {} : {:.2f}".format(i,rec_result["labels"][i],rec_result["scores"][i]))

    # 使用max()函数找到列表中的最大值
    max_value = max(rec_result["scores"])

    # 找到所有最大值的索引
    max_indices = [index for index, value in enumerate(rec_result["scores"]) if value == max_value][0]
    # print(max_indices)
    print("\n -> 预测情绪:{} : {}".format(rec_result["labels"][max_indices],rec_result["scores"][max_indices]))

脚本执行log如下:

情绪识别音频文件: emo/happy.mp3
[0] 生气/angry : 0.00
[1] 厌恶/disgusted : 0.00
[2] 恐惧/fearful : 0.00
[3] 开心/happy : 1.00
[4] 中立/neutral : 0.00
[5] 其他/other : 0.00
[6] 难过/sad : 0.00
[7] 吃惊/surprised : 0.00
[8] <unk> : 0.00

 -> 预测情绪:开心/happy : 1.0

 ​​​

助力快速掌握数据集的信息和使用方式。

数据可以如此美好!

更多推荐