Google-cloud-node: [cloud speech] the right way to get a transcript from operation? base64 decode!?

Created on 16 May 2017  路  9Comments  路  Source: googleapis/google-cloud-node

screen shot 2017-05-16 at 9 58 40 pm

Though I couldn't find the usage of operation reference to get a transcript result.
I found something similar by base64-decoding operation.metadata.response.value..

The strange thing is I got some special characters after decoding the value.
Could you share the the right way to get a transcript from operation?

var operation = speechClient.operation('68850831366825');
operation.get({},function(err,res){
              if (err){
                  console.log(err);
                  return;
              }
              var metadata = res.metadata;
              var isDone = metadata.done;
              if (isDone && metadata.response) {
                  var b64string = metadata.response.value;
                  var buf = new Buffer(b64string, 'base64');
                  var transcript = buf.toString('utf8');
                  .....
             }
speech p2

Most helpful comment

I'd like to note that the use case it caters to (startRecognition in one process, poll for results in another) is an important use-case in my opinion.
Longer audio files can take real long to process by the speech API. I'm using Cloud Functions to startRecognition and I can't afford to have a function sit around waiting for the promise to resolve. Also, I just run into the max runtime quota for those and the function instance is forcibly terminated.

All 9 comments

Just confirming the use case-- you are trying to get the transcript from a recognition request that was run in another process at another time?

@stephenplusplus Yes. thats what I am trying to do.

Thanks. We haven't designed an ideal solution for this, so the way you've been doing it would be the most correct. Off hand, I'm not sure what a good API would look like for this, so feel free to make suggestions / send a PR!

@lukesneeringer since Speech is about to go through the same process as Vision Partial Veneer, is this feature request relevant?

as a followup to to @mfkenson's snippet in the issue summary:

the base64 string found at metadata.response.value isn't usable data. It is the protocol buffers representation of the results. To get the result data, I am doing the following contortion to get useful data:

...
const results = speechClient.api.Speech.longrunningDescriptors.longRunningRecognize.responseDecoder(metadata.response.value).results
const result = map(results, r => r.alternatives[0].transcript).join('')

there may be a pretty way of doing this, but i've invested enough time in this for now.
This remains brittle solution as it relies on a deeply nested private API.

I find this public speechClient.operation rather useless in its current form and its presence on the public API more misleading than helpful as I couldn't find a public way of doing anything useful with the result set. Did I miss something? I certainly couldn't find any doc or examples showing me better.

I recommend you consider either deprecating it, augmenting it or putting a prominent warning about its limited use in the doc

I'd like to note that the use case it caters to (startRecognition in one process, poll for results in another) is an important use-case in my opinion.
Longer audio files can take real long to process by the speech API. I'm using Cloud Functions to startRecognition and I can't afford to have a function sit around waiting for the promise to resolve. Also, I just run into the max runtime quota for those and the function instance is forcibly terminated.

@ximus Even I could afford to sit and wait, there will be timeout exception (grpc)

Hi @mfkenson,
Thank you for reporting this.

Since the time that you reported this issue, we released an entirely new version of google-cloud-speech with significant alterations. Could you upgrade to the newest version (note that code changes will be necessary to use the new thing; your existing code will use the former, now deprecated code path), and it should fix this problem for you.

I am going to close this, but feel free to re-open if the issue persists.

I am no longer on the team

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dsimmons picture dsimmons  路  4Comments

arbesfeld picture arbesfeld  路  4Comments

charly37 picture charly37  路  3Comments

VikramTiwari picture VikramTiwari  路  3Comments

nicolasgarnier picture nicolasgarnier  路  4Comments