Reputation: 5099
I used the Scrumdinger example from Apple to create a speech to text feature in my app. As you can see in the gif below, the text starts typing many seconds after I start talking:
The speech to text functionality is super slow compared to speech to text on native apps like Notes, and users hate that experience. How can I improve the responsiveness? This is the code I use which might be related, I tried to change some of the values without any success though:
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)
}
Additionally, You can download the TestFlight version on this website and view the source code for the entire app on Github
Upvotes: 1
Views: 2186
Reputation: 79
Find the DispatchQueue
function call, try changing the qos
parameter from .background
to .userInteractive
Sample code is wrong, has been reported to Apple.
Upvotes: 7