ios – IBM Watson Speech To Text:无法使用swift sdk转录文本

我正在使用IBM Watson语音来发送iOS sdk来转录实时音频.我已经通过可可豆荚安装了它.在将音频转录为文本时,我遇到了问题(身份验证).

已安装的STT sdk版本为0.38.1.

我已经配置了所有内容,正确创建了服务和凭据,并确保使用正确的apikey和URL实例化SpeechToText.每当我调用startStreaming方法时,STT sdk会打印一些错误日志,这似乎与身份验证挑战有关.

这是代码片段.

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) }
  speechToText.recognizeMicrophone(settings: settings, failure: failure) { results in
  accumulator.add(results: results)
  print(accumulator.bestTranscript)

 }
}

错误日志

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

我已经挖掘了IBM Watson sdk文档,甚至用Google搜索了这个问题,但没有找到任何相关的答案.

任何帮助将受到高度赞赏.

最佳答案 随着SpeechToTextV1更改发布了新的版本
1.0.0的Swift SDK,下面的代码适用于我的语音到文本服务API密钥.

除非在达拉斯以外的地区创建服务,否则您不必广泛传递URL.检查URL here

import SpeechToTextV1 // If sdk is installed using Carthage. 
import SpeechToText // If sdk is installed as a pod 

let apiKey = "your-api-key"
let speechToText = SpeechToText(apiKey: apiKey)

var accumulator = SpeechRecognitionResultsAccumulator()

func startStreaming() {
    var settings = RecognitionSettings(contentType: "audio/ogg;codecs=opus")
    settings.interimResults = true
    speechToText.recognizeMicrophone(settings: settings) { response, error in
        if let error = error {
            print(error)
        }
        guard let results = response?.result else {
            print("Failed to recognize the audio")
            return
        }
        accumulator.add(results: results)
        print(accumulator.bestTranscript)
    }
}

func stopStreaming() {
    speechToText.stopRecognizeMicrophone()
}

您可以找到更多示例here

希望这可以帮助!!

点赞