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