Tuesday, July 14, 2020

Recognition of Spoken Words

Speech recognition means that when humans are speaking, a machine understands it. Here we are using Google Speech API in Python to make it happen.

Speech Recognition in Outlook

We need to install the following packages for this:

Pyaudio: It can be installed by using pip install Pyaudio command.
SpeechRecognition: This package can be installed by using pip install SpeechRecognition.
Google-Speech-API: It can be installed by using the command pip install google-api-python-client.

Example

Observe the following example to understand about recognition of spoken words:
Import the necessary packages as shown:

import speech_recognition as sr

Create an object as shown below:

recording = sr.Recognizer()

Now, the Microphone() module will take the voice as input:

with sr.Microphone() as source: recording.adjust_for_ambient_noise(source)
print("Please Say something:")
audio = recording.listen(source)

Now google API would recognize the voice and gives the output.

try:
print("You said: \n" + recording.recognize_google(audio))
except Exception as e:
print(e)

You can see the following output:

Please Say Something:
You said:


For example, if you said speech recognition is cool, then the system recognizes it correctly as follows:
speech recognition is cool
Share:

0 comments:

Post a Comment