Closed KlasZetterlund closed 8 years ago
I thought I had a fix for it, but I was wrong
Hi, could you help me with a quick question that has been blocking me: my code is 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)); //*_Problematic_**: 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."
Hi @ykcadcg, data type of keywords should be a JSONArray type and it could be used directly using "obj.put(key, value)", here is the sample:
obj.put("keywords", this.sConfig.keywords);
If the data type of this.sConfig.keywords can't be changed, please consider this:
JSONArray jsonArray = null;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
jsonArray = new JSONArray(this.sConfig.keywords);
}
obj.put("keywords", jsonArray);
Or
JSONArray jsonArray = null;
for(int i = 0; i < this.sConfig.keywords.length; i++){
jsonArray.put(this.sConfig.keywords[i]);
}
obj.put("keywords", jsonArray);
Thanks.
Thank you so much mihui! That's exactly what I need.
When I press record on the S-T-T-page the text shows up in the textView, no problem, but when I press stop the text turns into "ssl == null" I can't figure out what the problem is. I only get this error if the message is shorter than a few seconds.