In this video, I'll show you the solution of the project, which analyzes.
The mood of a speech from an audio file.
So we're going to convert the old you file into text first and then analyze that text.
We're going to do that in one single script.
As you may know from the previous videos in the course to make this work, you need to install the speech
recognition package.
So that's one in the.
This package will convert the audio file into text of the speech from the audio to text, and then we
do the necessary imports, the recognizer and the audio file, and then we essentially the recognizer
down here.
Then further we create an audio file.
So you see, I've uploaded this chili that way file in here, which sounds like this.
You can find this 1973 in the lecture resources of this file in Chile, ending the longest democratic
tradition in Latin America.
It was so I would say, the mood of this audio of this speech is negative, but let's see what the program
will see.
So at this point, what I'm doing is I'm creating this audio file and then use the recognizer that's
situated in here to load that audio file into the recognizer.
Once you do that, then the recognizer.
You can go here on indent from the with context manager and create the text variable points of the recognizer
and recognize a Google method.
And then you point to the old you that you extracted from the recognizer from that audio file using
the recognizer.
At this point, do we have access to the text and we can go ahead and analyze the mood of that text.
But first, we want to try it out to see the text is extracted correctly.
And it is.
So that's a text.
Now we can go further and analyze the moods of this text.
For that, we need an LTE cave, a natural language toolkit.
So we will need to do some other imports in here and put an SDK and from an altitude that sentiment
import sentiments intensity analyzer to be able to analyze the moods.
First, we need to download a dataset voter lexicon, which has a database of words and each words has
touched a mood.
So if it's a positive word or negative words, and then using this, we are able to tell if the text
is a general mood of a text is more positive or more negative than we instantiate.
The Sentiment Intensity Analyzer, which we input in here.
Then we are ready to find out of the school so the scores will look like this.
Let's bring it out.
So these are a range of coefficients.
You see, we have the negative coefficient, the zero point two and the neutral, it's you coefficient
0.7.
Positivity is very small and the components coefficient is minus 0.8.
So it's very close to minus one, which means it's it's a negative moods in the older file.
If it was closer to one, it would be very positive.
The compound coefficient.
So we that's now we can simply implement an f conditional such as if scores we extend the compound.
Value, so if the compound is greater than zero with printouts.
Positive speech else, Prince.
Negative speech, so that should tell us a final answer here.
If it's positive or negative, so it's a negative speech, obviously.
Now that would be a simple, simple, simple program to analyze the moods of the speech in an audio
file.
You can improve this even further.
You can create a graphical user interface or maybe a web app if you are after web development.
So in a graphical user interface, you could have an option to browse a file and then the user could
select of the audio file in the group.
And then you could press a button which runs this code so it analyzes the audio file.
It finds a mood, and it shows perhaps some text somewhere in the group.
So that would be next.
Very good exercise if you are off to graphical user interfaces.
Thank you for following this, and I'll talk to you later.