From 4152fb6a21de4549f39245f2ee55737bd2fae741 Mon Sep 17 00:00:00 2001 From: Russell Schmidt Date: Thu, 12 Jun 2025 17:29:30 -0500 Subject: [PATCH] Redirect sound player output to dev null On my linux system, the sound playing code goes to aplay. When called, aplay outputs a message about the file it is playing to stderr, which causes it to be printed on the input line, which can't be easily cleared. Redirect output from the audio player executable to dev/null. Deduplicate sound playing code a bit so we only need one call to subprocess.run, so I don't have to make this change in three places. --- contact/message_handlers/rx_handler.py | 32 ++++++++++++++------------ 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/contact/message_handlers/rx_handler.py b/contact/message_handlers/rx_handler.py index fa4d166..32bafe2 100644 --- a/contact/message_handlers/rx_handler.py +++ b/contact/message_handlers/rx_handler.py @@ -29,34 +29,36 @@ from contact.utilities.singleton import ui_state, interface_state, app_state def play_sound(): try: system = platform.system() + sound_path = "" + executable = "" - if system == "Darwin": # macOS + if system == "Darwin": #macOS sound_path = "/System/Library/Sounds/Ping.aiff" - if os.path.exists(sound_path): - subprocess.run(["afplay", sound_path], check=True) - return - else: - logging.warning(f"macOS sound file not found: {sound_path}") - + executable = "afplay" elif system == "Linux": sound_path = "/usr/share/sounds/freedesktop/stereo/complete.oga" + if(shutil.which("paplay")): + executable = "paplay" + else: + executable = "aplay" + + if executable != "" and sound_path != "": if os.path.exists(sound_path): - if shutil.which("paplay"): - subprocess.run(["paplay", sound_path], check=True) - return - elif shutil.which("aplay"): - subprocess.run(["aplay", sound_path], check=True) + if shutil.which(executable): + subprocess.run([executable, sound_path], check=True, + stdout=subprocess.DEVNULL, stderr = subprocess.DEVNULL) return else: - logging.warning("No sound player found (paplay/aplay)") + logging.warning("No sound player found (afplay/paplay/aplay)") else: - logging.warning(f"Linux sound file not found: {sound_path}") - + logging.warning(f"Sound file not found: {sound_path}") except subprocess.CalledProcessError as e: logging.error(f"Sound playback failed: {e}") except Exception as e: logging.error(f"Unexpected error: {e}") + + # Final fallback: terminal beep print("\a")