首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Watson Speech to Text -状态: 401,错误:未授权

Watson Speech to Text -状态: 401,错误:未授权
EN

Stack Overflow用户
提问于 2019-02-26 18:27:57
回答 1查看 362关注 0票数 0

我试图在我的聊天机器人中集成语音到文本服务,但收到标题中提到的错误。我只是使用了文档中描述的服务。他们将授权方法从用户名+密码更改为api密钥,对吗?这是我得到的错误:

代码语言:javascript
复制
Feb 26, 2019 11:18:38 AM okhttp3.internal.platform.Platform log
INFO: --> POST https://stream.watsonplatform.net/speech-to-text/api/v1/recognize http/1.1 (-1-byte body)
Feb 26, 2019 11:18:40 AM okhttp3.internal.platform.Platform log
INFO: <-- 401 Unauthorized https://stream.watsonplatform.net/speech-to-text/api/v1/recognize (2434ms, 37-byte body)
Feb 26, 2019 11:18:40 AM com.ibm.watson.developer_cloud.service.WatsonService processServiceCall
SEVERE: POST https://stream.watsonplatform.net/speech-to-text/api/v1/recognize, status: 401, error: Unauthorized
Exception in thread "AWT-EventQueue-0" com.ibm.watson.developer_cloud.service.exception.UnauthorizedException: Unauthorized: Access is denied due to invalid credentials. Tip: Did you set the Endpoint?
    at com.ibm.watson.developer_cloud.service.WatsonService.processServiceCall(WatsonService.java:368)
    at com.ibm.watson.developer_cloud.service.WatsonService$WatsonServiceCall.execute(WatsonService.java:429)
    at STTService.erkenneAudio(STTService.java:66)
    at GUI$recordAudioButtonListener.actionPerformed(GUI.java:179)

然而,我的代码是这样的:

代码语言:javascript
复制
    SpeechToText stt = new SpeechToText();

    stt.setApiKey("3PHwb6P36A0hgiovasdcqgesVyDZEO7awg2L1be");
    stt.setEndPoint("https://stream.watsonplatform.net/speech-to-text/api");

    try {
        RecognizeOptions recognizeOptions = new RecognizeOptions.Builder()
                  .audio(new File("C:/Users/jvermaet/Desktop/hallo.wav"))
                  .contentType(HttpMediaType.AUDIO_WAV)
                  .build();

        SpeechRecognitionResults srr = stt.recognize(recognizeOptions).execute();
        System.out.println(srr.toString());
                    
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        System.out.println("OO");
    }
EN

回答 1

Stack Overflow用户

发布于 2019-02-26 19:46:38

我只需要使用IAmOptions构造器。如果您不能导入IAmOptions,可能是因为您使用了旧版本的sdk,这是我的主要问题。

代码语言:javascript
复制
IamOptions options = new IamOptions.Builder()
.apiKey("{apikey}")
.build();
Assistant assistant = new Assistant("{version}", options);
assistant.setEndPoint("{url}");
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54883358

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档