I'm writing a Python app to record audio as a WAV file until a user presses pause or stop. After pausing the audio, the user should also be able to resume recording. Additionally:
The app can't know how long the recording will be beforehand
The app should avoid running out of memory (since the recording could be very long). For example, it could write to the WAV file in real-time to prevent storing the growing recording in memory.
What's a good approach for this problem? Can you please provide some code snippets for your solution?
With
I don't know how big to make the array (since I don't know the recording duration)
What would I do when the array fills up?
How would I incorporate 'pause' and 'resume' features? Sound-file has only read and write methods.
Is there a better way to stop the stream than using a KeyBoardInterrupt?
Could I create different recording after every 'pause' and combine the WAV files after the user clicks 'stop'?
I tried using Threading.Event() to block the recording thread to mimic a pause feature, but the recording kept writing to the file
My attempt at sound-device approach