YD_EMOE

5 downloads 0 likes on ModelScope updated

Model card

test.py中的get_emotion 函数为情感分析的模型接口

# 在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: '愤怒'}
    print(f"预测的情感类别: {emotion_dict[emotion]}")
    
# 调用示例如下
sentence = '喂,好是的,嗯,现在是可以通过了吗?然后可以,嗯,目前没有了,我等会儿下载吧。'
audio_path = './data/240773812285724574_20250304173005_right_1.wav'
emotion = get_emotion(sentence, audio_path)