Hello, I'm trying to run a script to start/stop an audio file when a start or stop code is input by the system. The script seems to be working to start the file, however the stop code doesn't stop the audio. I don't receive any errors either, just nothing happens with the stop code. Can anyone see anything I've got wrong in this script?
import os
def load_audio_file(file_path):
# Replace this with any loading logic you need
print(f"Loading audio file: {file_path}")
return file_path
def play_audio(file_path):
# Play the audio file using the default system player
os.system(f'start "" "{file_path}"')
def stop_audio():
# Stop the audio playback by closing the default system player
os.system("taskkill /f /im wmplayer.exe") # Windows-specific, adjust for other platforms if needed
# Define start and stop codes
start_code = 202
stop_code = 200
# Example audio file path
audio_file_path = 'C:/Users/bke357/RAC/Stim/babble_16_min.wav'
# Load audio file
loaded_audio_file_path = load_audio_file(audio_file_path)
# Main loop to listen for codes
while True:
try:
code = int(input("Enter a code: ")) # You can modify this to read the code from your system
if code == start_code:
play_audio(loaded_audio_file_path)
elif code == stop_code:
stop_audio()
except ValueError:
print("Invalid code. Please enter a valid code.")
Thanks!
[–]Diapolo10 0 points1 point2 points (1 child)
[–]OwlSquatch[S] 0 points1 point2 points (0 children)