updated scripts

master
Angeliki 5 years ago
parent ffb85f96f3
commit 450b1bc8bc

Binary file not shown.

@ -1,8 +0,0 @@
from pynput.keyboard import Key, Controller
keyboard = Controller()
while True:
if keyboard.press('space'):
print ('You Pressed A Key!')

@ -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)

@ -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)

@ -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)

@ -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()
Loading…
Cancel
Save