Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Record audio with any duration. #24

Closed
rodrimaia opened this issue May 7, 2016 · 6 comments
Closed

Record audio with any duration. #24

rodrimaia opened this issue May 7, 2016 · 6 comments

Comments

@rodrimaia
Copy link

Hi, I am trying to create a 'loop pedal' emulator, and I need to start recording audio without a duration already specified. Something like 'record audio until I want'. I dont know how to do that in sounddevice. Is this possible?

@mgeier
Copy link
Member

mgeier commented May 10, 2016

This is certainly possible but you'll have to implement it yourself using the callback API.

The reason why sounddevice.rec() uses a pre-defined duration, is to be able to allocate all necessary memory in one big NumPy array beforehand.

You could extend that to arbitrary durations by appending to a list of audio blocks in each callback.
Once you have enough, you can stop() (or abort()) the stream and afterwards join your list of audio blocks into a big NumPy array (if needed).

Note that allocating memory within the time-constrained callback may take too long, which may lead to drop-outs in your recording. You should be able to detect those with the status argument of your callback function. As long as status doesn't contain any error bits, you should be fine.

@mgeier
Copy link
Member

mgeier commented May 14, 2016

I've created an example showing how to record for an arbitrary amount of time: rec_unlimited.py.

Does this help?

@rodrimaia
Copy link
Author

Helps A LOT! thank you so much. I will experiment a little bit and try to do my 'loop pedal emulator'. this is extremely helpful. This module is awesome.

@ghost
Copy link

ghost commented Jun 23, 2021

Dude you gave me the exact thing which i needed, thanks

@egzon-korenica
Copy link

I've created an example showing how to record for an arbitrary amount of time: rec_unlimited.py.

Does this help?

This code is amazing, I was wondering though, is it possible to do multiple recordings in one session? I mean when you click ctrl+c the whole program shuts down.

@HaHeho
Copy link

HaHeho commented Jul 27, 2021

This code is amazing, I was wondering though, is it possible to do multiple recordings in one session? I mean when you click ctrl+c the whole program shuts down.

I mean, that is what the code does. There is nothing happening after catching the KeyboardInterrupt. You can modify that of course, like adding similar code afterwards or putting it inside a loop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants