0

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);
CoderX9
  • 115
  • 1
  • 2
  • 12
  • How did you obtain your api key, and for which region did you obtain it? The answers to these questions, may indicate why you are getting the 401. – chughts Jul 18 '19 at 14:49
  • I obtain API key from https://cloud.ibm.com/ and it was for Europe I suppose @chughts – CoderX9 Jul 18 '19 at 16:34

1 Answers1

0

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.

CoderX9
  • 115
  • 1
  • 2
  • 12