Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[speech-to-text] asynchronous creation, can't get recognitions.completed_with_results #415

Closed
micahbrich opened this issue Mar 14, 2017 · 12 comments

Comments

@micahbrich
Copy link

Hey there! I seem to have hit some issue in defining asynchronous callback events — the docs mention you can pass an extra query parameter to request the completed callback to include results, but I can't make that happen.

I've got this:

const params = {
    'content_type': 'audio/wav',
    audio: request(`https://${clip.wav}`),
    'callback_url': hostname + '/callback',
    'user_token': clip.id,
    model: 'en-US_NarrowbandModel',
    content_type: 'audio/wav',
    inactivity_timeout: -1,
    interim_results: false,
    max_alternatives: 4,
    word_confidence: true,
    timestamps: true,
    profanity_filter: false,
    smart_formatting: true,
    speaker_labels: true,
    'word_alternatives_threshold':0.5,
    events: "recognitions.started,recognitions.completed_with_results,recognitions.failed",
  };

  Watson.createRecognitionJob(params, function(error, job) {
    if (error)
      console.log('Error:', error);
    else
      console.log(JSON.stringify(job, null, 2));
  });

The callback registration, transcription, and everything else is working great, just not the specified callback events. I get something like the last two events shown here:

screen shot 2017-03-14 at 11 26 33

I tried specifying events in the params as a comma-separated string like the docs suggest & an array of strings (which the source looks like converts to a comma-separated string). I tried events as the key, but also event as a Hail Mary attempt. I tried writing the list as both recognitions.completed_with_results and just completed_with_results, in case it was a misunderstanding.

I can successfully use that recognitions.completed event ID to do a new GET request and get the results, but it's an extra step in a pretty time-sensitive app, so I'm hoping I can get the event & result in one like the docs suggest.

Does anyone have any ideas what's up? Am I missing something, or doing anything wrong? Is this a bug?

@adrien2p
Copy link
Contributor

Thank you for your back, i ´ll work on it as soon as possible and i give you a return on this issue.

@micahbrich
Copy link
Author

Thanks @adrien2p ! If I can do anything, let me know.

@jeffpk62
Copy link
Contributor

@adrien2p, it looks like the event parameter is coded to accept a single string rather than a comma-separated list of strings at line 134 of node-sdk/speech-to-text/v1.js:

@param {string} [params.event] - recognitions.started|recognitions.completed|recognitions.failed|recognitions.completed_with_results

@adrien2p
Copy link
Contributor

adrien2p commented Mar 15, 2017

@jeffpk62 you are right, it's codded to accept string were you can pass event1,event2,event3,
but the thing is the name of the parameter event instead of events.
I'll fix it and params.user_secret in the block comment of RegisterCallback method which should be [params.user_secret], after work (or during my break time). ^^

@nfriedly
Copy link
Contributor

@micahbrich This should be fixed in v2.26.1 which is now available on npm. Can you test and confirm?

@nfriedly nfriedly mentioned this issue Mar 17, 2017
2 tasks
@micahbrich
Copy link
Author

Hmmmm @nfriedly I can't explain it yet, but this isn't quite working.

It does successfully pass the events now, but it seems like when I include:

events: ["recognitions.started","recognitions.failed","recognitions.completed_with_results"]

in the options object, I don't ever get any completed_with_results callback. And I'm thinking that means something is working, because I also don't get a completed callback when I do that, either, which would be expected if the former were working.

I did dig into the library folder and saw that the events option was returning two functions along with the strings — I can't tell if that's how request works or not.

...
options: { qs: 
   { callback_url: 'https://testurl.ngrok.io/callback',
     events: 
      [ 'recognitions.started',
        'recognitions.failed',
        'recognitions.completed_with_results',
        sum: [Function],
        average: [Function] ],
     continuous: true,
     max_alternatives: 0,
     timestamps: true,
     word_confidence: true,
     inactivity_timeout: -1,
     model: 'en-US_NarrowbandModel',
     interim_results: false,
     profanity_filter: false,
     smart_formatting: true,
     speaker_labels: false },
  url: 'https://stream.watsonplatform.net/speech-to-text/api/v1/recognitions',
...

I can't figure out how to see the final URL that gets sent, though. Does that look normal?

@micahbrich
Copy link
Author

Wait! 🙌 Update, I spoke too soon. It looks like it works when I pass it a string. I swear I tried that before, I'm not crazy. I'm successfully getting both recognitions.started and recognitions.completed_with_results back! Awesome awesome awesome, so great!

@adrien2p
Copy link
Contributor

adrien2p commented Mar 21, 2017

Hi @micahbrich Yes you should give a coma separated string as
events: 'event1, event2, ...'

@nfriedly
Copy link
Contributor

Doh. We should make the SDK handle that. Users should be able to pass in an array and have it work.

not sure where the sum & average functions are coming from, I wonder if something is mucking with Array.prototoye somewhere...

@nfriedly
Copy link
Contributor

Starting with v2.27.1, it should accept either a comma-separated string or an array of strings.

@micahbrich
Copy link
Author

You guys are so on it. 🏀

@adrien2p
Copy link
Contributor

adrien2p commented Mar 21, 2017

@nfriedly Well done man :) it was faster enougth ^^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants