2024-09-15 23:12:30 -04:00
|
|
|
import asyncio
|
|
|
|
import logging
|
|
|
|
import sys
|
|
|
|
|
|
|
|
from pyflowery.models import FloweryAPIConfig
|
|
|
|
from pyflowery.pyflowery import FloweryAPI
|
|
|
|
|
|
|
|
root = logging.getLogger()
|
|
|
|
root.setLevel(logging.DEBUG)
|
|
|
|
|
|
|
|
handler = logging.StreamHandler(sys.stdout)
|
|
|
|
handler.setLevel(logging.DEBUG)
|
|
|
|
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
|
|
|
handler.setFormatter(formatter)
|
|
|
|
root.addHandler(handler)
|
|
|
|
|
2024-09-17 23:24:14 -04:00
|
|
|
api = FloweryAPI(FloweryAPIConfig(user_agent="PyFloweryTests"))
|
2024-09-15 23:12:30 -04:00
|
|
|
|
2024-09-16 09:07:27 -04:00
|
|
|
ALEXANDER = "fa3ea565-121f-5efd-b4e9-59895c77df23" # TikTok
|
|
|
|
JACOB = "38f45366-68e8-5d39-b1ef-3fd4eeb61cdb" # Microsoft Azure
|
|
|
|
STORMTROOPER = "191c5adc-a092-5eea-b4ff-ce01f66153ae" # TikTok
|
|
|
|
|
2024-09-18 09:55:25 -04:00
|
|
|
async def test_fetch_tts():
|
|
|
|
"""Test the fetch_tts method"""
|
|
|
|
voice = api.get_voices(voice_id=ALEXANDER)[0]
|
|
|
|
tts = await api.fetch_tts(text="Sphinx of black quartz, judge my vow. The quick brown fox jumps over a lazy dog.", voice=voice)
|
2024-09-15 23:12:30 -04:00
|
|
|
try:
|
|
|
|
with open('test.mp3', 'wb') as f:
|
|
|
|
f.write(tts)
|
2024-09-15 23:18:56 -04:00
|
|
|
except Exception as e: # pylint: disable=broad-except
|
2024-09-15 23:12:30 -04:00
|
|
|
api.config.logger.error(e, exc_info=True)
|
|
|
|
long_string = 'a' * 2049
|
|
|
|
try:
|
2024-09-18 09:55:25 -04:00
|
|
|
await api.fetch_tts(text=long_string)
|
2024-09-15 23:12:30 -04:00
|
|
|
except ValueError as e:
|
2024-09-16 09:07:27 -04:00
|
|
|
api.config.logger.error("This is expected to fail:\n%s", e, exc_info=True)
|
2024-09-15 23:12:30 -04:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2024-09-18 09:55:25 -04:00
|
|
|
api.config.logger.info("testing fetch_tts")
|
|
|
|
asyncio.run(test_fetch_tts())
|