Created
May 26, 2021 10:15
-
-
Save iosdevie/8187ea967b6fd8b21c6c6ab5fe89088e to your computer and use it in GitHub Desktop.
The AVAudioEngine is responsible for receiving the audio signals from the microphone. It provides our input for speech recognition.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let audioEngine = AVAudioEngine() | |
let audioSession = AVAudioSession.sharedInstance() | |
try audioSession.setCategory(.record, mode: .measurement, options: .duckOthers) | |
try audioSession.setActive(true, options: .notifyOthersOnDeactivation) | |
let inputNode = audioEngine.inputNode | |
inputNode.removeTap(onBus: 0) | |
let recordingFormat = inputNode.outputFormat(forBus: 0) | |
inputNode.installTap(onBus: 0, bufferSize: 1024, format: recordingFormat) { (buffer: AVAudioPCMBuffer, when: AVAudioTime) in | |
self.recognitionRequest?.append(buffer) | |
} | |
audioEngine.prepare() | |
try audioEngine.start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment