You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When i try to analyze a audio file with google speech api i get a error that the file is longer then 1min but the file is 30sec long. File in attachment and error message below.
This is my requerst code (part is path to the local audio file):
with open(part, 'rb') as speech:
# Base64 encode the binary audio file for inclusion in the request.
speech_content = base64.b64encode(speech.read())
#GOOGLE_APPLICATION_CREDENTIALS = self.googleApplicationCredentials
service = self.get_speech_service()
service_request = service.speech().asyncrecognize(
body={
'config': {
# There are a bunch of config options you can specify. See
# https://goo.gl/KPZn97 for the full list.
'encoding': 'LINEAR16', # raw 16-bit signed LE samples
'sampleRate': 16000, # 16 khz
# See http://g.co/cloud/speech/docs/languages for a list of
# supported languages.
'languageCode': language_code, # a BCP-47 language tag
},
'audio': {
'content': speech_content.decode('UTF-8')
}
}
)
Error message
Traceback (most recent call last):
File "test.py", line 5, in
analyze = Analyze('temp/33852851486977924039000.wav','en-us')
File "/home/bero/video-analyze/Analyze.py", line 39, in init
response = service_request.execute()
File "/home/bero/.local/lib/python3.5/site-packages/oauth2client/_helpers.py", line 133, in positional_wrapper
return wrapped(*args, **kwargs)
File "/home/bero/.local/lib/python3.5/site-packages/googleapiclient/http.py", line 838, in execute
raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 400 when requesting https://speech.googleapis.com/v1beta1/speech:asyncrecognize?alt=json returned "Audio 'content' cannot be longer than 1 min. For long audio, use the 'uri' parameter to specify a file.">
Yeah - it looks like the file is encoded as WAVE instead of raw (though perhaps this doesn't matter so much - see below). It's correctly 16-bit little-endian at 16khz, but it's stereo, which isn't supported and explains why the api thinks it's twice as long as it is :-)
I was able to get it to work after re-encoding it to 1 channel (sox 33852851486977924039000.wav foo.wav channels 1). Interestingly, the api doesn't seem to care about the WAVE container :-) (nor does aplay... TIL) It probably just interprets the header frames as audio samples, which become just noise for a short burst in the beginning..
Activity
[-]Error for 30sec long audio file[/-][+]Error for short audio file[/+]theacodes commentedon Feb 13, 2017
@gguuss or @jerjou, any thoughts?
gguuss commentedon Feb 13, 2017
I have seen the filesize get misinterpreted on certain formats. Are you sure you're using the right format? Can you encode the file as FLAC?
jerjou commentedon Feb 13, 2017
Yeah - it looks like the file is encoded as WAVE instead of raw (though perhaps this doesn't matter so much - see below). It's correctly 16-bit little-endian at 16khz, but it's stereo, which isn't supported and explains why the api thinks it's twice as long as it is :-)
I was able to get it to work after re-encoding it to 1 channel (
sox 33852851486977924039000.wav foo.wav channels 1). Interestingly, the api doesn't seem to care about the WAVE container :-) (nor doesaplay... TIL) It probably just interprets the header frames as audio samples, which become just noise for a short burst in the beginning..jerjou commentedon Feb 13, 2017
Closing for now - please reopen if this doesn't fix the issue!
bgrgicak commentedon Feb 14, 2017
Converting the file to flac mono solved the issue. Thank you for your help!
chore(deps): update all dependencies (#801)