Created
February 8, 2018 05:05
-
-
Save SunXiaoShan/71fb8bd4abd934cbf77a2d33f6e2cca2 to your computer and use it in GitHub Desktop.
VoiceRecognition
This file contains hidden or 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
recognitionRequest = SFSpeechAudioBufferRecognitionRequest() | |
let inputNode = self.getInputNode() | |
guard let recognitionRequest = recognitionRequest else { fatalError("Unable to created a SFSpeechAudioBufferRecognitionRequest object") } | |
// Configure request so that results are returned before audio recording is finished | |
recognitionRequest.shouldReportPartialResults = true | |
let recognizer = SFSpeechRecognizer(locale: Locale(identifier: (self.localeIdentifier)!)) | |
recognizer?.recognitionTask(with: recognitionRequest, delegate: self) | |
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