import paho.mqtt.client as mqtt

# MQTT Broker信息
broker = '127.0.0.1'
port = 1883
topic = 'audio/test'

# 音频文件路径
audio_file_path = 'tmp2.wav'

def publish_audio():
    client = mqtt.Client()
    client.connect(broker, port)

    with open(audio_file_path, 'rb') as audio_file:
        audio_data = audio_file.read()

    client.publish(topic, audio_data)
    client.disconnect()

if __name__ == "__main__":
    publish_audio()
    print("Audio published successfully.")
