Skip to content

Can't get speech_asynch_rest.py to work with Google Cloud Storage to transcribe long audio files #441

Closed
@mjgallow

Description

@mjgallow

I'm probably being dense or missing something, but speech_asynch_rest.py doesn't seem to work with Google Cloud Storage, and I believe you have to use Google Cloud Storage to transcribe long audio files.
I tried to find an answer to this on my own, but so far no luck. Hopefully I'm posting my issue in the right place, and following your guidelines for reporting issues (I did look over the guidelines that I could find). If not, let me know.

Here is an example Google Storage audio file to transcribe:
https://storage.googleapis.com/cloud-samples-tests/speech/brooklyn.flac

Below is what I'm entering and what errors I'm seeing when I try this in Windows 7 and Mac OS X El Capitan.

Also, note that I can run the examples fine that you list on https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/speech/api/README.md .
Also, note that I've been able successfully obtain transcripts for long audio files in my Google Cloud Storage using another method that involves curl.

I changed the audio part of the JSON object in speech_asynch_rest.py (currently line 68 or so, I believe) to the following only when trying to access the Google Cloud Storage audio file:

'uri': speech_content.decode('UTF-8')

If you need more information, let me know.

_Windows 7 PC Attempt, with error feedback included_
Open Window cmd.exe (Click Start. Type in "cmd" (without quotes). Press Enter/Return.)
"export" command doesn't work in DOS
Here's what I typed in at the prompt (username and specific project name and id replaced).
C:\Python\python-docs-samples-master\speech\api> cd C:/Users/USERNAME/env/Scripts
C:\Python\python-docs-samples-master\speech\api> call activate.bat
C:\Python\python-docs-samples-master\speech\api> cd C:/Python/python-docs-samples-master/speech/api
(env) C:\Python\python-docs-samples-master\speech\api>set GOOGLE_APPLICATION_CREDENTIALS=C:\Python\My_Project-SOME_NUMBER.json
(env) C:\Python\python-docs-samples-master\speech\api>python speech_rest.py resources/audio.raw
{"results": [{"alternatives": [{"confidence": 0.98267895, "transcript": "how old is the Brooklyn Bridge"}]}]}
(env) C:\Python\python-docs-samples-master\speech\api>python speech_async_rest.py resources/audio.raw
{"name": "LONG_NUMBER_HERE"}
Waiting for server processing...
Waiting for server processing...
[{"alternatives": [{"transcript": "how old is the Brooklyn Bridge", "confidence": 0.98267895}]}]
(env) C:\Python\python-docs-samples-master\speech\api>python speech_async_rest.py gs://cloud-samples-tests/speech/brooklyn.flac
Traceback (most recent call last):
File "speech_async_rest.py", line 101, in
main(args.speech_file)
File "speech_async_rest.py", line 52, in main
with open(speech_file, 'rb') as speech:
OSError: [Errno 22] Invalid argument: 'gs://cloud-samples-tests/speech/brooklyn.flac'

_Mac OS X El Capitan Attempt, with error feedback included_
Click Applications > Utilities > Terminal.
Here's what I typed in at the prompt (username, transcription number, and specific project name and id replaced).
$ cd Desktop/python-docs-samples-master/speech/api
$ source env/bin/activate
$ export GOOGLE_APPLICATION_CREDENTIALS=/Users/USERNAME/Desktop/google_stuff/My_Project-SOME_NUMBER.json
$ python speech_rest.py resources/audio.raw
{"results": [{"alternatives": [{"confidence": 0.98267895, "transcript": "how old is the Brooklyn Bridge"}]}]}
$ python speech_async_rest.py resources/audio.raw
{"name": "LONG_NUMBER_HERE"}
Waiting for server processing...
Waiting for server processing...
[{"alternatives": [{"confidence": 0.98267895, "transcript": "how old is the Brooklyn Bridge"}]}]
$ python speech_async_rest.py gs://cloud-samples-tests/speech/brooklyn.flac
Traceback (most recent call last):
File "speech_async_rest.py", line 101, in
main(args.speech_file)
File "speech_async_rest.py", line 52, in main
with open(speech_file, 'rb') as speech:
IOError: [Errno 2] No such file or directory: 'gs://cloud-samples-tests/speech/brooklyn.flac'

Metadata

Metadata

Assignees

Labels

🚨This issue needs some love.MLtriage meI really want to be triaged.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions