Skip to main content

OpenAI compatible TTS API with support for multiple TTS models

Project description

OpenAI TTS API

This extension provides an OpenAI compatible API for multiple TTS models including Kokoro TTS and RVC.

Used as extension in TTS Webui

Installation

pip install git+https://github.com/rsxdalv/extension_openai_tts_api@main

Requirements

Models require individual installation of their extensions.

# Kokoro TTS
pip install git+https://github.com/rsxdalv/extension_kokoro@main
# RVC
pip install git+https://github.com/rsxdalv/extension_rvc@main
# Chatterbox
pip install git+https://github.com/rsxdalv/extension_chatterbox@main

Usage

Kokoro TTS

import asyncio

from openai import AsyncOpenAI
from openai.helpers import LocalAudioPlayer

openai = AsyncOpenAI()

async def main() -> None:
    async with openai.audio.speech.with_streaming_response.create(
        model="hexgrad/Kokoro-82M",
        voice="af_heart",
        input="Today is a wonderful day to build something people love!",
    ) as response:
        await LocalAudioPlayer().play(response)

if __name__ == "__main__":
    asyncio.run(main())

RVC

import asyncio

from openai import AsyncOpenAI
from openai.helpers import LocalAudioPlayer

openai = AsyncOpenAI()

async def main() -> None:
    async with openai.audio.speech.with_streaming_response.create(
        model="hexgrad/Kokoro-82M",
        voice="af_heart",
        input="Today is a wonderful day to build something people love!",
        extra_body={
            "params": {
                "use_gpu": True,
                "rvc_params": {
                    "pitch_up_key": "0",
                    "index_path": "CaitArcane\\added_IVF65_Flat_nprobe_1_CaitArcane_v2",
                    "pitch_collection_method": "harvest",
                    "model_path": "CaitArcane\\CaitArcane",
                    "index_rate": 0.66,
                    "filter_radius": 3,
                    "resample_sr": 0,
                    "rms_mix_rate": 1,
                    "protect": 0.33,
                },
            },
        },
    ) as response:
        await LocalAudioPlayer().play(response)

if __name__ == "__main__":
    asyncio.run(main())

Chatterbox

from openai import OpenAI

client = OpenAI(api_key="sk-1234567890", base_url="http://localhost:7778/v1")

with client.audio.speech.with_streaming_response.create(
    model="chatterbox",
    # voice="random",
    voice="voices/irohazaka.wav",
    input="Today is a wonderful day to build something people love!",
    # speed=1.0, # not implemented
    extra_body={
        "params": {
            "exaggeration": 0.5,
            "cfg_weight": 0.5,
            "temperature": 0.8,
        },
    },
) as response:
    audio = response.read()
    with open("audio.mp3", "wb") as f:
        f.write(audio)

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

tts_webui_extension_openai_tts_api-0.13.0.tar.gz (17.2 kB view details)

Uploaded Source

Built Distribution

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

File details

Details for the file tts_webui_extension_openai_tts_api-0.13.0.tar.gz.

File metadata

File hashes

Hashes for tts_webui_extension_openai_tts_api-0.13.0.tar.gz
Algorithm Hash digest
SHA256 e3fe4222c87c1908c9f1f732ef2c9d88c47fccb14c37e3ce9565421f02a79ff4
MD5 dc70b861bb85e75ee1fee621293859e1
BLAKE2b-256 1a65f92ed5cbd654b0e1a308c86b1bb246b7d46e1c8a46eb6219a618b15971d2

See more details on using hashes here.

File details

Details for the file tts_webui_extension_openai_tts_api-0.13.0-py3-none-any.whl.

File metadata

File hashes

Hashes for tts_webui_extension_openai_tts_api-0.13.0-py3-none-any.whl
Algorithm Hash digest
SHA256 43e7b222c5006d9d29841f19b4b7bb81ef3f9ff51ea7b948d393f2aca4581d4d
MD5 1faf4ca594dc6412ec8cbcf058878f69
BLAKE2b-256 86457d2ecae004be12b4115d2ea0e603d65ef658aefa70ff893173fc9dc8fbb1

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