Merge remote-tracking branch 'origin/master' into simplify
This commit is contained in:
@@ -3,5 +3,5 @@ __init__ for edge_tts
|
||||
"""
|
||||
|
||||
from .communicate import Communicate
|
||||
from .list_voices import list_voices
|
||||
from .submaker import SubMaker
|
||||
from .list_voices import list_voices, VoicesManager
|
||||
from .submaker import SubMaker
|
||||
@@ -40,3 +40,29 @@ async def list_voices(proxy=None):
|
||||
) as url:
|
||||
data = json.loads(await url.text())
|
||||
return data
|
||||
|
||||
|
||||
class VoicesManager:
|
||||
"""
|
||||
A class to find the correct voice based on their attributes.
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
async def create(cls):
|
||||
self = VoicesManager()
|
||||
self.voices = await list_voices()
|
||||
self.voices = [
|
||||
{**voice, **{"Language": voice["Locale"].split("-")[0]}}
|
||||
for voice in self.voices
|
||||
]
|
||||
return self
|
||||
|
||||
def find(self, **kwargs):
|
||||
"""
|
||||
Finds all matching voices based on the provided attributes.
|
||||
"""
|
||||
|
||||
matching_voices = [
|
||||
voice for voice in self.voices if kwargs.items() <= voice.items()
|
||||
]
|
||||
return matching_voices
|
||||
|
||||
Reference in New Issue
Block a user