watson-developer-cloud / node-sdk

:comet: Node.js library to access IBM Watson services.
https://www.npmjs.com/package/ibm-watson
Apache License 2.0
1.48k stars 669 forks source link

[speech-to-text] keywords, keywords_threshold, word_alternatives_threshold are being dropped #189

Closed monte-hayward closed 8 years ago

monte-hayward commented 8 years ago

The v1 service wrapper would pick params allowed to be sent to the service. This pr updates the "allowed" list with the new parameters announced in Updates for December 2015.

ykcadcg commented 8 years ago

what's a good keywords_threshold? 0 or 1 or 0.8 or else? It can't be left unspecified

C:\Users\kyang\Documents\GitHub\curl-7.49.0\AMD64>curl -X POST -u 27f6c1ee-3d03-4ef7-a4ea-c06877ad9d6b:Q03HBDFk07DP --header "Content-Type: audio/flac" --header "Transfer-Encoding: chunked" --data-binary @C:\Users\kyang\Documents\GitHub\0001.flac "
tps://stream.watsonplatform.net/speech-to-text/api/v1/recognize?continuous=true&keywords="actually""
{
   "code_description": "Bad Request",
   "code": 400,
   "error": "keywords_threshold must be set if keywords list is not empty."
}
nfriedly commented 8 years ago

Yea, the range is 0-1. I think we set it to 0.2 for the demo, but for real world usage, I would suggest a bit higher, maybe 0.5 or 0.8. It's basically a trade-off though - is it more important that you catch the keyword even if the speaker mumbled it (0.2) or that you avoid false-positives when they actually said something else (0.8). To some extent, you'll want to test different values and see what fits your app.

ykcadcg commented 8 years ago

Thank you! I have another quick question: I'm new to Java/JSON. My code adapting speech-android-wrapper. My this.sConfig.keywords is a public String[]. I know this toString() messed up with passing this.sConfig.keywords, but how to pass it correctly? I got error: "error": "Required type for parameter \"keywords\" is list. Got type unicode instead." Thanks! ` private void sendSpeechHeader() {

     JSONObject obj = new JSONObject();
     try {
         obj.put("action", "start");
         obj.put("content-type", this.sConfig.audioFormat);
         obj.put("interim_results", true);
         obj.put("continuous", true);
         obj.put("inactivity_timeout", this.sConfig.inactivityTimeout);
         obj.put("word_confidence", true); 
         obj.put("keywords_threshold", this.sConfig.keywordsThreshold); 
         obj.put("keywords", Arrays.toString(this.sConfig.keywords)); //this.sConfig.keywords is a  public String[]
     } catch (JSONException e) {
         e.printStackTrace();
     }
     String startHeader = obj.toString(); //I know this toString() messed up with passing this.sConfig.keywords, but how to pass it correctly?

     this.upload(startHeader);
     this.encoder.onStart();
     Log.d(TAG, "Sending init message: " + startHeader);
 }`

Got error: 05-29 16:25:53.078 28782-29008/com.ibm.watson.developer_cloud.android.examples D/MainActivity: onMessage, message: { "error": "Required type for parameter \"keywords\" is list. Got type unicode instead."

ykcadcg commented 8 years ago

btw the debugger for startHeader is this: {"action":"start","content-type":"audio\/ogg;codecs=opus","interim_results":true,"continuous":true,"inactivity_timeout":600,"word_confidence":true,"keywords_threshold":0.75,"keywords":"[banana, apple]"}

ykcadcg commented 8 years ago

Thanks. I also noticed during debugging: "final" is always "true" and never "false". Is it expected?

nfriedly commented 8 years ago

The final will always be true unless you set interim_results: true in the opening JSON message. Then you'll get a series of non-final "preview" results before each final one.

As for the Java thing, I'm not as familiar with that, but my guess is that it wants a JSONArray: https://developer.android.com/reference/org/json/JSONArray.html

ykcadcg commented 8 years ago

Got you, you are right, it needs JSONArray. thanks!