Running SoundCard on Jupyter Notebook

I have been running SoundCard (0.4.1) on Jupyter Notebook for several years using a laptop with Mint 18.3, Python 3.6.4:Anaconda, Jupyter 4.4.0 . No problems… still works today.
I now run exactly the same notebook on a NUC i3 with Mint 22.1, Python 3.12.3, Jupyter 7.4.3.
In line with recommendations on this forum to work in a virtual environment, I run using uv as follows:
uv run --with jupyter --with numpy --with soundcard jupyter notebook
Installation appears to complete correctly.

import numpy as np
import soundcard as sc

x = np.linspace(0,1,1440001) # 2 minutes of sine wave
y = np.sin (2np.pi1500*120 * x) # at 1500 Hz

speakers = sc.all_speakers()
print(speakers)

my_speaker = sc.get_speaker (‘Audio Analog’)
my_speaker.play (y[:100000], samplerate = 120000) # First 8 seconds


I now get the following error message


AttributeError Traceback (most recent call last)
Cell In[1], line 11
8 print(speakers)
10 my_speaker = sc.get_speaker (‘Audio Analog’)
—> 11 my_speaker.play (y[:100000], samplerate = 120000) # First 8 seconds

File ~/.cache/uv/archive-v0/X6dwS-78MQS5Kvb-mB40E/lib/python3.12/site-packages/soundcard/pulseaudio.py:555, in _Speaker.play(self, data, samplerate, channels, blocksize)
553 channels = self.channels
554 with _Player(self._id, samplerate, channels, blocksize) as s:
→ 555 s.play(data)

File ~/.cache/uv/archive-v0/X6dwS-78MQS5Kvb-mB40E/lib/python3.12/site-packages/soundcard/pulseaudio.py:786, in _Player.play(self, data)
784 time.sleep(0.001)
785 continue
→ 786 bytes = data[:nwrite].ravel().tostring()
787 _pulse._pa_stream_write(self.stream, bytes, len(bytes), _ffi.NULL, 0, _pa.PA_SEEK_RELATIVE)
788 data = data[nwrite:]

AttributeError: ‘numpy.ndarray’ object has no attribute ‘tostring’

Is this a problem from Jupyter, from Mint or from Python? What is the solution?
Thanks for help.

Follow up, since there have been no responses from the forum yet.

It appears that on June 7, 2025, Numpy was upgraded to version 2.3.0.
According to the release notes np.tostring was removed.

This probably explains why I am getting the attributerrors telling that there is no tostring attribute.
But I do not know which program called it
Should I be requesting assistance from SoundCard or one of its dependencies?
Anybody else got the same problem?

My workaround is to remove numpy 2.3.0 and install 2.2.6. That works! I have sound back!

But I would like to recommend that the source program, which uses tostring, find an alternative attribute that numpy can accept.

This has been filed to be handled on the issues page of the SoundCard software you asked about, see here and here.

Note that you could have answered this question yourself, at least in part. I suspect you needed Jupyter for Mint interaction? However, when trying to troubleshoot it is always best to try to reduce it to a minimal reproducible example. It looks like the first 11 lines of your code don’t involve anything dependent on Jupyter or Mint and so you could have run it in Python directly. If you ran this in Python separate from Jupyter, you’d likely have the same issue. (And thus, would likely make the issue not pertinent to this forum.) I see you are using uv to run Jupyter, and uv also makes it easy to test things like this without Jupyter in the mix, more of the traditional way you’d run Python in a terminal/console or in a script containing python code that you call from the command line like python my_script.py. Removing Jupyter from the mix in this manner is a step, or at least ‘thought exercise’, you should go through when trying to find the right place to post about similar issues.

1 Like

Thanks for the response, advice and comments. Not being a programmer, but just a user of Jupyter Notebooks, the sudden onslaught of error messages is difficult to interpret. Hopefully this problem with Soundcard will shortly be resolved.

Don’t sell you self short. Your solution of rolling back was exactly one option a programmer might try. Ans so you seem to have handled it well.
Just to let you know, this sort of thing with code you have been using in the past not quite working when packages get updated happens from time to time. So don’t let the onslaught of error messages get you down. You already have one example that you can handle such things now.

1 Like