Runtime error with callback function
Closed this issue · 3 comments
I got following runtime errors when running anyone of the test scripts context_manager.py, loopback_callback.py and playback_callback.py.
From cffi callback <function Stream.init..callback_stub at 0x000001975AE45510>:
Traceback (most recent call last):
File "D:\python\Anaconda3\lib\site-packages\pysoundcard.py", line 424, in callback_stub
time_info, status_flags)
File "context_manager.py", line 7, in callback
out_data[:] = in_data
TypeError: 'int' object does not support item assignment
Here is the content of context_manager.py:
`from pysoundcard import Stream, continue_flag
import time
"""Loop back five seconds of audio data."""
def callback(in_data, out_data, time_info, status):
out_data[:] = in_data
return continue_flag
with Stream(samplerate=44100, blocksize=16, callback=callback):
time.sleep(5)
`
This seems to imply that out_data
is an integer in this case, for some reason. Could you debug this and check the types of in_data
, out_data
, time_info
, and status
?
I suspect that your default audio device has only inputs or only outputs, in which case the callback will only be called with either in_data
or out_data
, but not both.
Furthermore, PySoundCard has been unmaintained for quite a while now. I recommend using either SoundDevice for a maintained version of the same API, or SoundCard, for something much easier to use.
I've checked the types of in_data, out_data, time_info, and status.
The results are as follows:
<class 'numpy.ndarray'>
<class 'int'>
<class 'dict'>
<class 'int'>
I've changed the callback function. It works now. Thank you!
def callback(in_data, num_frames, time_info, status):
return (in_data, continue_flag)