Skip to content

Commit

Permalink
Use tabulate to pretty print voices (rany2#321)
Browse files Browse the repository at this point in the history
Signed-off-by: rany <[email protected]>
  • Loading branch information
rany2 authored Nov 22, 2024
1 parent 3e4de19 commit 3f2b635
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ dev =
isort
mypy
pylint
types-tabulate
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
install_requires=[
"aiohttp>=3.8.0",
"certifi>=2023.11.17",
"tabulate>=0.4.4",
"typing-extensions>=4.1.0",
],
)
29 changes: 13 additions & 16 deletions src/edge_tts/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,26 @@
from io import TextIOWrapper
from typing import Any, TextIO, Union

from tabulate import tabulate

from . import Communicate, SubMaker, list_voices


async def _print_voices(*, proxy: str) -> None:
"""Print all available voices."""
voices = await list_voices(proxy=proxy)
voices = sorted(voices, key=lambda voice: voice["ShortName"])
for idx, voice in enumerate(voices):
if idx != 0:
print()

for key in voice.keys():
if key in (
"SuggestedCodec",
"FriendlyName",
"Status",
"VoiceTag",
"Name",
"Locale",
):
continue
pretty_key_name = key if key != "ShortName" else "Name"
print(f"{pretty_key_name}: {voice[key]}")
headers = ["Name", "Gender", "ContentCategories", "VoicePersonalities"]
table = [
[
voice["ShortName"],
voice["Gender"],
", ".join(voice["VoiceTag"]["ContentCategories"]),
", ".join(voice["VoiceTag"]["VoicePersonalities"]),
]
for voice in voices
]
print(tabulate(table, headers))


async def _run_tts(args: Any) -> None:
Expand Down

0 comments on commit 3f2b635

Please sign in to comment.