(1.0.2) added get_voice() method and added handling for if the request code of get_tts() is between 400 and 600
This commit is contained in:
parent
8f52fda97c
commit
d585072d3e
4 changed files with 24 additions and 4 deletions
|
@ -15,6 +15,19 @@ class FloweryAPI:
|
|||
self.config = config
|
||||
self.adapter = RestAdapter(config)
|
||||
|
||||
async def get_voice(self, voice_id: str) -> Voice:
|
||||
"""Get a voice from the Flowery API
|
||||
|
||||
Args:
|
||||
voice_id (str): The ID of the voice
|
||||
|
||||
Returns:
|
||||
Voice: The voice
|
||||
"""
|
||||
async for voice in self.get_voices():
|
||||
if voice.id == voice_id:
|
||||
return voice
|
||||
|
||||
async def get_voices(self) -> AsyncGenerator[Voice, None]:
|
||||
"""Get a list of voices from the Flowery API
|
||||
|
||||
|
@ -59,4 +72,6 @@ class FloweryAPI:
|
|||
if voice:
|
||||
params['voice'] = voice.id if isinstance(voice, Voice) else voice
|
||||
request = await self.adapter.get('/tts', params, timeout=180)
|
||||
if request.status_code in range(400, 600):
|
||||
raise ValueError(request.data['message'])
|
||||
return request.data
|
||||
|
|
|
@ -1 +1 @@
|
|||
VERSION = "1.0.1"
|
||||
VERSION = "1.0.2"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue