iOS   发布时间:2022-03-30  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios – IBM Watson Speech To Text:无法使用swift sdk转录文本大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用IBM Watson语音来发送iOS sdk来转录实时音频.我已经通过可可豆荚安装了它.在将音频转录为文本时,我遇到了问题(身份验证).

已安装的STT sdk版本为0.38.1.@H_675_7@

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

这是代码片段.@H_675_7@

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)

 }
}

错误日志@H_675_7@

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搜索了这个问题,但没有找到任何相关的答案.@H_675_7@

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

解决方法

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

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

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@H_675_7@

希望这可以帮助!!@H_675_7@

大佬总结

以上是大佬教程为你收集整理的ios – IBM Watson Speech To Text:无法使用swift sdk转录文本全部内容,希望文章能够帮你解决ios – IBM Watson Speech To Text:无法使用swift sdk转录文本所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。