🔇Unable to run audio libraries in tensorflow-metal virtual environment

Hello,

I made a post earlier comparing the performance between the latest release of tensorflow with apple silicon support: https://developer.apple.com/forums/thread/687654.

In my testing the GitHub alpha greatly outperforms the current release.

  • I provided an installation guide for the GitHub alpha in that post.

sounddevice: https://pypi.org/project/sounddevice/

My goal is to get the python library sounddevice working in either of the virtual environments created by the two different tensorflow releases for apple silicon. Preferably the GitHub alpha, since its much faster.


GitHub alpha venv errors

Installation:

  1. First I make an environment following the installation guide I provided in my first post (linked above).
  2. I activate the virtual environment
  3. I install sounddevice using the following command:
  • $ python3 -m pip install sounddevice


When I try to import sounddevice I get the following errors:

Traceback (most recent call last):
  File "/Users/sadedwar/code/fun/ga-synth/venv/lib/python3.8/site-packages/sounddevice.py", line 72, in <module>
    _lib = _ffi.dlopen(_libname)
OSError: cannot load library '/usr/local/lib/libportaudio.dylib': dlopen(/usr/local/lib/libportaudio.dylib, 2): no suitable image found.  Did find:
	/usr/local/lib/libportaudio.dylib: mach-o, but wrong architecture
	/usr/local/Cellar/portaudio/19.7.0/lib/libportaudio.2.dylib: mach-o, but wrong architecture

tensorflow-metal PluggableDevice errors

Installation:

When I try to run the following code:

myrecording = sd.rec(int(duration * samplerate), samplerate=samplerate, channels=channels)

it yields this error:

Traceback (most recent call last):
  File "/Users/sadedwar/code/fun/ga-synth/makeDatasets.py", line 41, in <module>
    render_dataset(make_simple_dataset(100))
  File "/Users/sadedwar/code/fun/ga-synth/makeDatasets.py", line 37, in render_dataset
    data, samplerate = audioRecorder.play_and_rec()
  File "/Users/sadedwar/code/fun/ga-synth/audioRecorder.py", line 29, in play_and_rec
    recording, samplerate = rec_mono_16bit_8kHz(duration=0.1)
  File "/Users/sadedwar/code/fun/ga-synth/audioRecorder.py", line 17, in rec_mono_16bit_8kHz
    myrecording = sd.rec(int(duration * samplerate), samplerate=samplerate, channels=channels)
  File "/Users/sadedwar/miniforge3/envs/machinelearning/lib/python3.9/site-packages/sounddevice.py", line 274, in rec
    ctx.start_stream(InputStream, samplerate, ctx.input_channels,
  File "/Users/sadedwar/miniforge3/envs/machinelearning/lib/python3.9/site-packages/sounddevice.py", line 2573, in start_stream
    self.stream = StreamClass(samplerate=samplerate,
  File "/Users/sadedwar/miniforge3/envs/machinelearning/lib/python3.9/site-packages/sounddevice.py", line 1415, in __init__
    _StreamBase.__init__(self, kind='input', wrap_callback='array',
  File "/Users/sadedwar/miniforge3/envs/machinelearning/lib/python3.9/site-packages/sounddevice.py", line 836, in __init__
    def callback_ptr(iptr, optr, frames, time, status, _):
MemoryError: Cannot allocate write+execute memory for ffi.callback(). You might be running on a system that prevents this. For more information, see https://cffi.readthedocs.io/en/latest/using.html#callbacks

Any help is appreciated, thank you.

🔇Unable to run audio libraries in tensorflow-metal virtual environment
 
 
Q