Speech recognition is a machine's ability to listen to spoken words and identify them. You can then use speech recognition in Python to convert the spoken words into text, make a query or give a reply. You can even program some devices to respond to these spoken words. You can do speech recognition in python with the help of computer programs that take in input from the microphone, process it, and convert it into a suitable form.
For microphone use
- Check for pyaudio:
>>> import pyaudio as pa Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: No module named pyaudio >>>
- Install pyaudio
$ pip install --user pyaudio
For Speech Recognition
- Check for SpeechRecognition:
$ pip list --format=freeze | grep SpeechRecognition
- Install SpeechRecognition
$ pip install --user SpeechRecognition
import speech_recognition as sr
def main(): r= sr.Recognizer() with sr.Microphone() as source:
print("Listening...")
r.pause_threshold=0.6
audio = r.listen(source)
try:
ask = r.recognize_google(audio, language='en-us')
print(f"Converted Audio is: {ask}" )
except Exception:
print("say that again")
return ""
return ask
main()