Refactor header length retrieval to utilize more appropriate method
This commit is contained in:
@@ -5,6 +5,7 @@ Communicate package.
|
|||||||
|
|
||||||
import json
|
import json
|
||||||
import re
|
import re
|
||||||
|
import struct
|
||||||
import time
|
import time
|
||||||
import uuid
|
import uuid
|
||||||
from contextlib import nullcontext
|
from contextlib import nullcontext
|
||||||
@@ -414,12 +415,13 @@ class Communicate:
|
|||||||
"We received a binary message, but we are not expecting one."
|
"We received a binary message, but we are not expecting one."
|
||||||
)
|
)
|
||||||
|
|
||||||
yield {
|
# See: https://github.com/microsoft/cognitive-services-speech-sdk-js/blob/d071d11d1e9f34d6f79d0ab6114c90eecb02ba1f/src/common.speech/WebsocketMessageFormatter.ts#L46
|
||||||
"type": "audio",
|
header_length = struct.unpack(">H", received.data[:2])[0]
|
||||||
"data": received.data[
|
if len(received.data) > header_length + 2:
|
||||||
received.data.find(b"Path:audio\r\n") + 12 :
|
yield {
|
||||||
],
|
"type": "audio",
|
||||||
}
|
"data": received.data[header_length + 2 :],
|
||||||
|
}
|
||||||
audio_was_received = True
|
audio_was_received = True
|
||||||
elif received.type == aiohttp.WSMsgType.ERROR:
|
elif received.type == aiohttp.WSMsgType.ERROR:
|
||||||
raise WebSocketError(
|
raise WebSocketError(
|
||||||
|
|||||||
Reference in New Issue
Block a user