Audio Recording in OpenSesame on MacOS (M1)
Hi all,
I am having issues with recording sounds on my M1 Mac in OpenSesame. But I am able to play .wav files with the sampler item in OS without any problems.
I tried multiple plugins/packages without success, as I get roughly the same error message -9986. Please find the detailed errors below.
I think the main issue lies with Portaudio with my Mac in Opensesame specifically. It works well in Pycharm on my Mac, but not in Opensesame.
As a workaround I thought of copying the Portaudio files from my Mac to the OS folder. Which files should I copy to which folder then?
I had tried to copy the portaudio files to my Opensesame environment but failed because I wasn't sure where to copy them.
The Sounddevice package does show me my sounddevices correctly, so I dont't understand what the issue really is.
sd.query_devices() Out[10]: 0 iPhone Microphone, Core Audio (1 in, 0 out) > 1 MacBook Air Microphone, Core Audio (1 in, 0 out) < 2 MacBook Air Speakers, Core Audio (0 in, 2 out) 3 Microsoft Teams Audio, Core Audio (2 in, 2 out)
Could someone guide me through this issue? Audio recording is essential to my study.
Thanks!
For example, this is the message I get when I try to install Pyaudio in OS:
pip install pyaudio Collecting pyaudio Using cached PyAudio-0.2.13.tar.gz (46 kB) Installing build dependencies ... [?25ldone etting requirements to build wheel ... e g metadata (pyproject.toml) ... [?25ldone uilding wheels for collected packages: pyaudio Building wheel for pyaudio (pyproject.toml) ... [?25lerror error: subprocess-exited-with-error × Building wheel for pyaudio (pyproject.toml) did not run successfully. │ exit code: 1 ╰─> [19 lines of output] running bdist_wheel running build running build_py creating build creating build/lib.macosx-10.9-x86_64-cpython-311 creating build/lib.macosx-10.9-x86_64-cpython-311/pyaudio copying src/pyaudio/__init__.py -> build/lib.macosx-10.9-x86_64-cpython-311/pyaudio running build_ext building 'pyaudio._portaudio' extension creating build/temp.macosx-10.9-x86_64-cpython-311 creating build/temp.macosx-10.9-x86_64-cpython-311/src creating build/temp.macosx-10.9-x86_64-cpython-311/src/pyaudio clang -DNDEBUG -fwrapv -O2 -Wall -fPIC -O2 -isystem /Applications/OpenSesame.app/Contents/Resources/include -fPIC -O2 -isystem /Applications/OpenSesame.app/Contents/Resources/include -DMACOS=1 -I/usr/local/include -I/usr/include -I/opt/homebrew/include -I/usr/local/Cellar/portaudio/19.7.0/include -I/Applications/OpenSesame.app/Contents/Resources/include/python3.11 -c src/pyaudio/device_api.c -o build/temp.macosx-10.9-x86_64-cpython-311/src/pyaudio/device_api.o In file included from src/pyaudio/device_api.c:1: src/pyaudio/device_api.h:7:10: fatal error: 'Python.h' file not found #include "Python.h" ^~~~~~~~~~ 1 error generated. error: command '/usr/bin/clang' failed with exit code 1 [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed building wheel for pyaudio ailed to build pyaudio ERROR: Could not build wheels for pyaudio, which is required to install pyproject.toml-based projects
And this is the message for the sounddevice package:
myrecording = sd.rec(int(seconds * fs), samplerate=fs, channels=1) sd.wait() # Wait until recording is finished write('output.wav', fs, myrecording) # Save as WAV file ||PaMacCore (AUHAL)|| Error on line 1277: err='-66748', msg=Unknown Error --------------------------------------------------------------------------- PortAudioError Traceback (most recent call last) Cell In[14], line 1 ----> 1 myrecording = sd.rec(int(seconds * fs), samplerate=fs, channels=1) 2 sd.wait() # Wait until recording is finished 3 write('output.wav', fs, myrecording) # Save as WAV file File /Applications/OpenSesame.app/Contents/Resources/lib/python3.11/site-packages/sounddevice.py:276, in rec(frames, samplerate, channels, dtype, out, mapping, blocking, **kwargs) 273 ctx.read_indata(indata) 274 ctx.callback_exit() --> 276 ctx.start_stream(InputStream, samplerate, ctx.input_channels, 277 ctx.input_dtype, callback, blocking, **kwargs) 278 return out File /Applications/OpenSesame.app/Contents/Resources/lib/python3.11/site-packages/sounddevice.py:2582, in _CallbackContext.start_stream(self, StreamClass, samplerate, channels, dtype, callback, blocking, **kwargs) 2579 def start_stream(self, StreamClass, samplerate, channels, dtype, callback, 2580 blocking, **kwargs): 2581 stop() # Stop previous playback/recording -> 2582 self.stream = StreamClass(samplerate=samplerate, 2583 channels=channels, 2584 dtype=dtype, 2585 callback=callback, 2586 finished_callback=self.finished_callback, 2587 **kwargs) 2588 self.stream.start() 2589 global _last_callback File /Applications/OpenSesame.app/Contents/Resources/lib/python3.11/site-packages/sounddevice.py:1421, in InputStream.__init__(self, samplerate, blocksize, device, channels, dtype, latency, extra_settings, callback, finished_callback, clip_off, dither_off, never_drop_input, prime_output_buffers_using_stream_callback) 1391 def __init__(self, samplerate=None, blocksize=None, 1392 device=None, channels=None, dtype=None, latency=None, 1393 extra_settings=None, callback=None, finished_callback=None, 1394 clip_off=None, dither_off=None, never_drop_input=None, 1395 prime_output_buffers_using_stream_callback=None): 1396 """PortAudio input stream (using NumPy). 1397 1398 This has the same methods and attributes as `Stream`, except (...) 1419 1420 """ -> 1421 _StreamBase.__init__(self, kind='input', wrap_callback='array', 1422 **_remove_self(locals())) File /Applications/OpenSesame.app/Contents/Resources/lib/python3.11/site-packages/sounddevice.py:898, in _StreamBase.__init__(self, kind, samplerate, blocksize, device, channels, dtype, latency, extra_settings, callback, finished_callback, clip_off, dither_off, never_drop_input, prime_output_buffers_using_stream_callback, userdata, wrap_callback) 896 userdata = _ffi.NULL 897 self._ptr = _ffi.new('PaStream**') --> 898 _check(_lib.Pa_OpenStream(self._ptr, iparameters, oparameters, 899 samplerate, blocksize, stream_flags, 900 callback_ptr, userdata), 901 f'Error opening {self.__class__.__name__}') 903 # dereference PaStream** --> PaStream* 904 self._ptr = self._ptr[0] File /Applications/OpenSesame.app/Contents/Resources/lib/python3.11/site-packages/sounddevice.py:2747, in _check(err, msg) 2744 hosterror_info = host_api, info.errorCode, hosterror_text 2745 raise PortAudioError(errormsg, err, hosterror_info) -> 2747 raise PortAudioError(errormsg, err) PortAudioError: Error opening InputStream: Internal PortAudio error [PaErrorCode -9986]