Skip to main content

An asynchronous library for interacting with the FakeYou Text-to-Speech API.

Project description

AsyncFakeYou

AsyncFakeYou is an asynchronous Python library for interacting with the FakeYou Text-to-Speech API. It allows you to submit TTS requests, track their status, and download the resulting audio files, all in an asynchronous manner using asyncio, aiohttp and aiofiles.

Features

  • Asynchronous requests to FakeYou TTS API.
  • Generation with parallel execution control
  • Handle user authentication with session cookies

Installation

pip install asyncfakeyou

Simple usage

You can obtain a direct URL to the generated audio file.

from src.asyncfakeyou import AsyncAudioGen
import asyncio


async def text_to_speech():
    gen = AsyncAudioGen(cookies="your_cookie_string")
    audio_url = await gen.fetch_audio("model_token_here", "sample_text")
    print(audio_url)


asyncio.run(text_to_speech())

Or you can download the generated audio file to a specified directory.

from src.asyncfakeyou import AsyncAudioGen
import asyncio


async def text_to_speech():
    gen = AsyncAudioGen(cookies="your_cookie_string")
    audio_url = await gen.fetch_and_save_audio("model_token_here", "sample_text",
                                               output_path="./audio",
                                               filename="generated_audio.wav")
    print(audio_url)


asyncio.run(text_to_speech())

##How to obtain cookies? The cookies parameter of the AsyncAudioGen class is optional. However, I recommend setting it as it will give you higher queue priority, even without a paid subscription. If you have a premium account, you will be able to take advantage of all its benefits through this API.

from src.asyncfakeyou import receive_cookies
import asyncio


async def get_my_cookies():
    cookies = await receive_cookies("your_username_or_email", "your_password")
    print(cookies)


asyncio.run(get_my_cookies())

Parallel execution

If you need to generate multiple audio files, you can speed up the process by using fetch_tasks and fetch_and_save_tasks. These methods handle a fixed number of tasks in parallel (concurrent_tasks parameter) and automatically retry failed requests. The default value for concurrent_tasks is 3, but you can tweak this parameter.

You can iterate through the direct URLs to the generated audio files.

from src.asyncfakeyou import AsyncAudioGen
import asyncio


async def multiple_text_to_speech():
    gen = AsyncAudioGen(cookies="your_cookie_string")
    audio_tasks = [
        ("model_token_1", "sample_text_1"),
        ("model_token_2", "sample_text_2"),
        ("model_token_3", "sample_text_3")
    ]
    async for audio_url in gen.fetch_tasks(audio_tasks):
        print(audio_url)


asyncio.run(execute_tasks())

Or you can download the generated audio files to a specified directory.

from src.asyncfakeyou import AsyncAudioGen
import asyncio


async def multiple_text_to_speech():
    gen = AsyncAudioGen(cookies="your_cookie_string")
    audio_tasks = [
        ("model_token_1", "sample_text_1", "filename1.wav"),
        ("model_token_2", "sample_text_2", "filename2.wav"),
        ("model_token_3", "sample_text_3", "filename3.wav")
    ]
    await gen.fetch_and_save_tasks(audio_tasks, output_path="./audio")


asyncio.run(execute_tasks())

Contributing

Contributions are welcome! Please fork the repository and create a pull request with your improvements.

Project details


Download files

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

Source Distribution

asyncfakeyou-0.1.0.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

asyncfakeyou-0.1.0-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file asyncfakeyou-0.1.0.tar.gz.

File metadata

  • Download URL: asyncfakeyou-0.1.0.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for asyncfakeyou-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e550dac1240a150bcb7333ad47b0e6a3e1a412a659e4a298dbb8266b8278b580
MD5 340affc3e983a24f3487390d57853ef7
BLAKE2b-256 8500cf071e91bfa837aa2c769da69bc242bfbb217980d07bcc8db2126437b0ea

See more details on using hashes here.

File details

Details for the file asyncfakeyou-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: asyncfakeyou-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for asyncfakeyou-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d2bc52394ad54e4bc4bddd639050f8be9145d066fc992a0ec19053100c52b050
MD5 0e38c44d0ed7fc8a657c1e53dc05e652
BLAKE2b-256 547bcff7c3fb886146504c73cb84e35d45e820e69406587291ce5a8aa5f761c8

See more details on using hashes here.

Supported by

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