2024-09-15 23:12:30 -04:00
|
|
|
import asyncio
|
|
|
|
import logging
|
|
|
|
import sys
|
|
|
|
|
2024-11-15 00:10:38 -05:00
|
|
|
from pyflowery import VERSION, FloweryAPI, FloweryAPIConfig
|
2024-09-15 23:12:30 -04:00
|
|
|
|
|
|
|
root = logging.getLogger()
|
2024-11-15 00:10:38 -05:00
|
|
|
root.setLevel(level=logging.DEBUG)
|
2024-09-15 23:12:30 -04:00
|
|
|
|
2024-11-15 00:10:38 -05:00
|
|
|
handler = logging.StreamHandler(stream=sys.stdout)
|
|
|
|
handler.setLevel(level=logging.DEBUG)
|
|
|
|
formatter = logging.Formatter(fmt="%(asctime)s - %(name)s - %(levelname)s - %(message)s")
|
|
|
|
handler.setFormatter(fmt=formatter)
|
|
|
|
root.addHandler(hdlr=handler)
|
2024-09-15 23:12:30 -04:00
|
|
|
|
2024-11-15 00:10:38 -05:00
|
|
|
api = FloweryAPI(config=FloweryAPIConfig(user_agent=f"PyFloweryTests/{VERSION}"))
|
2024-09-15 23:12:30 -04:00
|
|
|
|
2024-11-15 00:10:38 -05: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-16 09:07:27 -04:00
|
|
|
|
2024-11-15 00:10:38 -05:00
|
|
|
|
|
|
|
async def test_fetch_tts() -> None:
|
2024-09-18 09:55:25 -04:00
|
|
|
"""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:
|
2024-11-15 00:10:38 -05:00
|
|
|
with open(file="test.mp3", mode="wb") as f:
|
2024-09-15 23:12:30 -04:00
|
|
|
f.write(tts)
|
2024-11-15 00:10:38 -05: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)
|
2024-11-15 00:10:38 -05:00
|
|
|
long_string = "a" * 2049
|
2024-09-15 23:12:30 -04:00
|
|
|
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-11-15 00:10:38 -05:00
|
|
|
api.config.logger.error("This is expected to fail, and is not causing a non-zero exit code:\n%s", e, exc_info=True)
|
|
|
|
|
2024-09-15 23:12:30 -04:00
|
|
|
|
2024-11-15 00:10:38 -05:00
|
|
|
if __name__ == "__main__":
|
2024-09-18 09:55:25 -04:00
|
|
|
api.config.logger.info("testing fetch_tts")
|
2024-11-15 00:10:38 -05:00
|
|
|
asyncio.run(main=test_fetch_tts())
|