IBM Watson Speech To Text:无法使用 Swift SDK 转录文本

IBM Watson Speech To Text : Not able to transcribe the text using the Swift SDK

我正在使用 IBM Watson speech to text iOS SDK 来转录实时音频。我已经通过 cocoa pods 安装了它。我在将音频转录为文本时遇到问题(身份验证)。

安装的STT SDK版本为0.38.1

我已经配置了所有内容,正确创建了服务和凭证,并确保 SpeechToText 使用正确的 apikeyURL 实例化。每当我调用 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 文档,甚至用谷歌搜索了这个问题,但没有找到任何相关答案。

Swift SDK 的新版本1.0.0 已发布,其中包含 SpeechToTextV1 更改,下面的代码适用于 Speech to Text 服务 API Key。

除非服务是在达拉斯以外的区域创建的,否则您不必大量通过 URL。检查 URLs 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

希望对您有所帮助!!