Skip to content

Commit

Permalink
Fix "unable to get local issuer certificate" when trust store is not …
Browse files Browse the repository at this point in the history
…available from OS

Closes #129

Signed-off-by: rany2 <[email protected]>
  • Loading branch information
rany2 committed Aug 12, 2023
1 parent 453a096 commit 8f8a334
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
name="edge-tts",
install_requires=[
"aiohttp>=3.8.0",
"certifi==2023.07.22",
],
)
6 changes: 5 additions & 1 deletion src/edge_tts/communicate.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import json
import re
import ssl
import time
import uuid
from contextlib import nullcontext
Expand All @@ -23,6 +24,7 @@
from xml.sax.saxutils import escape

import aiohttp
import certifi

from edge_tts.exceptions import (
NoAudioReceived,
Expand Down Expand Up @@ -302,9 +304,10 @@ async def stream(self) -> AsyncGenerator[Dict[str, Any], None]:
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,
Expand All @@ -320,6 +323,7 @@ async def stream(self) -> AsyncGenerator[Dict[str, Any], None]:
"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
Expand Down
4 changes: 4 additions & 0 deletions src/edge_tts/list_voices.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
"""

import json
import ssl
from typing import Any, Dict, List, Optional

import aiohttp
import certifi

from .constants import VOICE_LIST

Expand All @@ -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,
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/edge_tts/version.py
Original file line number Diff line number Diff line change
@@ -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("."))

0 comments on commit 8f8a334

Please sign in to comment.