Skip to content

Commit 3f2b635

Browse files
authored
Use tabulate to pretty print voices (#321)
Signed-off-by: rany <[email protected]>
1 parent 3e4de19 commit 3f2b635

File tree

3 files changed

+15
-16
lines changed

3 files changed

+15
-16
lines changed

setup.cfg

+1
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@ dev =
3535
isort
3636
mypy
3737
pylint
38+
types-tabulate

setup.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
install_requires=[
77
"aiohttp>=3.8.0",
88
"certifi>=2023.11.17",
9+
"tabulate>=0.4.4",
910
"typing-extensions>=4.1.0",
1011
],
1112
)

src/edge_tts/util.py

+13-16
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,26 @@
66
from io import TextIOWrapper
77
from typing import Any, TextIO, Union
88

9+
from tabulate import tabulate
10+
911
from . import Communicate, SubMaker, list_voices
1012

1113

1214
async def _print_voices(*, proxy: str) -> None:
1315
"""Print all available voices."""
1416
voices = await list_voices(proxy=proxy)
1517
voices = sorted(voices, key=lambda voice: voice["ShortName"])
16-
for idx, voice in enumerate(voices):
17-
if idx != 0:
18-
print()
19-
20-
for key in voice.keys():
21-
if key in (
22-
"SuggestedCodec",
23-
"FriendlyName",
24-
"Status",
25-
"VoiceTag",
26-
"Name",
27-
"Locale",
28-
):
29-
continue
30-
pretty_key_name = key if key != "ShortName" else "Name"
31-
print(f"{pretty_key_name}: {voice[key]}")
18+
headers = ["Name", "Gender", "ContentCategories", "VoicePersonalities"]
19+
table = [
20+
[
21+
voice["ShortName"],
22+
voice["Gender"],
23+
", ".join(voice["VoiceTag"]["ContentCategories"]),
24+
", ".join(voice["VoiceTag"]["VoicePersonalities"]),
25+
]
26+
for voice in voices
27+
]
28+
print(tabulate(table, headers))
3229

3330

3431
async def _run_tts(args: Any) -> None:

0 commit comments

Comments
 (0)