SpeechRecognition
SpeechRecognition
# importing libraries
import speech_recognition as sr
import os
from pydub import AudioSegment
from pydub.silence import split_on_silence
The below function loads the audio file, performs speech recognition, and
returns the text:
Audio Processing: Converting the audio signal into data that the SpeechRecognition library can work
with.
Recognition: Calling the recognize_google() method (or another available recognition method) on
the SpeechRecognition library to convert the audio data into text.
Pro_2
import speech_recognition as sr
try:
# using google speech recognition
print("Text: "+r.recognize_google(audio_text))
except:
print("Sorry, I did not get that")
Set Chunk Size: This basically involved specifying how many bytes of data we want to read at once.
Typically, this value is specified in powers of 2 such as 1024 or 2048
Set Sampling Rate: Sampling rate defines how often values are recorded for processing
Set Device ID to the selected microphone : In this step, we specify the device ID of the microphone
that we wish to use in order to avoid ambiguity in case there are multiple microphones. This also
helps debug, in the sense that, while running the program, we will know whether the specified
microphone is being recognized. During the program, we specify a parameter device_id. The
program will say that device_id could not be found if the microphone is not recognized.
Allow Adjusting for Ambient Noise: Since the surrounding noise varies, we must allow the program a
second or two to adjust the energy threshold of recording so it is adjusted according to the external
noise level.
Speech to text translation: This is done with the help of Google Speech Recognition. This requires an
active internet connection to work. However, there are certain offline Recognition systems such as
PocketSphinx, that have a very rigorous installation process that requires several dependencies.
Google Speech Recognition is one of the easiest to use.
SPEECH HINDI
pip install SpeechRecognition
pip install PyAudio
pip install pipwin
pipwin install pyaudio
r = sr.Recognizer()
with sr.Microphone() as source:
# Driver Code