Improve type support a bit more (#333)
Also fix default voice for util.py Signed-off-by: rany <rany2@riseup.net>
This commit is contained in:
@@ -3,14 +3,16 @@
|
||||
import argparse
|
||||
import asyncio
|
||||
import sys
|
||||
from typing import Any, Optional, TextIO
|
||||
from typing import Optional, TextIO
|
||||
|
||||
from tabulate import tabulate
|
||||
|
||||
from . import Communicate, SubMaker, list_voices
|
||||
from .constants import DEFAULT_VOICE
|
||||
from .data_classes import UtilArgs
|
||||
|
||||
|
||||
async def _print_voices(*, proxy: str) -> None:
|
||||
async def _print_voices(*, proxy: Optional[str]) -> None:
|
||||
"""Print all available voices."""
|
||||
voices = await list_voices(proxy=proxy)
|
||||
voices = sorted(voices, key=lambda voice: voice["ShortName"])
|
||||
@@ -27,7 +29,7 @@ async def _print_voices(*, proxy: str) -> None:
|
||||
print(tabulate(table, headers))
|
||||
|
||||
|
||||
async def _run_tts(args: Any) -> None:
|
||||
async def _run_tts(args: UtilArgs) -> None:
|
||||
"""Run TTS after parsing arguments from command line."""
|
||||
|
||||
try:
|
||||
@@ -84,15 +86,17 @@ async def _run_tts(args: Any) -> None:
|
||||
|
||||
async def amain() -> None:
|
||||
"""Async main function"""
|
||||
parser = argparse.ArgumentParser(description="Microsoft Edge TTS")
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Text-to-speech using Microsoft Edge's online TTS service."
|
||||
)
|
||||
group = parser.add_mutually_exclusive_group(required=True)
|
||||
group.add_argument("-t", "--text", help="what TTS will say")
|
||||
group.add_argument("-f", "--file", help="same as --text but read from file")
|
||||
parser.add_argument(
|
||||
"-v",
|
||||
"--voice",
|
||||
help="voice for TTS. Default: en-US-AriaNeural",
|
||||
default="en-US-AriaNeural",
|
||||
help=f"voice for TTS. Default: {DEFAULT_VOICE}",
|
||||
default=DEFAULT_VOICE,
|
||||
)
|
||||
group.add_argument(
|
||||
"-l",
|
||||
@@ -111,7 +115,7 @@ async def amain() -> None:
|
||||
help="send subtitle output to provided file instead of stderr",
|
||||
)
|
||||
parser.add_argument("--proxy", help="use a proxy for TTS and voice list.")
|
||||
args = parser.parse_args()
|
||||
args = parser.parse_args(namespace=UtilArgs())
|
||||
|
||||
if args.list_voices:
|
||||
await _print_voices(proxy=args.proxy)
|
||||
|
||||
Reference in New Issue
Block a user