Created
March 14, 2016 16:41
-
-
Save mertyildiran/957b8c9f7631f6ab7f21 to your computer and use it in GitHub Desktop.
Google Speech API example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# pip install SpeechRecognition | |
# https://pypi.python.org/pypi/SpeechRecognition/ | |
# recognizer_instance.recognize_google(audio_data, key = None, language = "en-US", show_all = False) | |
# Performs speech recognition on audio_data (an AudioData instance), using the Google Speech Recognition API. | |
# The Google Speech Recognition API key is specified by key. If not specified, it uses a generic key that works out of the box. | |
# This should generally be used for personal or testing purposes only, as it may be revoked by Google at any time. | |
# 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 | |
try: | |
# 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 in English: - " + r.recognize_google(audio, language = "en-US")) | |
print("Google Speech Recognition thinks you said in Turkish: - " + r.recognize_google(audio, language = "tr-TR")) | |
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)) |
can i use recognize_google function in offline? I want to download Google Api in local to use this function. So it's possible? and How please?
i'm trying to use voice_data = r.recognize_google(audio, language="pl-PL") unfortunetly this does not work i don't know if it is my Windows issue or maybe PL is not supported can You help me please?
@gucisz
You can find all language codes here: https://cloud.google.com/speech-to-text/docs/languages
According this page should work for you
I want to install 2 languages at the same time, how do I do that?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
i'm trying to use voice_data = r.recognize_google(audio, language="pl-PL") unfortunetly this does not work i don't know if it is my Windows issue or maybe PL is not supported can You help me please?