Fix "unable to get local issuer certificate" when trust store is not available from OS

Closes #129

Signed-off-by: rany2 <rany2@riseup.net>
This commit is contained in:
rany2 2023-08-12 17:25:46 +03:00
parent 453a096c54
commit 8f8a334203
No known key found for this signature in database
4 changed files with 11 additions and 2 deletions

View File

@ -5,5 +5,6 @@ setup(
name="edge-tts",
install_requires=[
"aiohttp>=3.8.0",
"certifi==2023.07.22",
],
)

View File

@ -5,6 +5,7 @@ Communicate package.
import json
import re
import ssl
import time
import uuid
from contextlib import nullcontext
@ -23,6 +24,7 @@ from typing import (
from xml.sax.saxutils import escape
import aiohttp
import certifi
from edge_tts.exceptions import (
NoAudioReceived,
@ -302,9 +304,10 @@ class Communicate:
prev_idx = -1
shift_time = -1
ssl_ctx = ssl.create_default_context(cafile=certifi.where())
for idx, text in enumerate(texts):
async with aiohttp.ClientSession(
trust_env=True
trust_env=True,
) as session, session.ws_connect(
f"{WSS_URL}&ConnectionId={connect_id()}",
compress=15,
@ -320,6 +323,7 @@ class Communicate:
"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",
},
ssl=ssl_ctx,
) as websocket:
# download indicates whether we should be expecting audio data,
# this is so what we avoid getting binary data from the websocket

View File

@ -3,9 +3,11 @@ list_voices package for edge_tts.
"""
import json
import ssl
from typing import Any, Dict, List, Optional
import aiohttp
import certifi
from .constants import VOICE_LIST
@ -20,6 +22,7 @@ async def list_voices(*, proxy: Optional[str] = None) -> Any:
Returns:
dict: A dictionary of voice attributes.
"""
ssl_ctx = ssl.create_default_context(cafile=certifi.where())
async with aiohttp.ClientSession(trust_env=True) as session:
async with session.get(
VOICE_LIST,
@ -37,6 +40,7 @@ async def list_voices(*, proxy: Optional[str] = None) -> Any:
"Accept-Language": "en-US,en;q=0.9",
},
proxy=proxy,
ssl=ssl_ctx,
) as url:
data = json.loads(await url.text())
return data

View File

@ -1,4 +1,4 @@
"""Edge TTS version information."""
__version__ = "6.1.7"
__version__ = "6.1.8"
__version_info__ = tuple(int(num) for num in __version__.split("."))