Skip to content

Commit 8da9145

Browse files
committed
Resolve NoAudioReceived issue
Fixes: #416 Fixes: #421 Fixes: #436 Fixes: #437 Fixes: #440 Fixes: #442 Fixes: #443 Fixes: #444 Signed-off-by: rany <rany2@riseup.net>
1 parent ea8740c commit 8da9145

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

src/edge_tts/communicate.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@ def __parse_metadata(self, data: bytes) -> TTSChunk:
392392
raise UnexpectedResponse("No WordBoundary metadata found")
393393

394394
async def __stream(self) -> AsyncGenerator[TTSChunk, None]:
395+
# TODO: support webm-24khz-16bit-mono-opus properly. Used by macOS.
395396
async def send_command_request() -> None:
396397
"""Sends the command request to the service."""
397398
word_boundary = self.tts_config.boundary == "WordBoundary"
@@ -506,9 +507,13 @@ async def send_ssml_request() -> None:
506507

507508
# At termination of the stream, the service sends a binary message
508509
# with no Content-Type; this is expected. What is not expected is for
509-
# an MPEG audio stream to be sent with no data.
510+
# an audio stream to be sent with no data.
510511
content_type = parameters.get(b"Content-Type", None)
511-
if content_type not in [b"audio/mpeg", None]:
512+
if content_type not in (
513+
b"audio/mpeg",
514+
b"audio/webm; codec=opus",
515+
None,
516+
):
512517
raise UnexpectedResponse(
513518
"Received binary message, but with an unexpected Content-Type."
514519
)

src/edge_tts/constants.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,27 @@
11
"""Constants for the edge_tts package."""
22

3-
BASE_URL = "api.msedgeservices.com/tts/cognitiveservices"
3+
BASE_URL = "speech.platform.bing.com/consumer/speech/synthesize/readaloud"
44
TRUSTED_CLIENT_TOKEN = "6A5AA1D4EAFF4E9FB37E23D68491D6F4"
55

6-
WSS_URL = (
7-
f"wss://{BASE_URL}/websocket/v1?Ocp-Apim-Subscription-Key={TRUSTED_CLIENT_TOKEN}"
8-
)
9-
VOICE_LIST = (
10-
f"https://{BASE_URL}/voices/list?Ocp-Apim-Subscription-Key={TRUSTED_CLIENT_TOKEN}"
11-
)
6+
WSS_URL = f"wss://{BASE_URL}/edge/v1?TrustedClientToken={TRUSTED_CLIENT_TOKEN}"
7+
VOICE_LIST = f"https://{BASE_URL}/voices/list?trustedclienttoken={TRUSTED_CLIENT_TOKEN}"
128

139
DEFAULT_VOICE = "en-US-EmmaMultilingualNeural"
1410

15-
CHROMIUM_FULL_VERSION = "140.0.3485.14"
11+
CHROMIUM_FULL_VERSION = "143.0.3650.75"
1612
CHROMIUM_MAJOR_VERSION = CHROMIUM_FULL_VERSION.split(".", maxsplit=1)[0]
1713
SEC_MS_GEC_VERSION = f"1-{CHROMIUM_FULL_VERSION}"
1814
BASE_HEADERS = {
1915
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
2016
f" (KHTML, like Gecko) Chrome/{CHROMIUM_MAJOR_VERSION}.0.0.0 Safari/537.36"
2117
f" Edg/{CHROMIUM_MAJOR_VERSION}.0.0.0",
22-
"Accept-Encoding": "gzip, deflate, br",
18+
"Accept-Encoding": "gzip, deflate, br, zstd",
2319
"Accept-Language": "en-US,en;q=0.9",
2420
}
2521
WSS_HEADERS = {
2622
"Pragma": "no-cache",
2723
"Cache-Control": "no-cache",
2824
"Origin": "chrome-extension://jdiccldimpdaibmpdkjnbmckianbfold",
29-
"Sec-WebSocket-Protocol": "synthesize",
3025
"Sec-WebSocket-Version": "13",
3126
}
3227
WSS_HEADERS.update(BASE_HEADERS)

0 commit comments

Comments
 (0)