Speech Recognition System
Speech Recognition System
Bachelor of Technology in
Computer Science and Engineering
by
Rajat Kushwaha – Roll No: 1809710081
ABSTRACT
Are you surprised about how the modern devices that are non-living things listen your voice,
not only this but they responds too. Yes,Its looks like a fantasy, but now-a-days technology
are doing the surprising things that were not possible in past. So guys, welcome to my new
tutorial Speech Recognition Python.This is a very awesome tutorial having lots of interesting
stuffs. In this tutorial we will learn about concept of speech recognition and it’s
implementation in python. So let’s gets started.
As the technologies are growing more rapidly and new features are emerging in this way
speech recognition is one of them. Speech recognition is a technology that have evolved
exponentially over the past few years. Speech recognition is one of the popular and best
feature in computer world. It have numerous applications that can boost convenience,
enhance security, help law enforcement efforts, that are the few examples. Let’s start
understanding the concept of speech recognition, it’s working and applications.
TABLE OF CONTENT
Title
ABSTRACT
TABLE OF CONTENT
CHAPTER 1: INTRODUCTION
CHAPTER 5: METHODOLOGY
REFERENCES
CHAPTER 1
INTRODUCTION
Speech Recognition is a process in which a computer or device record the speech of humans
and convert it into text format.
It is also known as Automatic Speech Recognition(ASR), computer speech recognition or
Speech To Text (STT).
Linguistics, computer science, and electrical engineering are some fields that are associated
with Speech Recognition.
Are you surprised about how the modern devices that are non-living things listen your voice,
not only this but they responds too. Yes,Its looks like a fantasy, but now-a-days technology
are doing the surprising things that were not possible in past. So guys, welcome to my new
tutorial Speech Recognition Python.This is a very awesome tutorial having lots of interesting
stuffs. In this tutorial we will learn about concept of speech recognition and it’s
implementation in python. So let’s gets started.
As the technologies are growing more rapidly and new features are emerging in this way
speech recognition is one of them. Speech recognition is a technology that have evolved
exponentially over the past few years. Speech recognition is one of the popular and best
feature in computer world. It have numerous applications that can boost convenience,
enhance security, help law enforcement efforts, that are the few examples. Let’s start
understanding the concept of speech recognition, it’s working and applications.
CHAPTER 2
LITERATURE REVIEW
Are you surprised about how the modern devices that are non-living things listen
your voice, not only this but they responds too. Yes,Its looks like a fantasy, but
now-a-days technology are doing the surprising things that were not possible in
past. So guys, welcome to my new tutorial Speech Recognition Python.This is a
very awesome tutorial having lots of interesting stuffs. In this tutorial we will learn
about concept of speech recognition and it’s implementation in python. So let’s
gets started.
As the technologies are growing more rapidly and new features are emerging in
this way speech recognition is one of them. Speech recognition is a technology
that have evolved exponentially over the past few years. Speech recognition is
one of the popular and best feature in computer world. It have numerous
applications that can boost convenience, enhance security, help law enforcement
efforts, that are the few examples. Let’s start understanding the concept of
speech recognition, it’s working and applications.
CHAPTER 3
PROBLEM FORMULATION
• first of all we will import speech_recognition as sr.
• Notice that we have speech_recognition in such format whereas earlier we have
installed it in this way SpeechRecognition , so you need to have a look around the cases
because this is case sensitive.
• Now we have used as notation because writing speech_recognition whole every time is
not a good way.
• Now we have to initialize r = sr.Recognizer() ,this will work as a recognizer to recognize
our voice.
• So, with sr.Microphone() as source: which means that we are initialising our source to
sr.Microphone ,we can also use some audio files to convert into text but in this tutorial i
am using Microphone voice.
• Next we will print a simple statement that recommend the user to speak anything.
• Now we have to use r.listen(source) command and we have to listen the source.So, it will
listen to the source and store it in the audio.
• It may happen some time the audio is not clear and you might not get it correctly ,so we
can put it inside the try and except block .
• So inside the try block, our text will be text = r.recognize_google(audio) ,now we have
various options like recognize_bing(),recognize_google_cloud(),recognize_ibm(), etc.But
for this one i am using recognize_google().And lastly we have to pass our audio.
• And this will convert our audio into text.
• Now we just have to print print(“You said : {}”.format(text)) ,this will print whatever you
have said.
• In the except block we can just write print(“Sorry could not recognize your voice”) ,this
will message you if your voice is not recorded clearly.
CHAPTER 4
PROPOSED WORK
Installing Libraries
we have to install two library for implementing speech recognition.
SpeechRecognition
PyAudio
Installing SpeechRecognition
Go to terminal and type
1
2
3
pip install SpeechRecognition
Installing PyAudio
Go to terminal and type
1
2
3
PyAudio provides Python bindings for PortAudio, the cross-platform audio I/O library. With
PyAudio, you can easily use Python to play and record audio on a variety of platforms, such
as GNU/Linux, Microsoft Windows, and Apple Mac OS X / macOS.
So this is the code for speech recognition in python.As you are seeing, it is quite simple and
easy.
Source Code:-
import pyttsx3
import speech_recognition as sr
import datetime
import wikipedia
import webbrowser
import os
import smtplib
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
print(voices[1].id)
engine.setProperty('voice', voices[0].id)
def speak(audio):
engine.say(audio)
engine.runAndWait()
def wishMe():
hour = int(datetime.datetime.now().hour)
if hour>=0 and hour<12:
speak("Good Morning!")
else:
speak("Good Evening!")
def takeCommand():
#It takes microphone input from the user and returns string output
r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening...")
r.pause_threshold = 1
audio = r.listen(source)
try:
print("Recognizing...")
query = r.recognize_google(audio, language='en-in')
print(f"User said: {query}\n")
except Exception as e:
# print(e)
print("Say that again please...")
return "None"
return query
if __name__ == "__main__":
wishMe()
while True:
# if 1:
query = takeCommand().lower()
# Logic for executing tasks based on query
if 'wikipedia' in query:
speak('Searching Wikipedia...')
query = query.replace("wikipedia", "")
results = wikipedia.summary(query, sentences=5)
speak("According to Wikipedia")
print(results)
speak(results)
apiai
assemblyai
google-cloud-speech
pockets
b. Prerequisites for Python Speech Recognition
You can use pip to install this-
>>> r=sr.Recognizer()
With Recognizer, we have a method for each API
>>> r.recognize_google(audio)
CHAPTER 6
CONCLUSION AND FUTURE SCOPE
Did you see how easy it was to recognize speech with Python? The APIs made it possible.
Well, why we stuffed this into the AI tutorial doesn’t need explanation. Python Speech
recognition forms an integral part of Artificial Intelligence. What would Siri or Alexa be
without it?. So, in conclusion to this Python Speech Recognition, we discussed Speech
Recognition API to read an Audio file in Python. Moreover, we saw reading a segment and
dealing with noise in Speech Recognition Python tutorial. You can freely tell us the reading
experience of this article through comments.
REFERENCES
[1] J. Brown, B. Shipman and R. Vetter, “SMS: The Short Message
Service,” in Computer, vol. 40, no. 12, pp. 106–110, Dec. 2007.
[2] B. Whitworth and E. Whitworth, “Spam and the social-technical gap,”
Computer, vol. 37, pp. 38–45, 2004.
[3] Hedieh Sajedi, Golazin Zarghami Parast, Fatemeh Akbari. SMS Spam
Filtering Using Machine Learning Techniques: A Survey. Machine
Learning Research. Vol. 1, №1, 2016, pp. 1–14. doi:
10.11648/j.mlr.20160101.11
[4] Yoon J, Kim H, Huh J. Hybrid spam filtering for mobile
communication. Journal of Computers and Security 2010; 29(4):446–459.
DOI:10.1016/j.cose.2005.12.003.
[5] Joe I,Shim H. An SMS spam filtering system using support vector
machine. In Proceedings of Future Generation Information Technology,
Dec. 2010; 577–584, DOI: 10.1007/978‐3‐642‐17569‐5_56.
[6] Russell, Stuart J, and Peter Norvig. Artificial Intelligence: A Modern
Approach. Englewood Cliffs, N.J: Prentice Hall, 1995. Print.
[7] Raschka, S.(2014), Naïve Bayes and Text Classification —
Introduction and Theory, Retrieved February 5, 2020, from
https://sebastianraschka.com/Articles/2014_Naïve_bayes_1.html#Referenc
es
[8] Intelligent Agents.(2008). Retrieved March 1, 2020 from
http://en.wikipedia.org/wiki/Intelligent_agents
[9]Artificial Intelligence/AI Agents and their Environments.Retrieved
March 1, 2020, from
https://en.wikibooks.org/wiki/Artificial_Intelligence/AI_Agents_and_their
_Environments
[10] Androutsopoulos, I., Koutsias, J., Chandrinos, K. V., Paliouras, G., &
Spyropoulos, C. D. (2000). An evaluation of Naïve Bayes ian anti-spam
filtering. arXiv preprint cs/0006013.
[11] Chávez, G.(2019, February 28) “Implementing a Naïve Bayes
classifier for text categorization in five steps”.Retrieved February 21,
2020,
[12] Dada, E. G., Bassi, J. S., Chiroma, H., Adetunmbi, A. O., & Ajibuwa,
O. E. (2019). Machine learning for email spam filtering: review,
approaches and open research problems. Heliyon, 5(6), e01802.
[13] Lok, E.K.( 2017, November 25) .Episode 1: Using TF-IDF to identify
the signal from the noise.Retrieved February 21, 2020