more typing

This commit is contained in:
rany2
2023-01-05 00:58:36 +02:00
parent c4c3dc5a13
commit 3e3828c04a
4 changed files with 19 additions and 8 deletions

View File

@@ -8,6 +8,6 @@ warn_unused_configs = True
#disallow_any_explicit = True
#disallow_any_generics = True
#disallow_subclassing_any = True
#disallow_untyped_calls = True
disallow_untyped_calls = True
disallow_untyped_defs = True
disallow_incomplete_defs = True

View File

@@ -3,7 +3,7 @@ list_voices package for edge_tts.
"""
import json
from typing import Any, Optional
from typing import Any, Dict, List, Optional
import aiohttp
@@ -47,8 +47,12 @@ class VoicesManager:
A class to find the correct voice based on their attributes.
"""
def __init__(self) -> None:
self.voices: List[Dict[str, Any]] = []
self.called_create: bool = False
@classmethod
async def create(cls): # type: ignore
async def create(cls: Any) -> "VoicesManager":
"""
Creates a VoicesManager object and populates it with all available voices.
"""
@@ -58,14 +62,19 @@ class VoicesManager:
{**voice, **{"Language": voice["Locale"].split("-")[0]}}
for voice in self.voices
]
self.called_create = True
return self
def find(self, **kwargs: Any) -> list[dict[str, Any]]:
def find(self, **kwargs: Any) -> List[Dict[str, Any]]:
"""
Finds all matching voices based on the provided attributes.
"""
if not self.called_create:
raise RuntimeError(
"VoicesManager.find() called before VoicesManager.create()"
)
matching_voices = [
voice for voice in self.voices if kwargs.items() <= voice.items() # type: ignore
voice for voice in self.voices if kwargs.items() <= voice.items()
]
return matching_voices

View File

@@ -78,7 +78,9 @@ class SubMaker:
data = "WEBVTT\r\n\r\n"
for offset, subs in zip(self.offset, self.subs):
subs = unescape(subs)
split_subs: List[str] = [subs[i : i + 79] for i in range(0, len(subs), 79)]
split_subs: List[str] = [
subs[i : i + 79] for i in range(0, len(subs), 79)
]
for i in range(len(split_subs) - 1):
sub = split_subs[i]

View File

@@ -5,8 +5,8 @@ Main package.
import argparse
import asyncio
from io import BufferedWriter
import sys
from io import BufferedWriter
from typing import Any
from edge_tts import Communicate, SubMaker, list_voices
@@ -45,7 +45,7 @@ async def _run_tts(args: Any) -> None:
if isinstance(media_file, BufferedWriter):
media_file.write(data["data"])
else:
sys.stdout.buffer.write(data["data"])
sys.stdout.buffer.write(data["data"])
elif data["type"] == "WordBoundary":
subs.create_sub((data["offset"], data["duration"]), data["text"])