Giter VIP home page Giter VIP logo

Comments (4)

mihui avatar mihui commented on August 30, 2024 1

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.

from speech-android-sdk.

KlasZetterlund avatar KlasZetterlund commented on August 30, 2024

I thought I had a fix for it, but I was wrong

from speech-android-sdk.

ykcadcg avatar ykcadcg commented on August 30, 2024

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."

from speech-android-sdk.

ykcadcg avatar ykcadcg commented on August 30, 2024

Thank you so much mihui! That's exactly what I need.

from speech-android-sdk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.