什么都是Watson服务不支持的符号,以避免BadRequestException

时间:2017-03-21 05:10:59

标签: java text-to-speech ibm-watson watson

我目前正在使用IBM Watson的Java SDK文本到语音转换API

代码如下

TextToSpeech textToSpeech = new TextToSpeech();
textToSpeech.setUsernameAndPassword(username, password);
ServiceCall<InputStream> inputStreamServiceCall = textToSpeech.synthesize(text, Voice.EN_ALLISON, AudioFormat.OGG);
InputStream in = inputStreamServiceCall.execute();

将文本转换为语音时会出现异常

  

com.ibm.watson.developer_cloud.service.exception.BadRequestException:           在com.ibm.watson.developer_cloud.service.WatsonService.processServiceCall(WatsonService.java:416)   〜[java的SDK-3.3.0.jar:NA]           在com.ibm.watson.developer_cloud.service.WatsonService $ 1.execute(WatsonService.java:179)   〜[java的SDK-3.3.0.jar:NA]

     

com.ibm.watson.developer_cloud.service.WatsonService   processServiceCall SEVERE:GET   https://stream.watsonplatform.net/text-to-speech/api/v1/synthesize?text=Question%20%20%3Cbreak%20time%3D%221s%22/%3E%20Use%20the%20figure%20below%20to%20answer%20the%20following%20question.%20If%20AC||DE,%20which%20of%20the%20following%20justifies%20%CE%94ABC%20~%20%CE%94DBE?%20%20%3Cbreak%20time%3D%221s%22/%3E%20%20Answer%20Choices%20%20%20%3Cbreak%20time%3D%221s%22/%3E%20%20Choice%20A%20%20%3Cbreak%20time%3D%221s%22/%3E%20%20%20Definition%20of%20Similar%20Triangles%20%20%20%3Cbreak%20time%3D%221s%22/%3E%20%20Choice%20B%20%20%3Cbreak%20time%3D%221s%22/%3E%20%20%20SAS%20Similarity%20Theorem%20%20%20%3Cbreak%20time%3D%221s%22/%3E%20%20Choice%20C%20%20%3Cbreak%20time%3D%221s%22/%3E%20%20%20SSS%20Similarity%20Theorem%20%20%20%3Cbreak%20time%3D%221s%22/%3E%20%20Choice%20D%20%20%3Cbreak%20time%3D%221s%22/%3E%20%20%20AA%20Similarity%20Postulate%20&voice=en-US_AllisonVoice&accept=audio/ogg;%20codecs%3Dopus,   状态:400,错误:

我通过用空格替换下列符号“”© - ''▒“{} |`\来解决这个问题。

请告知watson服务不支持的所有符号?

1 个答案:

答案 0 :(得分:0)

将com.ibm.watson.developer_cloud java-sdk升级到更高版本.latest是3.8.0。在java-sdk-3.3.0.jar中,在对watson进行API调用时,某些字符未正确编码。