Saa*_*mer 1 speech-recognition avfoundation speech-to-text ios swift
我使用Apple 的Scrumdinger示例在我的应用程序中创建了语音转文本功能。正如您在下面的 gif 中看到的,在我开始讲话几秒钟后,文本开始输入:

与 Notes 等本机应用程序上的语音转文本功能相比,语音转文本功能非常慢,而且用户讨厌这种体验。如何提高响应能力?这是我使用的代码,可能与之相关,但我尝试更改一些值,但没有成功:
private static func prepareEngine() throws -> (AVAudioEngine, SFSpeechAudioBufferRecognitionRequest) {
let audioEngine = AVAudioEngine()
let request = SFSpeechAudioBufferRecognitionRequest()
request.shouldReportPartialResults = true
// Configure the audio session for the app.
let audioSession = AVAudioSession.sharedInstance()
try audioSession.setCategory(.record, mode: .measurement, options: .duckOthers)
try audioSession.setActive(true, options: .notifyOthersOnDeactivation)
let inputNode = audioEngine.inputNode
// Configure the microphone input.
let recordingFormat = inputNode.outputFormat(forBus: 0)
inputNode.installTap(onBus: 0, bufferSize: 1024, format: recordingFormat) { (buffer: AVAudioPCMBuffer, when: AVAudioTime) in
request.append(buffer)
}
audioEngine.prepare()
try audioEngine.start()
return (audioEngine, request)
}
Run Code Online (Sandbox Code Playgroud)
此外,您可以在此网站上下载 TestFlight 版本,并在Github上查看整个应用程序的源代码