Fix 403 error for list voices endpoint (#272)

Fixes #271

Signed-off-by: rany <rany2@riseup.net>
This commit is contained in:
Rany
2024-10-19 10:05:08 +03:00
committed by GitHub
parent bd82487a8e
commit 80fc1d0a61
3 changed files with 30 additions and 24 deletions

View File

@@ -27,7 +27,7 @@ from xml.sax.saxutils import escape
import aiohttp
import certifi
from .constants import WSS_URL
from .constants import WSS_HEADERS, WSS_URL
from .exceptions import (
NoAudioReceived,
UnexpectedResponse,
@@ -369,15 +369,7 @@ class Communicate:
f"{WSS_URL}&ConnectionId={connect_id()}",
compress=15,
proxy=self.proxy,
headers={
"Pragma": "no-cache",
"Cache-Control": "no-cache",
"Origin": "chrome-extension://jdiccldimpdaibmpdkjnbmckianbfold",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "en-US,en;q=0.9",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
" (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36 Edg/129.0.0.0",
},
headers=WSS_HEADERS,
ssl=ssl_ctx,
) as websocket:
# Send the request to the service.

View File

@@ -7,3 +7,29 @@ TRUSTED_CLIENT_TOKEN = "6A5AA1D4EAFF4E9FB37E23D68491D6F4"
WSS_URL = f"wss://{BASE_URL}/edge/v1?TrustedClientToken={TRUSTED_CLIENT_TOKEN}"
VOICE_LIST = f"https://{BASE_URL}/voices/list?trustedclienttoken={TRUSTED_CLIENT_TOKEN}"
CHROMIUM_MAJOR_VERSION = "129"
BASE_HEADERS = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
f" (KHTML, like Gecko) Chrome/${CHROMIUM_MAJOR_VERSION}.0.0.0 Safari/537.36"
f" Edg/${CHROMIUM_MAJOR_VERSION}.0.0.0",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "en-US,en;q=0.9",
}
WSS_HEADERS = {
"Pragma": "no-cache",
"Cache-Control": "no-cache",
"Origin": "chrome-extension://jdiccldimpdaibmpdkjnbmckianbfold",
}
WSS_HEADERS.update(BASE_HEADERS)
VOICE_HEADERS = {
"Authority": "speech.platform.bing.com",
"Sec-CH-UA": f'" Not;A Brand";v="99", "Microsoft Edge";v="{CHROMIUM_MAJOR_VERSION}",'
f' "Chromium";v="{CHROMIUM_MAJOR_VERSION}"',
"Sec-CH-UA-Mobile": "?0",
"Accept": "*/*",
"Sec-Fetch-Site": "none",
"Sec-Fetch-Mode": "cors",
"Sec-Fetch-Dest": "empty",
}
VOICE_HEADERS.update(BASE_HEADERS)

View File

@@ -9,7 +9,7 @@ from typing import Any, Dict, List, Optional
import aiohttp
import certifi
from .constants import VOICE_LIST
from .constants import VOICE_HEADERS, VOICE_LIST
async def list_voices(*, proxy: Optional[str] = None) -> Any:
@@ -26,19 +26,7 @@ async def list_voices(*, proxy: Optional[str] = None) -> Any:
async with aiohttp.ClientSession(trust_env=True) as session:
async with session.get(
VOICE_LIST,
headers={
"Authority": "speech.platform.bing.com",
"Sec-CH-UA": '" Not;A Brand";v="99", "Microsoft Edge";v="91", "Chromium";v="91"',
"Sec-CH-UA-Mobile": "?0",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 "
"(KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36 Edg/91.0.864.41",
"Accept": "*/*",
"Sec-Fetch-Site": "none",
"Sec-Fetch-Mode": "cors",
"Sec-Fetch-Dest": "empty",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "en-US,en;q=0.9",
},
headers=VOICE_HEADERS,
proxy=proxy,
ssl=ssl_ctx,
) as url: