I have a python server which is used to play a different audio file for each char that is taken in input from a client in javascript. I need to terminate the audio when the server receive the 'z' char but when an audio is playing the server does not receive any input from the client until the audio ends, then it lets me play another audio (something like the multiprocessing is not working at all).
import websockets
import asyncio
from audio.PlayAudio import PlaySound
import multiprocessing as mp
HOST = "192.168.43.149"
PORT = 8484
print("Server listening on Port " + str(PORT) + " ip: " + HOST)
async def socket(websocket):
print("A client just connected")
async for message in websocket:
print("Received message from client: " + message)
if message == 'a':
i="0"
p = mp.Process(target=PlaySound, args=i)
p.run()
elif message == 'b':
i="1"
p = mp.Process(target=PlaySound, args=i)
p.run()
elif message == 'c':
i="2"
p = mp.Process(target=PlaySound, args=i)
p.run()
elif message == 'd':
i="3"
p = mp.Process(target=PlaySound, args=i)
p.run()
elif message == 'e':
i="4"
p = mp.Process(target=PlaySound, args=i)
p.run()
elif message == 'f':
i="5"
p = mp.Process(target=PlaySound, args=i)
p.run()
elif message == 'g':
i="6"
p = mp.Process(target=PlaySound, args=i)
p.run()
elif message == 'h':
i="7"
p = mp.Process(target=PlaySound, args=i)
p.run()
elif message == 'i':
i="8"
p = mp.Process(target=PlaySound, args=i)
p.run()
elif message == 'j':
i="9"
p = mp.Process(target=PlaySound, args=i)
p.run()
elif message == 'k':
i="10"
p = mp.Process(target=PlaySound, args=i)
p.run()
elif message == 'l':
i="11"
p = mp.Process(target=PlaySound, args=i)
p.run()
elif message == 'm':
i="12"
p = mp.Process(target=PlaySound, args=i)
p.run()
elif message == 'n':
i="13"
p = mp.Process(target=PlaySound, args=i)
p.run()
elif message == 'o':
i="14"
p = mp.Process(target=PlaySound, args=i)
p.run()
elif message == 'p':
i="15"
p = mp.Process(target=PlaySound, args=i)
p.run()
elif message == 'q':
i="16"
p = mp.Process(target=PlaySound, args=i)
p.run()
elif message == 'r':
i="17"
p = mp.Process(target=PlaySound, args=i)
p.run()
elif message == 's':
i="18"
p = mp.Process(target=PlaySound, args=i)
p.run()
elif message == 't':
i="19"
p = mp.Process(target=PlaySound, args=i)
p.run()
elif message == 'u':
i="20"
p = mp.Process(target=PlaySound, args=i)
p.run()
elif message == 'v':
i="21"
p = mp.Process(target=PlaySound, args=i)
p.run()
elif message == 'w':
i="22"
p = mp.Process(target=PlaySound, args=i)
p.run()
elif message == 'x':
i="23"
p = mp.Process(target=PlaySound, args=i)
p.run()
elif message == 'y':
i="24"
p = mp.Process(target=PlaySound, args=i)
p.run()
elif message == 'z':
p.kill()
start_server = websockets.serve(socket, HOST, PORT)
asyncio.get_event_loop().run_until_complete(start_server)
asyncio.get_event_loop().run_forever()
How can i solve this problem? I have also tried to use playsound but it has the same problem.