You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
644 B
Python

#!/usr/bin/env python3
import os, subprocess, shlex
import glob
from random import choice
from time import sleep
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)