From 3f2b635ff63932f774169bbf04fa4f188ffe27bb Mon Sep 17 00:00:00 2001 From: Rany Date: Fri, 22 Nov 2024 20:07:15 +0200 Subject: [PATCH] Use tabulate to pretty print voices (#321) Signed-off-by: rany --- setup.cfg | 1 + setup.py | 1 + src/edge_tts/util.py | 29 +++++++++++++---------------- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/setup.cfg b/setup.cfg index 6c939a4..19a6974 100644 --- a/setup.cfg +++ b/setup.cfg @@ -35,3 +35,4 @@ dev = isort mypy pylint + types-tabulate \ No newline at end of file diff --git a/setup.py b/setup.py index d2d5cd6..5d06540 100644 --- a/setup.py +++ b/setup.py @@ -6,6 +6,7 @@ setup( install_requires=[ "aiohttp>=3.8.0", "certifi>=2023.11.17", + "tabulate>=0.4.4", "typing-extensions>=4.1.0", ], ) diff --git a/src/edge_tts/util.py b/src/edge_tts/util.py index 2d42ebd..64f0601 100644 --- a/src/edge_tts/util.py +++ b/src/edge_tts/util.py @@ -6,6 +6,8 @@ import sys from io import TextIOWrapper from typing import Any, TextIO, Union +from tabulate import tabulate + from . import Communicate, SubMaker, list_voices @@ -13,22 +15,17 @@ 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: