Speech Recognition using Python

Written by gk-resource-person | Published 2020/05/08
Tech Story Tags: speech-recognition | speech-recognition-in-python | audio-to-text | latest-tech-stories | python | pythin-speech-recognition | identify-speech-in-python | recognizing-speech-in-python

TLDR SpeechRecognition is based on a version version 3.8.1. Each Recognizer instance has seven methods for recognizing speech from an audio source using various APIs. Only recognize_sphinx() works offline with the CMU Sphinx engine. The other six all require an internet connection to recognize speech using the API. Each recognize_*() method will throw a speech_recognition.RequestError exception if the API is unreachable. The other 6 methods require a connection to the server.via the TL;DR App

Install SpeechRecognition
$ pip install SpeechRecognition
After Installation, verify the version
>>> import speech_recognition as sr
>>> sr.__version__
'3.8.1'
Recognizer Class in SpeechRecognition
Key Implementations done by SpeechRecognition using the Recognizer class.
Primary purpose of Recognizer instance is to recognize speech.
Each instance comes with a variety of settings and functionality for recognizing speech from an audio source.
Creating a Recognizer instance is easy. In your current interpreter session, just type:
>>> r = sr.Recognizer()
Methods for Recognizing Speech
Each Recognizer instance has seven methods for recognizing speech from an audio source using various APIs
  1. recognize_bing(): Microsoft Bing Speech
  2. recognize_google(): Google Web Speech API
  3. recognize_google_cloud(): Google Cloud Speech - requires installation of the google-cloud-speech package
  4. recognize_houndify(): Houndify by SoundHound
  5. recognize_ibm(): IBM Speech to Text
  6. recognize_sphinx(): CMU Sphinx - requires installing PocketSphinx
  7. recognize_wit(): Wit.ai
Of the seven, only recognize_sphinx() works offline with the CMU Sphinx engine. The other six all require an internet connection.
Recognizing Speech
Each recognize_*() method will throw a speech_recognition.RequestError exception if the API is unreachable.
For recognize_sphinx(), this could happen as the result of a missing, corrupt or incompatible Sphinx installation.
For the other six methods, RequestError may be thrown if quota limits are met, the server is unavailable, or there is no internet connection.
Call recognize_google()
>>> r.recognize_google()
Adding Audio Files for Speech Recognition
Now, record the WAV File so that it can be translated to text. Any WAV file can be taken
Speech Extraction Google API
import speech_recognition as sr

harvard=sr.AudioFile('myrecord.wav')

r = sr.Recognizer()

with harvard as source:
    audio=r.record(source)

print (type(audio))

print (r.recognize_google(audio))
The text will be recognized from audio file "myaudio.wav" and will be printed

Written by gk-resource-person | Trainer Research Tools, Data Science, Blockchain Technology, Cyber Security, Artificial Intelligence
Published by HackerNoon on 2020/05/08