I am doing an app which includes text-to-speech, using Java. I used IBM Watson Text-to-Speech API but I always have Unauthorized Error with my code. Could anyone help me to fix it? Thank you very much!
IamOptions options = new IamOptions.Builder()
.apiKey({apikey})
.build();
TextToSpeech textToSpeech = new TextToSpeech(options);
textToSpeech.setEndPoint("https://stream.watsonplatform.net/text-to-speech/api");
try {
SynthesizeOptions synthesizeOptions =
new SynthesizeOptions.Builder()
.text(name)
.accept("audio/wav")
.voice("en-US_AllisonVoice")
.build();
InputStream inputStream =
textToSpeech.synthesize(synthesizeOptions).execute().getResult();
InputStream in = WaveUtils.reWriteWaveHeader(inputStream);
After I key in the API key and install the app, I always get such log:
AndroidRuntime: FATAL EXCEPTION: inference
Process: org.tensorflow.demo, PID: 21282
com.ibm.cloud.sdk.core.service.exception.UnauthorizedException: Unauthorized
at com.ibm.cloud.sdk.core.service.BaseService.processServiceCall(BaseService.java:478)
at com.ibm.cloud.sdk.core.service.BaseService$WatsonServiceCall.execute(BaseService.java:544)
at org.tensorflow.demo.DetectorActivity$3.run(DetectorActivity.java:351)
at android.os.Handler.handleCallback(Handler.java:907)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:216)
at android.os.HandlerThread.run(HandlerThread.java:65)
The line which went wrong is
InputStream inputStream =
textToSpeech.synthesize(synthesizeOptions).execute().getResult();