【发布时间】:2017-06-15 05:17:22
【问题描述】:
快速入门的新手!我正在尝试实现一个使用语音识别器将语音转换为文本的应用程序。
问题 SFSpeechRecognizer().isAvailable 是false
private let request = SFSpeechAudioBufferRecognitionRequest()
private var task: SFSpeechRecognitionTask?
private let engine = AVAudioEngine()
func recognize() {
guard let node = engine.inputNode else {
return
}
let recordingFormat = node.outputFormat(forBus: 0)
node.installTap(onBus: 0, bufferSize: 1024, format: recordingFormat) { buffer, _ in
self.recognitionRequest.append(buffer);
}
engine.prepare()
do {
try engine.start()
} catch {
return print(error)
}
guard let systemRecognizer = SFSpeechRecognizer() else {
return
}
if !systemRecognizer.isAvailable {
self.log(.debug, msg: "Entered this condition and stopped!")
return
}
}
问题
我不确定它为什么会在模拟器中停止。麦克风可以在 iPhone 模拟器中使用吗?
更新 我尝试使用以下代码测试音频文件,
let audioFile = Bundle.main.url(forResource: "create_activity", withExtension: "m4a", subdirectory: "Sample Recordings")
let recognitionRequest = SFSpeechURLRecognitionRequest(url: audioFile!)
收到错误消息,Error Domain=kAFAssistantErrorDomain Code=1101 "(null)"
【问题讨论】:
-
所以,这意味着我们只能在模拟器中通过音频文件对其进行测试。对吗?
-
是的,正确,....
标签: ios iphone swift speech-recognition