#aarya tadvalkar#kgptalkie#nlp#nltk#real time sentiment analysis#speech to text#textblob

Real-Time Phone Call Sentiment Analysis

Build a Python pipeline that transcribes live microphone audio and classifies sentiment polarity in real time using NLTK and TextBlob.

May 22, 2026 at 9:45 AM7 min readFollowFollow (Hindi)

Topics You Will Master

Converting live microphone audio to text using Python's SpeechRecognition library
Analyzing sentiment polarity and subjectivity with TextBlob
Preprocessing and tagging text with NLTK for real-time NLP
Building a looped pipeline that captures and scores multiple audio utterances
Best For

Python developers who want to add real-time voice sentiment analysis to chatbots, call-center tools, or voice assistants — and are comfortable running pip installs in a terminal.

Expected Outcome

A working Python script that listens to your microphone, transcribes each spoken phrase with Google Speech Recognition, and immediately prints its sentiment polarity and subjectivity score.

Have you ever wondered what a phone call "feels like" in numbers? Sentiment analysis — the process of automatically determining whether a piece of text is positive, negative, or neutral — can answer that question, and Python makes it surprisingly easy to apply it in real time.

In this tutorial you will build a pipeline with two parts. The first part converts spoken audio from your microphone into text. The second part scores that text for sentiment using TextBlob — a lightweight NLP library with a simple API. Along the way you will also explore NLTK (Natural Language Toolkit), which provides the underlying language models TextBlob relies on.

Prerequisites: Python 3.x, TextBlob, NLTK, SpeechRecognition, PyAudio, and a working microphone.

Setting Up TextBlob and NLTK

Install TextBlob with pip:

PLAINTEXT
!pip install textblob

TextBlob is a Python library for processing textual data. It gives you a simple, readable API for common NLP tasks such as part-of-speech tagging, noun-phrase extraction, sentiment analysis, classification, and translation.

Install NLTK (Natural Language Toolkit) next:

PYTHON
!pip install nltk
import nltk

NLTK is a leading platform for building Python programs that work with human language data. It provides interfaces to over 50 corpora and lexical resources (including WordNet), plus libraries for classification, tokenization, stemming, tagging, parsing, and semantic reasoning.

Installing nltk with pip does not automatically download every resource. You need to fetch a few data packages separately. The three you need for this tutorial are punkt (sentence tokenizer), averaged_perceptron_tagger (POS tagger), and brown (corpus used by TextBlob):

PYTHON
nltk.download('punkt')
nltk.download('averaged_perceptron_tagger')
nltk.download('brown')

Each call returns True when the download succeeds:

PLAINTEXT
True

You can also open the NLTK downloader GUI to browse, update, or download additional packages:

PYTHON
nltk.download()

Exploring TextBlob Sentiment Features

Create a TextBlob object by passing a string to the blob alias. The variable tb is now a TextBlob instance you can query:

PYTHON
from textblob import TextBlob as blob
tb = blob('Hi, please like this post!')
tb
PYTHON
TextBlob("Hi, please like this post!")

Part-of-Speech Tagging

The tags property returns a list of (word, POS tag) tuples, where each tag is a standard Penn Treebank label:

  • NNP — proper noun, singular
  • NN — noun, singular
  • DT — determiner
  • IN — preposition or subordinating conjunction
PYTHON
tb.tags
OUTPUT
[('Hi', 'NNP'), ('please', 'NN'), ('like', 'IN'), ('this', 'DT'), ('post', 'NN')]

Noun Phrase Extraction

The noun_phrases property extracts multi-word noun phrases from the text:

PYTHON
tb.noun_phrases
PYTHON
WordList(['hi'])

Sentiment Scoring

The sentiment property returns a named tuple with two scores. Polarity is a float in the range [-1.0, 1.0], where -1.0 is very negative and 1.0 is very positive. Subjectivity is a float in the range [0.0, 1.0], where 0.0 is completely objective and 1.0 is completely subjective:

PYTHON
tb.sentiment
PYTHON
Sentiment(polarity=0.0, subjectivity=0.0)

The phrase "Hi, please like this post!" scores 0.0 polarity — TextBlob treats it as neutral. Try a phrase with a clear positive emotion:

PYTHON
tb = blob('I love this channel. There are many useful posts here!')
tb.sentiment
OUTPUT
Sentiment(polarity=0.4583333333333333, subjectivity=0.3666666666666667)

A polarity of 0.46 confirms a positive sentiment. The subjectivity of 0.37 means the statement is mostly factual with a mild personal opinion.

Setting Up Real-Time Voice Recording

To capture live audio you need two additional packages. Run these commands in your terminal (use administrator/elevated mode in Anaconda Prompt if on Windows):

PLAINTEXT
!pip install SpeechRecognition
PLAINTEXT
!conda install pyaudio

For a full walkthrough of the SpeechRecognition setup, watch the companion video:

Import the library:

PYTHON
import speech_recognition as sr

