Switch to httpx for http2 support
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
[metadata]
|
[metadata]
|
||||||
name = edge-tts
|
name = edge-tts
|
||||||
version = 1.0.1
|
version = 1.0.2
|
||||||
author = rany
|
author = rany
|
||||||
author_email = ranygh@riseup.net
|
author_email = ranygh@riseup.net
|
||||||
description = Microsoft Edge's TTS
|
description = Microsoft Edge's TTS
|
||||||
@@ -22,6 +22,8 @@ scripts = bin/edge-playback
|
|||||||
python_requires = >=3.7
|
python_requires = >=3.7
|
||||||
install_requires =
|
install_requires =
|
||||||
websockets>=9.1
|
websockets>=9.1
|
||||||
|
httpx>=0.18.1
|
||||||
|
h2>=4.0.0
|
||||||
|
|
||||||
[options.packages.find]
|
[options.packages.find]
|
||||||
where=src
|
where=src
|
||||||
|
|||||||
@@ -4,12 +4,12 @@ import json
|
|||||||
import uuid
|
import uuid
|
||||||
import signal
|
import signal
|
||||||
import argparse
|
import argparse
|
||||||
import urllib.request
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import ssl
|
import ssl
|
||||||
import websockets
|
import websockets
|
||||||
import unicodedata
|
import unicodedata
|
||||||
import logging
|
import logging
|
||||||
|
import httpx
|
||||||
from email.utils import formatdate
|
from email.utils import formatdate
|
||||||
from xml.sax.saxutils import escape
|
from xml.sax.saxutils import escape
|
||||||
|
|
||||||
@@ -32,20 +32,21 @@ def removeIncompatibleControlChars(s):
|
|||||||
return "".join(output)
|
return "".join(output)
|
||||||
|
|
||||||
def list_voices():
|
def list_voices():
|
||||||
req = urllib.request.Request(voiceList)
|
with httpx.Client(http2=True, headers={
|
||||||
req.add_header('Authority', 'speech.platform.bing.com')
|
'Authority': 'speech.platform.bing.com',
|
||||||
req.add_header('Host', 'speech.platform.bing.com')
|
'Host': 'speech.platform.bing.com',
|
||||||
req.add_header('Sec-CH-UA', "\" Not;A Brand\";v=\"99\", \"Microsoft Edge\";v=\"91\", \"Chromium\";v=\"91\"")
|
'Sec-CH-UA': "\" Not;A Brand\";v=\"99\", \"Microsoft Edge\";v=\"91\", \"Chromium\";v=\"91\"",
|
||||||
req.add_header('Sec-CH-UA-Mobile', '?0')
|
'Sec-CH-UA-Mobile': '?0',
|
||||||
req.add_header('User-Agent', 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36 Edg/91.0.864.41')
|
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36 Edg/91.0.864.41',
|
||||||
req.add_header('Accept', '*/*')
|
'Accept': '*/*',
|
||||||
req.add_header('Sec-Fetch-Site', 'none')
|
'Sec-Fetch-Site': 'none',
|
||||||
req.add_header('Sec-Fetch-Mode', 'cors')
|
'Sec-Fetch-Mode': 'cors',
|
||||||
req.add_header('Sec-Fetch-Dest', 'empty')
|
'Sec-Fetch-Dest': 'empty',
|
||||||
req.add_header('Accept-Language', 'en-US,en;q=0.9')
|
'Accept-Language': 'en-US,en;q=0.9'
|
||||||
logging.debug("Loading json from %s" % voiceList)
|
}) as url:
|
||||||
data = json.loads(urllib.request.urlopen(req).read())
|
logging.debug("Loading json from %s" % voiceList)
|
||||||
logging.debug("JSON Loaded")
|
data = json.loads(url.get(voiceList).content)
|
||||||
|
logging.debug("JSON Loaded")
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def mkssmlmsg(text="", voice="en-US-AriaNeural", pitchString="+0Hz", rateString="+0%", volumeString="+0%", customspeak=False):
|
def mkssmlmsg(text="", voice="en-US-AriaNeural", pitchString="+0Hz", rateString="+0%", volumeString="+0%", customspeak=False):
|
||||||
|
|||||||
Reference in New Issue
Block a user