0% found this document useful (0 votes)
276 views16 pages

Speech Recognition System

This document is a mini-project report submitted by Rajat Kushwaha for their Bachelor of Technology degree. The report discusses speech recognition systems and includes an abstract, table of contents, and initial chapters on introduction, literature review, and problem formulation. It outlines the objectives of studying speech recognition and implementing it using Python.

Uploaded by

Rajat Kushwaha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
276 views16 pages

Speech Recognition System

This document is a mini-project report submitted by Rajat Kushwaha for their Bachelor of Technology degree. The report discusses speech recognition systems and includes an abstract, table of contents, and initial chapters on introduction, literature review, and problem formulation. It outlines the objectives of studying speech recognition and implementing it using Python.

Uploaded by

Rajat Kushwaha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

Mini-Project Report on

Speech Recognition System


Submitted as fulfilment of the requirements for the
award of the degree of

Bachelor of Technology in
Computer Science and Engineering

by
Rajat Kushwaha – Roll No: 1809710081

Under the Supervision of


Mr. T. Akilan
Mr. Mayank Dixit

Galgotias College of Engineering & Technology


Greater Noida, Uttar Pradesh
India-201306
Affiliated to

Dr. A.P.J. Abdul Kalam Technical University


Lucknow, Uttar Pradesh,
India-226031
May, 2020

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

1.1 Purpose of the project

1.2 Objective of the project

CHAPTER 2: LITERATURE REVIEW

CHAPTER 3: PROBLEM FORMULATION

CHAPTER 4: PROPOSED WORK

CHAPTER 5: METHODOLOGY

CHAPTER 6: CONCLUSION AND FUTURE SCOPE

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

Creating new project


Create a new project and name it as SpeechRecognitionExample (Though the name doesn’t
matter at all it can be anything). And then create a python file inside the project. I hope you
already know about creating new project in python.

Installing Libraries
we have to install two library for implementing speech recognition.

SpeechRecognition
PyAudio
Installing SpeechRecognition
Go to terminal and type

pip install SpeechRecognition

1
2
3
pip install SpeechRecognition

SpeechRecognition is a library that helps in performing speech recognition in python. It


support for several engines and APIs, online and offline e.g. Google Cloud Speech API,
Microsoft Bing Voice Recognition, IBM Speech to Text etc.

Installing PyAudio
Go to terminal and type

pip install pyaudio

1
2
3

pip install pyaudio

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.

Performing Speech Recognition


Now let’s jump into the coding part.

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!")

elif hour>=12 and hour<18:


speak("Good Afternoon!")

else:
speak("Good Evening!")

speak("I am Assistant Sir. Please tell me how may I help you")

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

def sendEmail(to, content):


server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.login('[email protected]', 'your-password')
server.sendmail('[email protected]', to, content)
server.close()

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)

elif 'open youtube' in query:


webbrowser.open("youtube.com")

elif 'open google' in query:


webbrowser.open("google.com")

elif 'open stackoverflow' in query:


webbrowser.open("stackoverflow.com")

elif 'play music' in query:


music_dir = 'D:\Downloads'
songs = os.listdir(music_dir)
print(songs)
os.startfile(os.path.join(music_dir, songs[0]))

elif 'the time' in query:


strTime = datetime.datetime.now().strftime("%H:%M:%S")
speak(f"Sir, the time is {strTime}")

elif 'open code' in query:


codePath = "C:\\Python jarvis\\jarvis.py"
os.startfile(codePath)

elif 'send email' in query:


try:
speak("What should I say?")
content = takeCommand()
to = "[email protected]"
sendEmail(to, content)
speak("Email has been sent!")
except Exception as e:
print(e)
speak("Sorry Sir. I am not able to send this email")

elif 'hello' in query:


speak("Hello Sir,Have a nice day!!!")

elif 'who are you' in query:


speak('I am vitual machine and build as artificial intelligence and made to help human beings')

elif 'stop' in query:


speak('Good Bye Sir!!!')
exit()
CHAPTER 5
METHODOLOGY

1. Python Speech Recognition


Welcome to our Python Speech Recognition Tutorial. In this tutorial of AI with Python Speech
Recognition, we will learn to read an audio file with Python. We will make use of the speech
recognition API to perform this task. Moreover, we will discuss reading a segment and dealing
with noise.

So, let’s start the Python Speech recognition Tutorial.

Python Speech Recognition - Artificial Intelligence


Python Speech Recognition – Artificial Intelligence

2. What is Python Speech Recognition?


From systems facilitating single speakers and limited vocabularies of around a dozen words, to
systems that recognize from multiple speakers and possess huge vocabularies in various
languages, we have come a long way. What we do here is- we convert speech from physical
sound to electrical signals using a microphone. Then, we use an analogue-to-digital converter to
convert this to digital data. Finally, we use multiple models to transcribe audio to text. In the
Hidden Markov Model (HMM), we divide the speech signal into 10-millisecond fragments.
Do you know about Recursion in Python

a. Available APIs in Python Speech Recognition


With Python, we have several APIs available:

apiai
assemblyai
google-cloud-speech
pockets
b. Prerequisites for Python Speech Recognition
You can use pip to install this-

pip install SpeechRecognition


3. Reading an Audio File in Python
a. The Recognizer class
First, we make an instance of the Recognizer class.

>>> r=sr.Recognizer()
With Recognizer, we have a method for each API

b. Capturing data with record()


We can have the context manager open the file and read its contents, then record it into an
AudioData instance.

>>> with demo as source:


audio=r.record(source)

c. Recognizing Speech in the Audio


Finally, you can call recognize_google() to perform the transcription.

>>> r.recognize_google(audio)

4. Reading a Segment of Audio


When you only want to read a part of your audio file, you can use the arguments offset– telling it
where to begin (in seconds), and duration– telling it how long to listen.

Let’s take a tour of Python Datetime Module

>>> with demo as source:


audio=r.record(source,offset=4,duration=3)
>>> r.recognize_google(audio)

6. Working With Microphones


To be able to work with your own voice with speech recognition, you need the PyAudio package.
You can install it with pip-
pip install PyAudio

a. The Microphone class


Like Recognizer for audio files, we will need Microphone for real-time speech data. Since we
installed new packages, let’s exit our interpreter and open another session.

>>> import speech_recognition as sr


>>> r=sr.Recognizer()

b. Capturing Microphone Input


With the context manager, we capture input using the listen() method.

>>> with mic as source:


audio=r.listen(source)

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

You might also like