python-sounddevice icon indicating copy to clipboard operation
python-sounddevice copied to clipboard

Issue changing the callback "frames"

Open kraykai opened this issue 4 years ago • 1 comments

Hello, I am using a sounddevice.Stream with a callback function and want to change the "frames". I can't seem to find a way to do this. When, in the line containing "sd.Stream" I attempt to do the following...

with sd.Stream(channels=1, callback=callback(frames=1024)): sd.sleep(int(duration * 1000))

...I get the following error TypeError: callback() missing 4 required positional arguments: 'indata', 'outdata', 'time', and 'status'"

How can I change the frame size? Thanks

Here is the full code

def callback(indata, outdata, frames, time, status): if status: print(status) print(str(indata.shape) + str(type(indata))) indata1 = np.clip(indata, a_min= -0.01, a_max= +0.01) outdata[:] = indata1

with sd.Stream(channels=1, callback=callback(frames=1024)): sd.sleep(int(duration * 1000))

kraykai avatar Jul 11 '21 13:07 kraykai

Please post code in a Markdown environment, so it is readable and indentations is preserved. Also, there seems to be some imports and variable definitions missing.

```python
print('Code')
```

To answer your question. I assume you want to change the overall block length? You can do so with

sd.Stream(blocksize=1024, channels=1, callback=callback)

You probably also want to take a look at the other parameters in sd.Stream() to get the data from the correct device, sample rate, etc.

HaHeho avatar Jul 11 '21 19:07 HaHeho