In this article i want to show you an example of Python With Google Speech, so Speech Recognition is a library for performing speech recognition, with support for several engines and APIs, online and offline.
So now for this first of all you need to install speechRecognition Library in Python ,
First, make sure you have all the requirements listed in the “Requirements” section.
The easiest way to install this is using pip install SpeechRecognition.
Otherwise, download the source distribution from PyPI, and extract the archive.
In the folder, run python setup.py install.
import speech_recognition as sr
def main():
r = sr.Recognizer()
with sr.Microphone() as source:
r.adjust_for_ambient_noise(source)
print("Please say something")
audio = r.listen(source)
print("Recognizing Now .... ")
# recognize speech using google
try:
print("You have said \n" + r.recognize_google(audio))
print("Audio Recorded Successfully \n ")
except Exception as e:
print("Error : " + str(e))
# write audio
with open("recorded.wav", "wb") as f:
f.write(audio.get_wav_data())
if __name__ == "__main__":
main()
So at the top first we have created a recognizer object, also for removing noises we need to add this line of code
r.adjust_for_ambient_noise(source)
And in here we are recognizing the speech using Google Speech
print("You have said \n" + r.recognize_google(audio))
In here we are going to record the audio
with open("recorded.wav", "wb") as f:
f.write(audio.get_wav_data())
Now run the code and this will be the result
#python #machine-learning #data-science