java - IBM Watson:未经授权
问题描述
我正在使用 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 密钥和端点。
推荐阅读
- r - 错误:当 R 中没有安装 NA 值时需要 TRUE/FALSE 的缺失值
- html - 在 div 之间添加边界线
- java - 如果语句中 x 可以等于一系列数字/一个数字范围?
- ios - 当行数设置为 0 时 UITextView 内容消失
- css - 在“购物车”页面 woocommerce 中自定义/删除这些部分?
- geometry - 关闭多面体的边界
- python - 获取具有模糊性的正则表达式组
- json - 如何使用来自 json 的动态生成值在 Angular 4 中添加元标记
- reactjs - 使用 react-redux 连接打字稿
- python - 在 Windows 上安装 Cartopy 和依赖项