I am trying to use pyaudio to stream input from the microphone on M1 MacBookPro, but getting OSErrors. Here is the code to list different microphones,
def list_microphones(pyaudio_instance):
info = pyaudio_instance.get_host_api_info_by_index(0)
numdevices = info.get('deviceCount')
result = []
for i in range(0, numdevices):
if (pyaudio_instance.get_device_info_by_host_api_device_index(0, i).get('maxInputChannels')) > 0:
name = pyaudio_instance.get_device_info_by_host_api_device_index(
0, i).get('name')
result += [[i, name]]
return result
On running this I get two microphone (external and inbuilt) -- [[0, 'External Microphone'], [2, 'MacBook Pro Microphone']]. I have tried both options,
Microphone 1 or 2: Internal -- Error is OSError: [Errno -9999] Unanticipated host error
Code
audio = pyaudio.PyAudio()
FORMAT = pyaudio.paInt16
CHANNELS = 1
RATE = 44100
FRAME_DURATION = 30
CHUNK = int(RATE * FRAME_DURATION / 1000)
RECORD_SECONDS = 50
#
stream = audio.open(input_device_index=2, # or 0
format=FORMAT,
channels=CHANNELS,
rate=RATE,
input=True,
frames_per_buffer=CHUNK)
Error
||PaMacCore (AUHAL)|| AUHAL component not found.Exception in thread Thread-2:
Traceback (most recent call last):
File "/opt/homebrew/Caskroom/miniforge/base/envs/op_asr/lib/python3.8/threading.py", line 932, in _bootstrap_inner
self.run()
File "/opt/homebrew/Caskroom/miniforge/base/envs/op_asr/lib/python3.8/threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "live-whisper-asr.py", line 61, in vad_process
stream = audio.open(input_device_index=2,
File "/opt/homebrew/Caskroom/miniforge/base/envs/op_asr/lib/python3.8/site-packages/pyaudio.py", line 754, in open
stream = Stream(self, *args, **kwargs)
File "/opt/homebrew/Caskroom/miniforge/base/envs/op_asr/lib/python3.8/site-packages/pyaudio.py", line 445, in __init__
self._stream = pa.open(**arguments)
OSError: [Errno -9999] Unanticipated host error
Thank you!