I have the following test code for getting realtime microphone input on macOS:
import AVFoundation // for AVAudioEngine
class Mic
{
public let audioEngine = AVAudioEngine()
func startRecording() throws
{
print("- - -")
let inputNode = audioEngine.inputNode
print("- - -")
if inputNode.inputFormat(forBus: 0).sampleRate == 0 {
exit(0);
}
let recordingFormat = inputNode.outputFormat(forBus: 0)
inputNode.installTap(onBus: 0, bufferSize: 1024, format: recordingFormat) { (buffer: AVAudioPCMBuffer, when: AVAudioTime) in
print( "YES! Got some samples!")
}
audioEngine.prepare()
try audioEngine.start()
}
func stopRecording()
{
audioEngine.stop()
}
}
I get output:
2019-07-22 16:26:36.773244+0300 realtime_mic[8111:540360] [plugin] AddInstanceForFactory: No factory registered for id F8BB1C28-BAE8-11D6-9C31-00039315CD46
2019-07-22 16:26:36.803372+0300 realtime_mic[8111:540360] HALC_ShellDriverPlugIn::Open: Can't get a pointer to the Open routine
2019-07-22 16:26:36.804020+0300 realtime_mic[8111:540360] HALC_ShellDriverPlugIn::Open: Can't get a pointer to the Open routine
Does this mean I'm doing something wrong?
Is it possible to prevent these warnings from displaying on the console?
AVFoundation
framework. I just usedNSSound
andNSSound.play()
inCocoa
. – Olvan