play_audio function crash python chat

18 Views Asked by At

Hi so I have a problem with a function in my python code

play_audio loads in the receive message function (notifcation) when I receive a message a crash occurs (no traceback)

The audio file is in the same directory and I suspect that

play_obj.wait_done()

Stops the thread

import socket
import threading
import simpleaudio as sa

def play_audio(file_path):
    wave_obj = sa.WaveObject.from_wave_file(file_path)
    play_obj = wave_obj.play()
    play_obj.wait_done()  


def receive_messages():
    while True:
        data = client_socket.recv(1024)
        if not data:
            print("Disconnected from server.")
            break
        print("Message received from server:", data.decode())
        play_audio('darks-uwu-made-with-Voicemod.wav') 

def send_message():
    while True:
        message = input("Enter your message: ")
        client_socket.sendall(message.encode())

client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_ip = 'xoxo25012008-61686.portmap.host'  # Remplacez par l'IP du serveur central
server_port = 61686  # Port sur lequel le serveur central écoute
client_socket.connect((server_ip, server_port))

receive_thread = threading.Thread(target=receive_messages)
send_thread = threading.Thread(target=send_message)

receive_thread.start()
send_thread.start() 


So first I tried to delete the play_audio function and its work but I wanted to keep it, then I deleted play_obj.wait_done()

And it crashes too

Thanks for any help

0

There are 0 best solutions below