watson-developer-cloud / speech-to-text-swift

Speech-to-Text example using the Swift SDK
Apache License 2.0
34 stars 17 forks source link

Authentication error occurred: Not able to transcribe the audio #17

Closed kamarshad closed 5 years ago

kamarshad commented 5 years ago

I want to transcribe the real-time audio and using this library for the same. I have installed it through cocoa pods (Also tried integrating it using the Carthage got the same error.). I am stuck with an issue (authentication) while transcribing the audio to text.

The installed STT sdk version is 0.38.1.

I have configured everything correctly, created the service at (https://console.bluemix.net/catalog/services/speech-to-text) and using the correct credential and also making sure SpeechToText instantiated with proper apikey and URL. Whenever I call the startStreaming method sdk prints some error log, which might be related to the authentication challenge.

   let speechToText = SpeechToText(apiKey: Credentials.SpeechToTextAPIKey, iamUrl: Credentials.SpeechToTextURL)
   var accumulator = SpeechRecognitionResultsAccumulator()

   func startStreaming()  {
    var settings = RecognitionSettings(contentType: "audio/ogg;codecs=opus")
    settings.interimResults = true
    let failure = { (error: Error) in print("Error: \(error) Error localised info: \ (error.localizedDescription)") }
    speechToText.recognizeMicrophone(settings: settings, failure: failure) { results in
    accumulator.add(results: results)
    print(accumulator.bestTranscript)
   }
 }

sdk auto printed logs

  CredStore - performQuery - Error copying matching creds.  Error=-25300,  query={
    class = inet;
    "m_Limit" = "m_LimitAll";
    ptcl = htps;
   "r_Attributes" = 1;
   sdmn = "IBM Watson Gateway(Log-in)";
   srvr = "gateway-syd.watsonplatform.net";
   sync = syna;
 }

Logs printed in error clouser Error: failure(401, "unauthorized") Error localised info: The operation couldn’t be completed. (RestKit.RestError error 0.)

Xcode: 10.1 iPhone device: iPhoneX(12.0)/iPhone7(11.4)

Looking for your help Thanks

kamarshad commented 5 years ago

Can someone help me in regard to above issue? @jthomas @schen22 @HughMorrow @tmarkiewicz @glennrfisher It would be a great help.

AnthonyOliveri commented 5 years ago

Since you're using IBM's public cloud, you don't need to set the iamUrl parameter in the SpeechToText initializer. Try removing that parameter and see if it authenticates properly.

kamarshad commented 5 years ago

Hello @AnthonyOliveri Thank you for your reply. I also tried initializing the SpeechToText only with apikey but not able to authenticate and got the error below.

speechToText = SpeechToText(apiKey: Credentials.SpeechToTextAPIKey)

Error log WSError(type: Starscream.ErrorType.upgradeError, message: "Invalid HTTP upgrade", code: 401)

AnthonyOliveri commented 5 years ago

That error is coming from a third party dependency Starscream, so I won't be able to help as much with that. I did a google search of the error, which returned a LOT of issues that have been opened against Starscream for that error message. Hopefully one of those issues contains the solution you need.

Can you try using the recognize method that doesn't use websockets? That way we can see if this error is in fact specific to Starscream, which handles the websocket connections.

kamarshad commented 5 years ago

Hello @AnthonyOliveri,

Thanks for your reply. Yesterday released version 1.0.0 solved the issue but if one create the service in Dallas region(though not verified it for other region). And apikey is sufficient for intantiating the SpeechToText

speechToText = SpeechToText(apiKey: Credentials.SpeechToTextAPIKey)
AnthonyOliveri commented 5 years ago

Honestly, I'm not sure how that resolved the issue, but I'm glad it did!

To clarify, are you saying that it does or does not work in Dallas?

kamarshad commented 5 years ago

I have tested it for Dallas region and it is working fine for it. Thank you

leitdeux commented 5 years ago

@kamarshad If you're using locations other than Dallas, make sure to set the serviceURL property of your SpeechToText instance. I was also struggling with the same authentication 401 errors thrown by Starscream until I read through the readme again in the swift-sdk repository:

https://github.com/watson-developer-cloud/swift-sdk

So, if your Watson service location was Tokyo, for example, you'd want the following:

let speechToText = SpeechToText(apiKey: "your-api-key")
speechToText.serviceURL = "https://gateway-tok.watsonplatform.net/speech-to-text/api"