Created
September 13, 2021 23:05
-
-
Save rudrankriyam/3ce161779ca0cf2e9f752b8195356a24 to your computer and use it in GitHub Desktop.
HomeViewModel extension ShazamKit
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
// MARK: Audio Recognition | |
extension HomeViewModel { | |
// 1 | |
private func prepareAudioRecording() throws { | |
let audioSession = AVAudioSession.sharedInstance() | |
try audioSession.setCategory(.record) | |
try audioSession.setActive(true, options: .notifyOthersOnDeactivation) | |
} | |
// 2 | |
private func generateSignature() { | |
let inputNode = engine.inputNode | |
let recordingFormat = inputNode.outputFormat(forBus: .zero) | |
inputNode.installTap(onBus: .zero, bufferSize: 1024, | |
format: recordingFormat) { [weak session] buffer, _ in | |
session?.matchStreamingBuffer(buffer, at: nil) | |
} | |
} | |
// 3 | |
private func startAudioRecording() throws { | |
try engine.start() | |
isRecognizingSong = true | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment