# 在get_emotion函数中传入文本以及音频的路径即可实现情感分析
# 由于extract_audio_features函数一次仅能提取一个音频的特征,因此get_emotion函数一次仅能分析一个样本的情感
def get_emotion(sentence, audio_path):
text_feature = extract_text_features(sentence, text_model)
audio_feature = extract_audio_features(audio_path, audio_model)
output = emoe_model(text=text_feature, audio=audio_feature)
logits_c = output['logits_c']
emotion = torch.argmax(logits_c, dim=1).item()
emotion_dict = {0: '愤怒', 1: '厌恶', 2: '中性'} # (angry=0, disgusted=1, neutral=2)
print(f"预测的情感类别: {emotion_dict[emotion]}")
return emotion
# 调用示例如下
if __name__ == '__main__':
sentence = '喂,好是的,嗯,现在是可以通过了吗?然后可以,嗯,目前没有了,我等会儿下载吧。'
audio_path = 'data/3315758594578346_20240701093706_right_1.wav'
emotion = get_emotion(sentence, audio_path)
print(emotion)
YD_EMOE2
1 downloads
0 likes
on ModelScope
updated