watson-developer-cloud / java-sdk

:1st_place_medal: Java SDK to use the IBM Watson services.
http://watson-developer-cloud.github.io/java-sdk/
Apache License 2.0
590 stars 533 forks source link

[Text-to-Speech] failed with combine of special characters, e.g Spanish + ";" #602

Closed josepmao closed 7 years ago

josepmao commented 7 years ago

Get error:

SEVERE: GET https://stream.watsonplatform.net/text-to-speech/api/v1/synthesize?text=La%20guerra%20es%20de%20vital%20importancia%20para%20el%20Estado;%20es%20el%20dominio%20de%20la%20vida%20o%20de%20la%20muerte,%20el%20camino%20hacia%20la%20supervivencia%20o%20la%20p%C3%A9rdida%20del%20Imperio:%20es%20forzoso%20manejarla%20bien.&voice=es-ES_EnriqueVoice&accept=audio/wav, status: 400, error: 'ascii' codec can't decode byte 0xc3 in position 82: ordinal not in range(128)
com.ibm.watson.developer_cloud.service.exception.BadRequestException: 'ascii' codec can't decode byte 0xc3 in position 82: ordinal not in range(128)
    at com.ibm.watson.developer_cloud.service.WatsonService.processServiceCall(WatsonService.java:416)
    at com.ibm.watson.developer_cloud.service.WatsonService$1.execute(WatsonService.java:180)
    at Jmaotest.testTTS(Jmaotest.java:67)
    at Jmaotest.main(Jmaotest.java:26)

Change second line code to:

String output = URLEncoder.encode(text, "UTF-8").replace("+", "%20");
InputStream stream =service.synthesize(output, Voice.ES_ENRIQUE, AudioFormat.WAV).execute();

It works as expected.

Because in Java-SDK, we use HTTP GET to send request, thus need URL-encoded, while it seems not working fine while in Spanish.

Suggest either improve URL-encoder part, or change to use POST method.

jeffpk62 commented 7 years ago

@germanattanasio moving to a POST seems like a good first attempt at a fix. I can look at this tomorrow.

germanattanasio commented 7 years ago

great

jeffpk62 commented 7 years ago

@germanattanasio I took a look, and converting to a POST requires changing a number of tests accordingly. Using URL encoding may be better, but then we break tests for other reasons and I don't think we want to double URL encode the string. Also, the okhttp library may be URL encoding the string already, but I don't know it well enough and lack the time to work through it. I'm really sorry; I just don't have the cycles to handle this right now.

germanattanasio commented 7 years ago

I'm going to assign this @blakesteve

josepmao commented 7 years ago

@germanattanasio @blakesteve any update here?

blakesteve commented 7 years ago

Reopening due to reversion, see #635