Speech Recongnition using Python

The goal of this mini python project is to learn about the Speech Recognition package to convert audio into text. The process is as follows:

  1. Installing and importing PyAudio and SpeechRecognition package. Visit this link to download the PyAudio package if you come across any error using pip functionality.
  2. Setting a variable to Recognizer function.
  3. Writing the function for converting microphone into text.
  4. Calling out the function
In [1]:
from platform import python_version
print('You are using {} version of Python'.format(python_version()))
You are using 3.7.3 version of Python
In [2]:
!pip install PyAudio
!pip install SpeechRecognition
Requirement already satisfied: PyAudio in c:\users\saluj\appdata\local\continuum\anaconda3\lib\site-packages (0.2.11)
Requirement already satisfied: SpeechRecognition in c:\users\saluj\appdata\local\continuum\anaconda3\lib\site-packages (3.8.1)

Importing Speech Recognition package

In [3]:
import speech_recognition as sr

#setting a variable to Recognizer function
r = sr.Recognizer()

Defining function for SR

In [4]:
def speech_recognition():
    #setting audio source as microphone
    with sr.Microphone() as source:
        print("Speak Now : ")
        audio = r.listen(source)

            audio_to_text = r.recognize_google(audio)
            print('You said: {}'.format(audio_to_text))
            print('Sorry, could not convert audio to text. Please try again!')

Calling out SR function

In [5]:
Speak Now : 
You said: this is so cool

Author: Amandeep Saluja