Python Speech Recognition library (SpeechRecognition) : Introduction.

SpeechRecognition perform speech recognition using several engines and API’s. This engines and API’s are working online or offline.

One of them is Google’s Google Speech Recognition. It is also the default engine. The few essays I was able to make based on the example provided by the library are very satisfactory in both English and French.

With a few lines of code, you can have an application that listens for a few seconds to the microphone and transcribes


#!/usr/bin/env python3.6

# NOTE: this example requires PyAudio because it uses the Microphone class

import speech_recognition as sr

# obtain audio from the microphone
r = sr.Recognizer()
with sr.Microphone() as source:
    print("Say something!")
    audio = r.listen(source)

# recognize speech using Google Speech Recognition
    # for testing purposes, we're just using the default API key
    # to use another API key, use `r.recognize_google(audio, key="GOOGLE_SPEECH_RECOGNITION_API_KEY")`
    # instead of `r.recognize_google(audio)`
    print("Google Speech Recognition thinks you said " + r.recognize_google(audio, language="fr-FR"))

except sr.UnknownValueError:
    print("Google Speech Recognition could not understand audio")

except sr.RequestError as e:
    print("Could not request results from Google Speech Recognition service; {0}".format(e))

This is only the beginning, the sequel to the next episode.


Leave a Reply

Your email address will not be published. Required fields are marked *