Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix difference in command request from Edge #324

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 2 additions & 17 deletions src/edge_tts/communicate.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,32 +319,19 @@ def __parse_metadata(self, data: bytes) -> TTSChunk:

async def __stream(self) -> AsyncGenerator[TTSChunk, None]:
async def send_command_request() -> None:
"""Sends the request to the service."""

# Prepare the request to be sent to the service.
#
# Note sentenceBoundaryEnabled and wordBoundaryEnabled are actually supposed
# to be booleans, but Edge Browser seems to send them as strings.
#
# This is a bug in Edge as Azure Cognitive Services actually sends them as
# bool and not string. For now I will send them as bool unless it causes
# any problems.
#
# Also pay close attention to double { } in request (escape for f-string).
"""Sends the command request to the service."""
await websocket.send_str(
f"X-Timestamp:{date_to_string()}\r\n"
"Content-Type:application/json; charset=utf-8\r\n"
"Path:speech.config\r\n\r\n"
'{"context":{"synthesis":{"audio":{"metadataoptions":{'
'"sentenceBoundaryEnabled":false,"wordBoundaryEnabled":true},'
'"sentenceBoundaryEnabled":"false","wordBoundaryEnabled":"true"},'
'"outputFormat":"audio-24khz-48kbitrate-mono-mp3"'
"}}}}\r\n"
)

async def send_ssml_request() -> None:
"""Sends the SSML request to the service."""

# Send the request to the service.
await websocket.send_str(
ssml_headers_plus_data(
connect_id(),
Expand Down Expand Up @@ -375,10 +362,8 @@ async def send_ssml_request() -> None:
headers=WSS_HEADERS,
ssl=ssl_ctx,
) as websocket:
# Send the request to the service.
await send_command_request()

# Send the SSML request to the service.
await send_ssml_request()

async for received in websocket:
Expand Down
Loading