簡體   English   中英

IBM Watson:未經授權

[英]IBM Watson: Unauthorized

我正在使用Java開發包含文字轉語音的應用程序。 我使用了IBM Watson Text-to-Speech API,但是我的代碼始終出現未經授權的錯誤。 誰能幫我修復它? 非常感謝你!

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);

鍵入API密鑰並安裝應用程序后,我總是會收到以下日志:

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)

出錯的行是

InputStream inputStream =
                              textToSpeech.synthesize(synthesizeOptions).execute().getResult();

這是因為您使用了錯誤的密鑰或錯誤的端點。 服務的端點在不同地區之間有所不同,但是您可以在創建服務的一組憑據時確定使用哪個密鑰和端點。 如果您查看服務憑證,將獲得一個iam密鑰和端點。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM