perform a voice-based sentiment analysis using python.
In this project, we’re going to use two libraries in python.
The first one is the Vader sentiment package and the second one is the
speech recognition library in python.
Both two are open source libraries; you can use these packages an unlimited
number of times.
Sentiment analysis (or opinion mining) is a natural language processing technique
used to determine whether data is positive, negative, or neutral. Here the data means
your comments about any particular product or a review kind of thing.
For example, Take a company like Amazon that sells so many products to people.
And if you want to buy any product from amazon the first thing you will search for
the reviews about the product. The reviews are very important
and they will give an impression about the
product to the buyer.
Companies like Amazon are using the sentiment analysis method to give
the product rating. It will be very helpful for the buyers
to understand more about the product.
The Internet is free for everyone and you can type anything about any particular
product on e-commerce sites. Customers express their thoughts and feelings
more openly than ever before, sentiment analysis is becoming an essential tool to
monitor and understand those opinions about the product. Automatically analyzing
customer feedback, such as opinions in survey responses, social media conversations,
and product ratings, allows brands to learn what makes customers happy or frustrated
so,that they can tune their products and services to meet their customers’ needs.
So this is what the sentiment analysis is
Why sentiment analysis is very important for business?
A company must release the customers' needed product and that is the sign of
good companies. The customers are the first priority to the MNC companies.
These companies are tracking the customers data. So Sentiment
analysis is extremely important for that cause because it helps to quickly understand
the overall opinions of their customers. If you understand your customers' needs
you can sell those products to your customers and it will be very helpful to grow your
business .So this is the simple concept about sentimental analysis.
Let’s start to code.
Basically sentiment analysis is a simple project in the field of Machine learning.
But this blog is not a machine learning subject here im using python library to do
this job.Sentiment analysis is a simple project in python.Suppose if you want the
machine learning concepts by applying in sentiment analysis comment down your
thoughts
So i will make this sentiment analysis project by applying the machine learning
concepts in python.
STEP 1:
pip install vadersentiment
pip install speech recognition
First you need to install a python package called Vader sentiment.So open your
command prompt and just type pip install vadersentiment.So this will help you to
install the library.
And you’ve to install the speech-recognition library so type
pip install speech-recognition this will install this library.
After installing the packages you need to import the vadersentiment library and
speech-recognition library on your IDE.
STEP 2:
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
import speech_recognition as sr
And create a variable called a recognizer and call the instance recognizer() this will
help to initiate the speech-recognition library.
STEP 3:
recognizer=sr.Recognizer()
with sr.Microphone() as source:
print('Clearing background noise...')
recognizer.adjust_for_ambient_noise(source,duration=1)
print('Waiting for your message...')
recordedaudio=recognizer.listen(source)
print('Done recording..')
Next we want to initiate our microphone for recording our voices.For that type
with sr.Microphone as source.Here we’re declaring
the instance microphone as source variable.And In this block
of code you’ve to clear your background noises.
In this library there is an option called adjust for ambient_noises.This is an object
and here just pass the parameter as your source.This object simply clears the
background noises before starting to record.
Now we’ve to record the voices for that
create variable recorded
audio and in this variable you need to pass the recognizer.listen object
and inside this pass your source.
These two statements are very important when doing the speech-recognition
related tasks on your project. Mainly these statements
help to increase the quality
of recording your voices.
STEP 4:
try:
print('Printing the message..')
text=recognizer.recognize_google(recordedaudio,language='en-US')
print('Your message:{}'.format(text))
except Exception as ex:
print(ex)
We finished the recording process in our code.Now you need to create a try block
and here create variable text and call recognize_google object.There are so many
APIs are available in this library.The recognize_google is a most used voice_recognizer
instance in this library.So I'm using this one to recognize my voices.And I created the
except block this will print any errors or exception in our code.
Now we finished the speech_recognition tasks.Let’s write the code for the
sentiment analysis.
STEP 5:
#Sentiment analysis
Sentence=[str(text)]
analyser=SentimentIntensityAnalyzer()
for i in Sentence:
v=analyser.polarity_scores(i)
print(v)
Declare a variable called sentence and make sure this variable must be a list datatype
.If you’re passing the stand-alone string it will take each character and do the analysis
with each character that is present on the string.
It’s not useful one when we do this.Create a list in sentence variable and pass
the str(text) this is the correct form.
And create a variable analyser and call the instance sentimentInstentsityAnalyzer().
Next we’ve to traverse the list.If you want to perform the sentiment analysis on
single sentence you don’t need to use the list and forloop condition.
If you want to do the sentiment analysis for a group of sentences then this will be
the optimal way to analyze the sentence.And create a variable V and in this variable
you need to call the analyzer.polarity_scores.The polarity scores are very important to
determine whether the sentence is positive or negative or neutral one.And in this
object pass the sentence variable.
So that’s all about this code, let's run this program.
When you run this program you will get the output like positive, negative or neutral.
Based on these category values you can easily predict whether you are telling a
positive comment or negative comment or neutral comment.
Thanks for reading this article💗
Full code :Voice based sentiment Analysis
You are doing well ��
ReplyDeleteThanks for providing this ����
Keep it up ��
Thanks
Delete