Speech sentiment analysis

In this notebook we illustrate the power of pliers converters and extractors in a single pipeline. Specifically, we first run a state-of-the-art speech recognition API to transcribe the text of an audio clip. Then, we run a sentiment analysis API to extract the emotion ratings of the spoken words. The audio clip of this example is a short clip of an Obama administration press conference.

Note: the analysis is not using any audio features to assist emotion extraction. It is simply only using the text transcribed from the audio


In [1]:
from pliers.tests.utils import get_test_data_path
from os.path import join
from pliers.stimuli import AudioStim
from pliers.graph import Graph

In [2]:
# Configure our stimulus and extraction graph
stim = AudioStim(join(get_test_data_path(), 'video', 'obama_speech.wav'))
nodes = [
    {
        'transformer':'IBMSpeechAPIConverter', 
        'parameters':{'resolution':'phrases'}, 
        'children':[
            {
                'transformer':'IndicoAPITextExtractor',
                'parameters':{'models':['emotion']}
            }
        ]
    }
]
graph = Graph(nodes)

Parameters:

IBMSpeechAPIConverter - resolution specifies how we should chunk the text; using phrases provides better results for emotion analysis, as opposed to word-by-word analysis

IndicoAPITextExtractor - models specifies which analysis models to run using the Indico API; 'emotion' will give back five emotion ratings (anger, joy, fear, sadness, surprise) of the text


In [3]:
results = graph.run(stim)
results


Out[3]:
stim history filename class onset IndicoAPITextExtractor
emotion_anger emotion_joy emotion_fear emotion_sadness emotion_surprise
0 AudioStim->IBMSpeechAPIConverter/ComplexTextSt... None ComplexTextStim 0.99 0.069150 0.446798 0.261152 0.119870 0.103030
1 AudioStim->IBMSpeechAPIConverter/ComplexTextSt... None ComplexTextStim 4.24 0.157051 0.218239 0.218792 0.188566 0.217352
2 AudioStim->IBMSpeechAPIConverter/ComplexTextSt... None ComplexTextStim 5.64 0.053322 0.599211 0.118703 0.085534 0.143229
3 AudioStim->IBMSpeechAPIConverter/ComplexTextSt... None ComplexTextStim 8.20 0.207950 0.215616 0.214244 0.176775 0.185416

In [ ]: