Files
edge-tts/src/edge_tts/list_voices.py
2021-12-07 22:09:43 +02:00

42 lines
1.3 KiB
Python

"""
list_voices package.
"""
import json
import aiohttp
from .constants import VOICE_LIST
async def list_voices():
"""
List all available voices and their attributes.
This pulls data from the URL used by Microsoft Edge to return a list of
all available voices. However many more experimental voices are available
than are listed here. (See https://aka.ms/csspeech/voicenames)
Returns:
dict: A dictionary of voice attributes.
"""
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",
},
) as url:
data = json.loads(await url.text())
return data