spatialaudio / python-sounddevice

:sound: Play and Record Sound with Python :snake:
https://python-sounddevice.readthedocs.io/
MIT License
982 stars 145 forks source link

Issue changing the callback "frames" #351

Open kraykai opened 3 years ago

kraykai commented 3 years ago

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))

HaHeho commented 3 years ago

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
```python
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.