What is a simple solution to record audio in Python with pause, resume and no duration time?

Viewed 20

I'm looking for a simple solution for audio recording with pause, resume and no duration time. pyaudio, sounddevice, I can do something with them, but this is a rather low level. The difficulty is that they require duration time for recording, that is, the recording time that must be set initially. In my case, the recording should continue until the appropriate code is called to stop. I found code to record without duration time in sounddevice, but it's still complicated and not a library to use in other parts of the code: https://github.com/spatialaudio/python-sounddevice/blob/master/examples/rec_unlimited.py The easiest way to record that I was able to find is using the recorder library: https://pypi.org/project/recorder/ Here is the code for a simple voice recorder that I managed to find:

import tkinter as tk
from tkinter import *
import recorder 

window = Tk()#creating window
window.geometry('700x300')#geomtry of window
window.title('TechVidvan')#title to window
Label(window,text="Click on Start To Start Recording",font=('bold',20)).pack()#label

rec = recorder.Recorder(channels=2)
running = None

def start():
    global running

    if running is not None:
        print('already running')
    else:
        running = rec.open('untitled.flac', 'wb')
        running.start_recording()
    Label(window,text='Recording has started').pack()

def stop():
    global running

    if running is not None:
        running.stop_recording()
        running.close()
        running = None
        Label(window,text='Recording has stoped').pack()
    else:
        print('not running')


Button(window,text='Start',bg='green',command=start,font=('bold',20)).pack()#create a button
Button(window,text='Stop',bg='green',command=stop,font=('bold',20)).pack()#create a button

window.mainloop()

But the question of pause and resume is still open. Maybe you can advise something? Thanks in advance!

1 Answers

I'd recommend using either the SimpleSound package or pyaudio

import simplesound as sa
import pyaudio as pa

for recording sound pyaudio might be a better choice, but have a play around and see what works for you <3

Related