AudioSocket error — “Received AudioSocket message other than hangup or audio”

Hi everyone,

I’m working with Asterisk and the AudioSocket application to stream call audio to a Python server for processing (e.g., transcription).
However, during a live call, I’m seeing this error in the Asterisk logs:

[Oct 28 11:24:16] ERROR[136104][C-00000003]: res_audiosocket.c:295 ast_audiosocket_receive_frame_with_hangup: 
Received AudioSocket message other than hangup or audio, refer to protocol specification for valid message types
[Oct 28 11:24:16] WARNING[136104][C-00000003]: app_audiosocket.c:206 audiosocket_run: 
Failed to receive frame from AudioSocket server '127.0.0.1:4000' connected to channel 'PJSIP/tata-endpoint-00000002'

From what I understand, this means Asterisk received a message from my AudioSocket server that doesn’t match the expected binary audio format or hangup frame.

I’d appreciate help understanding:

  1. What exact message format Asterisk expects from the AudioSocket server (e.g., byte framing, headers, etc.).

  2. Whether I need to send any response back to Asterisk after receiving the audio frames.

  3. Any example implementation or reference Python code for a proper AudioSocket receiver that keeps the connection alive for the entire call.

Here’s how I’m starting the socket server (simplified):

server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind(('127.0.0.1', 4000))
server.listen(1)
conn, addr = server.accept()
data = conn.recv(1024)
# process data...

What could be causing this protocol error, and what’s the correct way to handle or ignore messages so Asterisk doesn’t drop the stream?

Thanks in advance!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.