PyFlowery/tests/tests.py

44 lines
1.3 KiB
Python
Raw Permalink Normal View History

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)
api = FloweryAPI(FloweryAPIConfig())
async def test_get_voices():
2024-09-15 23:18:56 -04:00
"""Test the get_voices method"""
2024-09-15 23:12:30 -04:00
async for voice in api.get_voices():
if 'en' in voice.language.code:
api.config.logger.info(voice)
async def test_get_tts():
2024-09-15 23:18:56 -04:00
"""Test the get_tts method"""
2024-09-15 23:12:30 -04:00
tts = await api.get_tts(text="BLAST HIM!", voice="191c5adc-a092-5eea-b4ff-ce01f66153ae")
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:
await api.get_tts(text=long_string)
except ValueError as e:
api.config.logger.error(e, exc_info=True)
if __name__ == '__main__':
api.config.logger.info("testing get_voices")
asyncio.run(test_get_voices())
api.config.logger.info("testing get_tts")
asyncio.run(test_get_tts())