Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- You might need to install aplay to get this to work, not sure what you're using to play WAV files. Use:
- sudo apt install alsa-utils
- to install aplay.
- The first script is what you'll run with the Mystic menu command GY, make sure the second script is in the same directory as the first script, usually /mystic/themes/default/scripts
- ############## login_wav.mpy ##############
- import mystic_bbs as bbs
- import subprocess
- import os
- # Path to this MPY script
- path = bbs.param_str(0)
- dir_path = os.path.dirname(path)
- # Worker script and WAV file
- player_script = os.path.join(dir_path, "play_wav.py")
- wav_file = "/mystic/56k_mdm.wav"
- # Suppress output so nothing leaks into the BBS session
- devnull = open(os.devnull, "w")
- # Launch the worker and immediately return control to Mystic
- subprocess.Popen(
- ["python", player_script, wav_file],
- stdout=devnull,
- stderr=devnull,
- close_fds=True
- )
- ############## play_wav.py ##############
- import sys
- import subprocess
- import os
- def play_wav(wav_file):
- if not os.path.exists(wav_file):
- return
- # aplay blocks, but that's fine because this script is detached from Mystic
- subprocess.call(["aplay", wav_file])
- if len(sys.argv) > 1:
- play_wav(sys.argv[1])
Advertisement
Add Comment
Please, Sign In to add comment