Python Audio WebSocket Client Not Receiving Data - Need Configuration Help

I’m trying to stream audio from OpenHAB to a Python client using the audio WebSocket feature. I can successfully establish a WebSocket connection, but I never receive any audio data when I send commands. Looking for help to understand the correct configuration and usage pattern.

My Configuration

  1. OpenHAB Items (audio.items)
// Several configurations attempted:
String PythonSpeaker "Python Speaker" 


  1. Python Test Code
import asyncio
import websockets
import json
import numpy as np
import sounddevice as sd

class OpenHABAudioClient:
    def __init__(self, host="192.168.1.100", port=8080, item_name="PythonSpeaker"):
        self.ws_url = f"ws://{host}:{port}/audio/{item_name}.stream"
        self.sample_rate = 16000
        
    async def connect_and_listen(self):
        print(f"Connecting to {self.ws_url}")
        
        async with websockets.connect(self.ws_url) as websocket:
            print("✅ WebSocket connected!")
            
            # Send a test command
            test_command = "say:Hello from OpenHAB"
            await websocket.send(test_command)
            print(f"Sent command: {test_command}")
            
            # Listen for data
            message_count = 0
            while message_count < 20:
                try:
                    # Wait for message with timeout
                    message = await asyncio.wait_for(websocket.recv(), timeout=2.0)
                    
                    if isinstance(message, bytes):
                        print(f"🎵 Received binary audio: {len(message)} bytes")
                        # Process audio data
                        audio_data = np.frombuffer(message, dtype=np.float32)
                        print(f"Audio samples: {len(audio_data)}")
                        
                        # Play audio
                        sd.play(audio_data, samplerate=self.sample_rate)
                        sd.wait()
                        
                    else:
                        print(f"📝 Received text: {message}")
                        
                    message_count += 1
                    
                except asyncio.TimeoutError:
                    print("⏱️ No data received...")
                    message_count += 1
                    
                except Exception as e:
                    print(f"❌ Error: {e}")
                    break
                    
            print("Test completed")

if __name__ == "__main__":
    client = OpenHABAudioClient()
    asyncio.run(client.connect_and_listen())
  1. OpenHAB Rules (test.rules)
rule "Trigger Python Audio"
when
    Item TestAudio changed
then
    // Attempted various command formats:
    PythonSpeaker.sendCommand("say:Testing 123")
    // PythonSpeaker.sendCommand("Hello world")
    
    // PythonSpeaker.sendCommand("tts:Hello from OpenHAB")
end

What I’ve Tried

Command Formats Attempted:

  1. Plain text: PythonSpeaker.sendCommand(“Hello world”)
  2. Say command: PythonSpeaker.sendCommand(“say:Hello world”)
  3. TTS command: PythonSpeaker.sendCommand(“tts:Hello world”)
  4. Play URL: PythonSpeaker.sendCommand(“play:https://example.com/audio.mp3”)

Connection Attempts:

  1. Direct WebSocket: Connection successful
  2. With authentication: Added Basic Auth headers (no difference)
  3. Different audio formats: Tried FLOAT32LE, S16LE, S24LE

Observed Behavior

  1. :white_check_mark: WebSocket Connection: Successfully connects to ws://192.168.1.100:8080/audio/PythonSpeaker.stream
  2. :white_check_mark: Command Accepted: OpenHAB logs show commands are received:
    2026-01-13 03:35:22.456 [INFO ] [openhab.event.ItemCommandEvent] - Item 'PythonSpeaker' received command say:Hello world
    
  3. :cross_mark: No Audio Data: WebSocket never sends binary audio data
  4. :cross_mark: No Errors: No error messages in OpenHAB logs
  5. :cross_mark: Silent Connection: WebSocket stays open but no data transmission

Python Output:

Connecting to ws://192.168.1.100:8080/audio/PythonSpeaker.stream
✅ WebSocket connected!
Sent command: say:Hello from OpenHAB
⏱️ No data received...
⏱️ No data received...
... (continues with no audio data)

Questions

  1. Is the audio WebSocket feature enabled by default? Do I need to install additional components?
  2. What’s the correct item configuration? Should I be using Things or just Items?
  3. How do I trigger audio streaming?
    · Should audio automatically stream when a client connects?
    · Do I need to send a specific command format?
    · Is there a REST API endpoint to trigger audio?
  4. Text-to-Speech Requirements:
    · Do I need a TTS service configured?
    · Which TTS engines work with the audio binding?
    · Any additional configuration needed?
  5. Audio Format:
    · What’s the default audio format (sample rate, channels, encoding)?
    · Can I specify the format in the WebSocket URL?
    · Should I expect binary PCM or encoded audio?
  6. Debugging:
    · How can I verify the audio binding is working?
    · Any specific logs to enable?
    · How to test without writing a full client?

What I Need

  1. A working example of:
    · Correct OpenHAB item/thing configuration
    · Python/ESP32 code that successfully receives audio
    · Command format to trigger audio playback
  2. Understanding of:
    · The complete data flow from command to WebSocket
    · Required dependencies/services
    · Common pitfalls and solutions

Additional Info

· I have the transform and voice addons installed
· HTTP/WebSocket ports are open and accessible
· Other bindings (HTTP, MQTT) work correctly
· I can play audio through the OpenHAB UI speakers successfully

Any help would be greatly appreciated! I’ve been stuck on this for a while and the documentation is sparse on this specific feature.