简体   繁体   中英

watson speech to text unauthorized request error401

I tried to use the code from IBM Watson GitHub repository I had to change a little bit for some errors I got when pasting it. I tried then to run the code to see it transcript from an audio file to text. But I got error 401 unauthorized. I tried to see solutions but didn't find one. Her is my code,

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

So the answer was for me to solve this was to add service.setEndPoint("https://gateway-lon.watsonplatform.net/speech-to-text/api"); as the second line. URL for me was found looking at the Credentials at the IBM cloud service website, not that the URL might be different compared to mine where mine is located at London.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM