import subprocess from subprocess import Popen import mouse import time is_recording=False while True: if mouse.is_pressed(button='left') and not is_recording: is_recording=True subprocess.Popen('espeak recording',shell=True) p=subprocess.Popen('./record.py',shell=True) #p.wait() time.sleep(2) elif mouse.is_pressed(button='left') and is_recording: is_recording=False subprocess.Popen('espeak stop recording',shell=True) p.kill() #p.wait() time.sleep(2)