首页 > 解决方案 > 沃森语音到文本未经授权的请求错误 401

问题描述

我尝试使用 IBM Watson GitHub 存储库中的代码,我不得不对粘贴时遇到的一些错误进行一些更改。然后我尝试运行代码以查看它从音频文件到文本的转录。但我得到错误 401 未经授权。我试图查看解决方案,但没有找到。她是我的密码,

SpeechToText service = new SpeechToText();
IamOptions options1 = new IamOptions.Builder()
  .apiKey("{apikey}")
  .build();
service.setIamCredentials(options1);

File audio = new File("C:\\Users\\usern\\Downloads\\audio-file.FLAC");

RecognizeOptions options = new RecognizeOptions.Builder()
  .audio(audio)
  .contentType(HttpMediaType.AUDIO_FLAC)
  .build();

SpeechRecognitionResults transcript = service.recognize(options).execute().getResult();
System.out.println(transcript);

标签: javaibm-cloudibm-watsonspeech-to-text

解决方案


所以我要解决这个问题的答案是添加service.setEndPoint("https://gateway-lon.watsonplatform.net/speech-to-text/api"); 为第二行。我的 URL 是在查看 IBM 云服务网站上的凭证时找到的,并不是说该 URL 与我在伦敦的我所在的 URL 可能不同。


推荐阅读