Skip to main content

Easy async interface to easy-gtts-api

Project description

py-easygTTS

Asynchronous interface to an easy-gtts server written with aiohttp.
One class currently exists, easygTTS.gtts, which takes 2 optional args base_url (url to a easy-gtts server) and session (aiohttp.ClientSession)

Examples

One time use

import easygTTS
import asyncio

async def main():
    async with easygTTS.gtts() as gtts:
        hello_uk = await gtts.get(text="Hello World", lang="en-uk")
        hello_usa = await gtts.get(text="Hello World", lang="en-us")
        langs = await gtts.langs()

    with open("Hello World (UK).mp3", "wb") as f:
        f.write(hello_uk)
    with open("Hello World (USA).mp3", "wb") as f:
        f.write(hello_usa)
    print(f"Returned langs = {langs}")

asyncio.run(main())

Using a global session

import easygTTS
import asyncio
import aiohttp

async def main():
    session = aiohttp.ClientSession()
    gtts = easygTTS.gtts(session=session)

    hello = await gtts.get(text="Hello World")
    with open("Hello.mp3", "wb") as f:
        f.write(hello)

    # later in your code
    extra = await gtts.get(text="even more to TTS")
    with open("Extra.mp3", "wb") as f:
        f.write(extra)

    # at the end
    await session.close()

asyncio.run(main())

Project details


Release history Release notifications | RSS feed

This version

1.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

easygTTS-1.0.tar.gz (2.6 kB view hashes)

Uploaded Source

Built Distribution

easygTTS-1.0-py2.py3-none-any.whl (3.3 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page