开始使用免费开始使用

分析电话通话的情感

当您将音频文件转写为文本后,就可以在文本上执行自然语言处理。

在本练习中,我们将使用 NLTK 的 VADER(Valence Aware Dictionary and sEntiment Reasoner,情感分析工具)来分析 call_2.wav 的转写文本(文件)。

要完成转写,我们将使用之前创建的 transcribe_audio() 函数。

得到文本后,我们将使用 NLTKSentimentIntensityAnalyzer() 类来获取情感极性得分。

.polarity_scores(text) 会返回 pos(正向)、neu(中性)、neg(负向)和 compound 四个值。compound 是前面三个值的综合。数值越高,文本越偏正向;越低则越偏负向。

本练习是课程的一部分

Python 语音语言处理

查看课程

练习说明

  • 实例化一个 SentimentIntensityAnalyzer(),并将其保存到变量 sid
  • 转写目标通话文本并保存为 call_2_text
  • 打印 call_2_textpolarity_scores()

交互式实操练习

通过完成这段示例代码来试试这个练习。

from nltk.sentiment.vader import SentimentIntensityAnalyzer

# Create SentimentIntensityAnalyzer instance
sid = ____

# Let's try it on one of our phone calls
call_2_text = transcribe_audio(____)

# Display text and sentiment polarity scores
print(call_2_text)
print(sid.____(call_2_text))
编辑并运行代码