diff --git a/pyflowery/pyflowery.py b/pyflowery/pyflowery.py index ba1323e..fb3ecfd 100644 --- a/pyflowery/pyflowery.py +++ b/pyflowery/pyflowery.py @@ -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 diff --git a/pyflowery/version.py b/pyflowery/version.py index 50b5ea9..2be0457 100644 --- a/pyflowery/version.py +++ b/pyflowery/version.py @@ -1 +1 @@ -VERSION = "1.0.1" +VERSION = "1.0.2" diff --git a/pyproject.toml b/pyproject.toml index bc12f0a..f4ad24d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "pyflowery" -version = "1.0.1" +version = "1.0.2" description = "A Python API wrapper for the Flowery API" authors = ["cswimr "] license = "GPL 3.0-only" diff --git a/tests/tests.py b/tests/tests.py index c0922a8..0c7027c 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -16,6 +16,10 @@ root.addHandler(handler) api = FloweryAPI(FloweryAPIConfig()) +ALEXANDER = "fa3ea565-121f-5efd-b4e9-59895c77df23" # TikTok +JACOB = "38f45366-68e8-5d39-b1ef-3fd4eeb61cdb" # Microsoft Azure +STORMTROOPER = "191c5adc-a092-5eea-b4ff-ce01f66153ae" # TikTok + async def test_get_voices(): """Test the get_voices method""" async for voice in api.get_voices(): @@ -24,7 +28,8 @@ async def test_get_voices(): async def test_get_tts(): """Test the get_tts method""" - tts = await api.get_tts(text="BLAST HIM!", voice="191c5adc-a092-5eea-b4ff-ce01f66153ae") + voice = await api.get_voice(voice_id=ALEXANDER) + tts = await api.get_tts(text="Sphinx of black quartz, judge my vow. The quick brown fox jumps over a lazy dog.", voice=voice) try: with open('test.mp3', 'wb') as f: f.write(tts) @@ -34,7 +39,7 @@ async def test_get_tts(): try: await api.get_tts(text=long_string) except ValueError as e: - api.config.logger.error(e, exc_info=True) + api.config.logger.error("This is expected to fail:\n%s", e, exc_info=True) if __name__ == '__main__': api.config.logger.info("testing get_voices")