【问题标题】:Watson Speech to Text - status: 401, error: UnauthorizedWatson Speech to Text - 状态:401,错误:未经授权
【发布时间】:2021-03-09 23:21:17
【问题描述】:

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

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)

不过,这就是我的代码的样子:

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

【问题讨论】:

  • 我在上面的代码中看到了实际的顶点,也许你不想在公共论坛上分享。
  • 我只是将它们更改为一些随机字符。

标签: speech-recognition chatbot ibm-watson speech-to-text


【解决方案1】:

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

IamOptions options = new IamOptions.Builder()
.apiKey("{apikey}")
.build();
Assistant assistant = new Assistant("{version}", options);
assistant.setEndPoint("{url}");

【讨论】:

  • 你能举个例子来帮助未来的用户吗?
  • 我扩展了我的答案
猜你喜欢
  • 2020-02-26
  • 2018-03-06
  • 2020-08-12
  • 1970-01-01
  • 1970-01-01
  • 2015-09-14
  • 2015-04-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多