Overview
Performs speech recognition using the Google Speech Recognition API. This method uses a generic API key that works out of the box for testing purposes.Method Signature
Parameters
The audio data to recognize. Must be an
AudioData instance obtained from a Recognizer.record() or Recognizer.listen() call.Google Speech Recognition API key. If not specified, 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.To obtain your own API key, follow the steps on the API Keys page at the Chromium Developers site. In the Google Developers Console, Google Speech Recognition is listed as “Speech API”.
Recognition language as an RFC5646 language tag (e.g.,
"en-US" for US English, "fr-FR" for French, "es-ES" for Spanish).See supported language tags for a complete list.Profanity filter level:
0: No filter1: Only shows the first character and replaces the rest with asterisks
If
True, returns the raw API response as a JSON dictionary. If False, returns only the transcription text.If
True, returns a tuple of (transcript, confidence). Only applicable when show_all=False.Returns
The recognized text (when
show_all=False and with_confidence=False)A tuple of
(transcript, confidence) when with_confidence=TrueThe raw API response when
show_all=True, containing:result: List of recognition resultsalternative: List of alternative transcriptions with confidence scores
Exceptions
Raised when the speech is unintelligible
Raised when:
- The API request fails
- The API key is invalid
- There is no internet connection
Example Usage
Basic Recognition
With Custom Language
With Confidence Score
With Custom API Key
Get Full API Response
Language Support
Google Speech Recognition supports over 120 languages and variants. Common language codes:en-US- English (United States)en-GB- English (United Kingdom)es-ES- Spanish (Spain)fr-FR- French (France)de-DE- German (Germany)it-IT- Italian (Italy)ja-JP- Japanesezh-CN- Chinese (Simplified)ko-KR- Koreanpt-BR- Portuguese (Brazil)ru-RU- Russianar-SA- Arabic
Notes
- The generic API key may have rate limits or be revoked
- For production use, obtain your own API key
- Audio must be at least 8 kHz sample rate
- Audio is automatically converted to 16-bit samples
- Confidence scores may not always be available