Uberi / speech_recognition

Speech recognition module for Python, supporting several engines and APIs, online and offline.
https://pypi.python.org/pypi/SpeechRecognition/
BSD 3-Clause "New" or "Revised" License
8.44k stars 2.4k forks source link

ValueError: After Some iterations of file recognition of Google Speech Recognition #393

Open 1010Manoj opened 5 years ago

1010Manoj commented 5 years ago

My input file is 16 bit PCM wav file. Does google has limits for number of attempts per day/hour...

Traceback (most recent call last): File "ASR_speech.py", line 17, in print("The audio file contains: " + r.recognize_google(audio)) File "/home/microdesign/.local/lib/python2.7/site-packages/speech_recognition/init.py", line 851, in recognize_google result = json.loads(line)["result"] File "/usr/lib/python2.7/json/init.py", line 339, in loads return _default_decoder.decode(s) File "/usr/lib/python2.7/json/decoder.py", line 364, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/lib/python2.7/json/decoder.py", line 382, in raw_decode raise ValueError("No JSON object could be decoded") ValueError: No JSON object could be decoded

1010Manoj commented 5 years ago

My script is like this

import speech_recognition as sr import io

AUDIO_FILE = ("one.wav") with open(AUDIO_FILE, 'rb') as file: data = file.read()

print len(data) file_obj=io.BytesIO(data) r = sr.Recognizer()

with sr.AudioFile(file_obj) as source: r.adjust_for_ambient_noise(source) audio= r.record(source)

try: print("The audio file contains: " + r.recognize_google(audio))

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))

del file_obj

Malathi15 commented 5 years ago

Thank you @1010Manoj The script above works fine for me.. My Doubt is how can I Recognize the speech from the mp4 video file using Google Speech Recognition?

1010Manoj commented 5 years ago

As per my knowledge ..not support by Google speech for now Trick By converting video to audio and then use Google Speech Recognition will work but conversion time is more depending on video size.