diff --git a/audios/20190703-180345.wav b/audios/20190703-180345.wav deleted file mode 100644 index fbca91f..0000000 Binary files a/audios/20190703-180345.wav and /dev/null differ diff --git a/keytest.py b/keytest.py deleted file mode 100755 index 14b833b..0000000 --- a/keytest.py +++ /dev/null @@ -1,8 +0,0 @@ -from pynput.keyboard import Key, Controller - -keyboard = Controller() - -while True: - if keyboard.press('space'): - print ('You Pressed A Key!') - diff --git a/mouse-record.py b/mouse-record.py new file mode 100755 index 0000000..0d305f5 --- /dev/null +++ b/mouse-record.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python3 +import subprocess +import shutil +import shlex +import os +import mouse +from datetime import datetime +from time import sleep + +home_path = os.path.dirname(os.path.abspath(__file__)) +recordings_path = home_path + '/audios/' +archive_path='/media/pi/97A6-3AD6' +#recordings_path = 'audios/' +recording_tmp_file = recordings_path + '.temp.wav' +cmd = "arecord -f cd -D hw:1,0 {}".format(recording_tmp_file) +cmd = shlex.split(cmd) + + + + +start_rec=datetime.now() +is_recording = False +while True: + if mouse.is_pressed(button='left') and not is_recording: + start_rec=datetime.now() + is_recording = True + # start recording + print ('rec') + subprocess.Popen('espeak recording',shell=True) + rec = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=False) + sleep(1) + elif (mouse.is_pressed(button='left') and is_recording) or ((datetime.now()-start_rec).seconds > 60 and is_recording): + is_recording = False + print('stop') + # stop recording & rename soundfile + rec.kill() + now = datetime.now().strftime('%Y%m%d-%H%M%S') + recording_file = recordings_path + 'rec_' + now + '.wav' + subprocess.Popen('espeak stop recording',shell=True) + print(recording_tmp_file, recording_file) + os.rename(recording_tmp_file, recording_file) + #if sum([len(files) for r, d, files in os.walk(recordings_path)])>10: + audiofiles=os.listdir(path=recordings_path) + if len(audiofiles)>5: + for audiofile in audiofiles: + if audiofile.startswith("rec_"): + print (audiofile) + shutil.move(recordings_path + audiofile,(archive_path + '/archive_audios/')) + print ('recordings moved to archive_audios') + sleep(1) + sleep(0.01) diff --git a/mouse-test.py b/mouse-test.py deleted file mode 100755 index 180eac4..0000000 --- a/mouse-test.py +++ /dev/null @@ -1,20 +0,0 @@ -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) diff --git a/playback-loop.py b/playback-loop.py index d22892a..74d2a48 100755 --- a/playback-loop.py +++ b/playback-loop.py @@ -3,17 +3,23 @@ import os, subprocess, shlex import glob from random import choice +from time import sleep -home_path = os.path.abspath(__file__) -#recordings_path = home_path + '/audios/*' -recordings_path = 'audios/*' -while True: - soundfiles=glob.glob(recordings_path) - print(soundfiles) - sound = choice(soundfiles) - cmd = "aplay -f cd -D hw:1,0 {}".format(sound) - cmd = shlex.split(cmd) - subprocess.call(cmd) +home_path = os.path.dirname(os.path.abspath(__file__)) +recordings_path = home_path + '/audios/*' +while True: + print(recordings_path) + soundfiles = glob.glob(recordings_path) + if len(soundfiles) > 0: # if there are files + #print(soundfiles) + sound = choice(soundfiles) + print(sound) + cmd = "play {} -c 1".format(sound) + cmd = shlex.split(cmd) + subprocess.call(cmd) + else: # if there are no files; sleep; and check again if there are files + sleep(2) + # sleep(1) diff --git a/record.py b/record.py deleted file mode 100755 index ef84921..0000000 --- a/record.py +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/env python3 -import subprocess -import shlex -import os -from datetime import datetime -from time import sleep - -now = datetime.now().strftime('%Y%m%d-%H%M%S') -home_path = os.path.abspath(__file__) -#recordings_path = home_path + '/audios/' -recordings_path ='audios/' -recording_file = recordings_path + now + '.wav' - -print(recording_file) - -cmd = "arecord -f cd -D hw:1,0 {}".format(recording_file) -cmd = shlex.split(cmd) - -# start recording -rec = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=False) - - -sleep(5) - - - -# stop recording -rec.kill() - -