When I initiate the beep test command, it does not play the audio and instead brings back the menu, then plays the timer that then prints the message, almost like multiprocessing.Process() got skipped. Did I forget to call a function?
I tried a range of things, up to having a separate .py file imported to replace multitasking(), but the logical error remained through every of my attempts. A note is that the .py file works on its own, maybe the ifs or third party functions could be messing with the code.
import os, playsound, multiprocessing, time
cwd= os.getcwd()
def beep_test():
audio= "".join((cwd+"\\BTsound.mp3"))
playsound.playsound(audio,True)
def multitasking():
sound_process = multiprocessing.Process(target=beep_test)
sound_process.start()
timer = 10
while timer > 0 and sound_process.is_alive():
time.sleep(1)
print(f"..{timer}")
timer -= 1
if timer == 0:
sound_process.terminate()
print("Time's up, runners must grab a water bottle and walk around. Do not sit down.")
comm_mode=input("""How would you like to input your commands?
1. Silent (Typed)
2. Prod (Speech Recognition)
""")
if __name__ == "__main__":
if "1" in comm_mode:
while True:
try:
message = input("Type 'ghost' to begin.\n")
except:
message = input("")
if "ghost" in message:
print("GHOST online")
message = input("What do you need?\n")
if "begin beep test" in message:
multitasking()
else:
print("Don't worry about it, error's on 1.")
The different function is this one:
import os, playsound, multiprocessing, time
cwd = os.getcwd()
def beep_test():
audio= "".join((cwd+"\\beep-test-audio.mp3"))
playsound.playsound(audio,True)
def thingy():
sound_process = multiprocessing.Process(target=beep_test)
sound_process.start()
timer = 10
while timer > 0 and sound_process.is_alive():
time.sleep(1)
print(f"..{timer}")
timer -= 1
if timer == 0:
sound_process.terminate()
print("Time's up, runners must grab a water bottle and walk around. Do not sit down.")
print(__name__)
if __name__ == "__main__":
thingy()