Allow custom voice list to be passed to VoiceManager

* Useful so that the application could cache the list.
* Bump to version 6.1.x
This commit is contained in:
rany2
2023-01-09 18:31:53 +02:00
parent bd9cc2bd2d
commit d95b5d339f
3 changed files with 6 additions and 4 deletions

View File

@@ -1,6 +1,6 @@
[metadata] [metadata]
name = edge-tts name = edge-tts
version = 6.0.9 version = 6.1.0
author = rany author = rany
author_email = ranygh@riseup.net author_email = ranygh@riseup.net
description = Microsoft Edge's TTS description = Microsoft Edge's TTS

View File

@@ -14,4 +14,4 @@ __all__ = [
"exceptions", "exceptions",
"list_voices", "list_voices",
] ]
__version__ = "6.0.7" __version__ = "6.1"

View File

@@ -52,12 +52,14 @@ class VoicesManager:
self.called_create: bool = False self.called_create: bool = False
@classmethod @classmethod
async def create(cls: Any) -> "VoicesManager": async def create(
cls: Any, custom_voices: Optional[List[Dict[str, Any]]] = None
) -> Any:
""" """
Creates a VoicesManager object and populates it with all available voices. Creates a VoicesManager object and populates it with all available voices.
""" """
self = VoicesManager() self = VoicesManager()
self.voices = await list_voices() self.voices = await list_voices() if custom_voices is None else custom_voices
self.voices = [ self.voices = [
{**voice, **{"Language": voice["Locale"].split("-")[0]}} {**voice, **{"Language": voice["Locale"].split("-")[0]}}
for voice in self.voices for voice in self.voices