0

I don't have enough knowledge about Pyaudio and I couldn't find it on the net. I want the script run until I stop it and when I stop, it must save recording. The sample code from Pyaudio records for a fixed time.

Ilkin
  • 386
  • 3
  • 17
  • Have a look at my example [rec_unlimited.py](https://github.com/spatialaudio/python-sounddevice/blob/master/examples/rec_unlimited.py). – Matthias May 02 '17 at 08:43

1 Answers1

0

What you need to do is use error handling to save the audio once you have a keyboard exception, (in this case pressing something like Ctrl + C to end the program.

While True:
    try:
        recording_function()

    except KeyboardInterrupt:
        save_function() #record to a file
    except: 
        #generic error processing
zglin
  • 2,891
  • 2
  • 15
  • 26
  • Thanks, it works. How can I handle termination? I found atexit but it doesn't handle termination – Ilkin May 02 '17 at 15:17
  • how are you terminating the script? Is it a button or someother method? – zglin May 02 '17 at 19:13
  • with a button or directly closing window – Ilkin May 03 '17 at 15:25
  • with a button use the onclick handler in whatever GUI Framework you have, otherwise use `atexit` to serve as an exit handler (https://docs.python.org/3/library/atexit.html) – zglin May 03 '17 at 16:24