Transcribing and Scoring a Single Utterance

The Recognizer object manages audio capture, and sr.Microphone() opens your default input device. The recognize_google() method sends the recorded audio to Google's Speech-to-Text API and returns a transcript string. Set timeout=2 so the listener stops if there is no speech for two seconds:

PYTHON
r = sr.Recognizer()
with sr.Microphone() as source:
    print('Say Something...')
    audio = r.listen(source, timeout=2)
    try:
        text = r.recognize_google(audio)
        tb = blob(text)
        print(text)
        print(tb.sentiment)
    except:
        print('Sorry... Try again')

The output below shows a transcript scored with a slightly negative polarity (-0.02):

PLAINTEXT
Say Something...
these people are really very poor and I am going to kill everybody I I main they don't deserve to live in this country and then either deserve to live on the planet Earth
Sentiment(polarity=-0.02015151515151517, subjectivity=0.5283333333333333)

Running the Pipeline 10 Times

To simulate a sustained phone call, run the same capture-and-score loop 10 times. Each iteration waits up to 3 seconds for speech, transcribes it, and immediately prints the sentiment:

PYTHON
iter_num = 10
index = 0
while(index<iter_num):
    with sr.Microphone() as source:
        print()
        print('Say Something...')
        audio = r.listen(source, timeout=3)
        try:
            text = r.recognize_google(audio)
            tb = blob(text)
            print(text)
            print(tb.sentiment)
        except:
            print('Sorry... Try again')
        index = index + 1

The output below shows 10 consecutive utterances with their polarity and subjectivity scores. Notice how the scores shift with the emotional content of each phrase:

PLAINTEXT
Say Something...
hello hi baby what's up I am missing you so much
Sentiment(polarity=0.0, subjectivity=0.125)

Say Something...
do you know I love you so much and have anyone told you that you are the one of the most beautiful girl in the world
Sentiment(polarity=0.5125, subjectivity=0.575)

Say Something...
ok so have you are you done with your dinner are you going to have your dinner
Sentiment(polarity=0.5, subjectivity=0.5)

Say Something...
Informatica ok one thing do you know we we have a lot of the things common in between us we like like romantic movies and and you books except Raso these are the really great things between us
Sentiment(polarity=0.25, subjectivity=0.5625)

Say Something...
yes you are right my apology but do not there to tell me again otherwise I'll kill you also that you ok I also you with the gun in your head and in your heart and don't dare to talk to me like this ever
Sentiment(polarity=0.39285714285714285, subjectivity=0.5178571428571428)

Say Something...
but still I love you so much I hate you don't talk to me like this and I'll never call you back
Sentiment(polarity=-0.10000000000000002, subjectivity=0.5)

Say Something...
online now you see here in this sentence when I say that but still I love you so much I hate you and don't talk to me like this and I'll never call you now you can see here there is a negativity in this sentence and it is saying that yes there is any creativity in this sentence super have some 123456 and the 7th 7th time running so what I am talking here its Guna of course printed so let's get it printed and then we'll talk again
Sentiment(polarity=0.01111111111111109, subjectivity=0.7222222222222222)

Say Something...
Sorry... Try again

Say Something...
kidding and please do not mind I love you 3000 even I love you goodnight
Sentiment(polarity=0.5, subjectivity=0.6)

Say Something...
ok now you see here so this is there is polarity at this the positivity Heera 20.5 so this is how you see here our phone call is being converted into word text by using this lesson tutorial you can go and watch speech recognition in Python speed detection in Python at KGP talking you can search and you can get this otherwise I have already given the link for this this listen here you can watch from here as well here
Sentiment(polarity=0.5, subjectivity=0.5)

Polarity values range from -0.10 (the "I hate you / never call you back" phrase) up to 0.51 (the "I love you" compliment). The loop also gracefully handles one failed recognition attempt with Sorry... Try again.

Conclusion

In this tutorial you built a real-time sentiment analysis pipeline for audio. You installed and configured TextBlob and NLTK, explored part-of-speech tagging and noun-phrase extraction, and then connected Google's Speech Recognition API to score live microphone input. Running the loop 10 times showed how polarity fluctuates utterance-by-utterance in a realistic conversation.

Key takeaways:

  • TextBlob's sentiment property returns polarity ([-1, 1]) and subjectivity ([0, 1]) in a single call — no manual feature engineering required.
  • NLTK data packages (punkt, averaged_perceptron_tagger, brown) must be downloaded separately after installing the library.
  • sr.recognize_google() handles the heavy lifting of speech-to-text; wrapping calls in a try/except block keeps the pipeline running when audio is unclear.
  • Polarity alone does not capture sarcasm or context — it reflects the literal sentiment of the individual words TextBlob recognizes.
  • A simple while loop is enough to monitor sentiment continuously across multiple utterances.

Next steps:

Find this tutorial useful?

Subscribe to our YouTube channels for more practical production walk-throughs.

Discussion & Comments