tts-webui-extension.openai-tts-api 0.13.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. tts_webui_extension_openai_tts_api-0.13.0/LICENSE +21 -0
  2. tts_webui_extension_openai_tts_api-0.13.0/PKG-INFO +154 -0
  3. tts_webui_extension_openai_tts_api-0.13.0/README.md +112 -0
  4. tts_webui_extension_openai_tts_api-0.13.0/setup.cfg +4 -0
  5. tts_webui_extension_openai_tts_api-0.13.0/setup.py +62 -0
  6. tts_webui_extension_openai_tts_api-0.13.0/tts_webui_extension/openai_tts_api/__init__.py +0 -0
  7. tts_webui_extension_openai_tts_api-0.13.0/tts_webui_extension/openai_tts_api/api/__init__.py +6 -0
  8. tts_webui_extension_openai_tts_api-0.13.0/tts_webui_extension/openai_tts_api/api/audio.py +60 -0
  9. tts_webui_extension_openai_tts_api-0.13.0/tts_webui_extension/openai_tts_api/api/info.py +42 -0
  10. tts_webui_extension_openai_tts_api-0.13.0/tts_webui_extension/openai_tts_api/api/models.py +51 -0
  11. tts_webui_extension_openai_tts_api-0.13.0/tts_webui_extension/openai_tts_api/extension_metadata.py +15 -0
  12. tts_webui_extension_openai_tts_api-0.13.0/tts_webui_extension/openai_tts_api/main.py +346 -0
  13. tts_webui_extension_openai_tts_api-0.13.0/tts_webui_extension/openai_tts_api/migrate_config.py +9 -0
  14. tts_webui_extension_openai_tts_api-0.13.0/tts_webui_extension/openai_tts_api/models/__init__.py +7 -0
  15. tts_webui_extension_openai_tts_api-0.13.0/tts_webui_extension/openai_tts_api/models/create_speech_request.py +49 -0
  16. tts_webui_extension_openai_tts_api-0.13.0/tts_webui_extension/openai_tts_api/models/response_format.py +10 -0
  17. tts_webui_extension_openai_tts_api-0.13.0/tts_webui_extension/openai_tts_api/router.py +60 -0
  18. tts_webui_extension_openai_tts_api-0.13.0/tts_webui_extension/openai_tts_api/services/__init__.py +34 -0
  19. tts_webui_extension_openai_tts_api-0.13.0/tts_webui_extension/openai_tts_api/services/transcription_service.py +81 -0
  20. tts_webui_extension_openai_tts_api-0.13.0/tts_webui_extension/openai_tts_api/services/tts_service.py +364 -0
  21. tts_webui_extension_openai_tts_api-0.13.0/tts_webui_extension/openai_tts_api/services/voice_service.py +119 -0
  22. tts_webui_extension_openai_tts_api-0.13.0/tts_webui_extension/openai_tts_api/threader.py +126 -0
  23. tts_webui_extension_openai_tts_api-0.13.0/tts_webui_extension/openai_tts_api/transcribe_audio_file.py +7 -0
  24. tts_webui_extension_openai_tts_api-0.13.0/tts_webui_extension/openai_tts_api/utils/__init__.py +7 -0
  25. tts_webui_extension_openai_tts_api-0.13.0/tts_webui_extension/openai_tts_api/utils/audio_utils.py +35 -0
  26. tts_webui_extension_openai_tts_api-0.13.0/tts_webui_extension/openai_tts_api/utils/presets.py +108 -0
  27. tts_webui_extension_openai_tts_api-0.13.0/tts_webui_extension.openai_tts_api.egg-info/PKG-INFO +154 -0
  28. tts_webui_extension_openai_tts_api-0.13.0/tts_webui_extension.openai_tts_api.egg-info/SOURCES.txt +29 -0
  29. tts_webui_extension_openai_tts_api-0.13.0/tts_webui_extension.openai_tts_api.egg-info/dependency_links.txt +1 -0
  30. tts_webui_extension_openai_tts_api-0.13.0/tts_webui_extension.openai_tts_api.egg-info/requires.txt +27 -0
  31. tts_webui_extension_openai_tts_api-0.13.0/tts_webui_extension.openai_tts_api.egg-info/top_level.txt +5 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 rsxdalv
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,154 @@
1
+ Metadata-Version: 2.4
2
+ Name: tts_webui_extension.openai_tts_api
3
+ Version: 0.13.0
4
+ Summary: OpenAI compatible TTS API with support for multiple TTS models
5
+ Home-page: https://github.com/rsxdalv/tts_webui_extension.openai_tts_api
6
+ Author: rsxdalv
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: License :: OSI Approved :: MIT License
9
+ Classifier: Operating System :: OS Independent
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE
12
+ Requires-Dist: openai
13
+ Requires-Dist: gradio
14
+ Requires-Dist: uvicorn
15
+ Requires-Dist: psutil
16
+ Requires-Dist: fastapi
17
+ Requires-Dist: pydantic
18
+ Requires-Dist: requests
19
+ Requires-Dist: scipy
20
+ Requires-Dist: numpy
21
+ Provides-Extra: kokoro
22
+ Requires-Dist: extension_kokoro; extra == "kokoro"
23
+ Provides-Extra: rvc
24
+ Requires-Dist: extension_rvc; extra == "rvc"
25
+ Provides-Extra: chatterbox
26
+ Requires-Dist: extension_chatterbox; extra == "chatterbox"
27
+ Provides-Extra: kitten-tts
28
+ Requires-Dist: extension_kitten_tts; extra == "kitten-tts"
29
+ Provides-Extra: styletts2
30
+ Requires-Dist: extension_styletts2; extra == "styletts2"
31
+ Provides-Extra: f5-tts
32
+ Requires-Dist: extension_f5_tts; extra == "f5-tts"
33
+ Dynamic: author
34
+ Dynamic: classifier
35
+ Dynamic: description
36
+ Dynamic: description-content-type
37
+ Dynamic: home-page
38
+ Dynamic: license-file
39
+ Dynamic: provides-extra
40
+ Dynamic: requires-dist
41
+ Dynamic: summary
42
+
43
+ # OpenAI TTS API
44
+
45
+ This extension provides an OpenAI compatible API for multiple TTS models including Kokoro TTS and RVC.
46
+
47
+ Used as extension in [TTS Webui](https://github.com/rsxdalv/tts-webui)
48
+
49
+ ## Installation
50
+
51
+ ```bash
52
+ pip install git+https://github.com/rsxdalv/extension_openai_tts_api@main
53
+ ```
54
+
55
+ ## Requirements
56
+
57
+ Models require individual installation of their extensions.
58
+
59
+ ```bash
60
+ # Kokoro TTS
61
+ pip install git+https://github.com/rsxdalv/extension_kokoro@main
62
+ # RVC
63
+ pip install git+https://github.com/rsxdalv/extension_rvc@main
64
+ # Chatterbox
65
+ pip install git+https://github.com/rsxdalv/extension_chatterbox@main
66
+ ```
67
+
68
+ ## Usage
69
+
70
+ ### Kokoro TTS
71
+
72
+ ```python
73
+ import asyncio
74
+
75
+ from openai import AsyncOpenAI
76
+ from openai.helpers import LocalAudioPlayer
77
+
78
+ openai = AsyncOpenAI()
79
+
80
+ async def main() -> None:
81
+ async with openai.audio.speech.with_streaming_response.create(
82
+ model="hexgrad/Kokoro-82M",
83
+ voice="af_heart",
84
+ input="Today is a wonderful day to build something people love!",
85
+ ) as response:
86
+ await LocalAudioPlayer().play(response)
87
+
88
+ if __name__ == "__main__":
89
+ asyncio.run(main())
90
+ ```
91
+
92
+ ### RVC
93
+
94
+ ```python
95
+ import asyncio
96
+
97
+ from openai import AsyncOpenAI
98
+ from openai.helpers import LocalAudioPlayer
99
+
100
+ openai = AsyncOpenAI()
101
+
102
+ async def main() -> None:
103
+ async with openai.audio.speech.with_streaming_response.create(
104
+ model="hexgrad/Kokoro-82M",
105
+ voice="af_heart",
106
+ input="Today is a wonderful day to build something people love!",
107
+ extra_body={
108
+ "params": {
109
+ "use_gpu": True,
110
+ "rvc_params": {
111
+ "pitch_up_key": "0",
112
+ "index_path": "CaitArcane\\added_IVF65_Flat_nprobe_1_CaitArcane_v2",
113
+ "pitch_collection_method": "harvest",
114
+ "model_path": "CaitArcane\\CaitArcane",
115
+ "index_rate": 0.66,
116
+ "filter_radius": 3,
117
+ "resample_sr": 0,
118
+ "rms_mix_rate": 1,
119
+ "protect": 0.33,
120
+ },
121
+ },
122
+ },
123
+ ) as response:
124
+ await LocalAudioPlayer().play(response)
125
+
126
+ if __name__ == "__main__":
127
+ asyncio.run(main())
128
+ ```
129
+
130
+ ### Chatterbox
131
+
132
+ ```python
133
+ from openai import OpenAI
134
+
135
+ client = OpenAI(api_key="sk-1234567890", base_url="http://localhost:7778/v1")
136
+
137
+ with client.audio.speech.with_streaming_response.create(
138
+ model="chatterbox",
139
+ # voice="random",
140
+ voice="voices/irohazaka.wav",
141
+ input="Today is a wonderful day to build something people love!",
142
+ # speed=1.0, # not implemented
143
+ extra_body={
144
+ "params": {
145
+ "exaggeration": 0.5,
146
+ "cfg_weight": 0.5,
147
+ "temperature": 0.8,
148
+ },
149
+ },
150
+ ) as response:
151
+ audio = response.read()
152
+ with open("audio.mp3", "wb") as f:
153
+ f.write(audio)
154
+ ```
@@ -0,0 +1,112 @@
1
+ # OpenAI TTS API
2
+
3
+ This extension provides an OpenAI compatible API for multiple TTS models including Kokoro TTS and RVC.
4
+
5
+ Used as extension in [TTS Webui](https://github.com/rsxdalv/tts-webui)
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ pip install git+https://github.com/rsxdalv/extension_openai_tts_api@main
11
+ ```
12
+
13
+ ## Requirements
14
+
15
+ Models require individual installation of their extensions.
16
+
17
+ ```bash
18
+ # Kokoro TTS
19
+ pip install git+https://github.com/rsxdalv/extension_kokoro@main
20
+ # RVC
21
+ pip install git+https://github.com/rsxdalv/extension_rvc@main
22
+ # Chatterbox
23
+ pip install git+https://github.com/rsxdalv/extension_chatterbox@main
24
+ ```
25
+
26
+ ## Usage
27
+
28
+ ### Kokoro TTS
29
+
30
+ ```python
31
+ import asyncio
32
+
33
+ from openai import AsyncOpenAI
34
+ from openai.helpers import LocalAudioPlayer
35
+
36
+ openai = AsyncOpenAI()
37
+
38
+ async def main() -> None:
39
+ async with openai.audio.speech.with_streaming_response.create(
40
+ model="hexgrad/Kokoro-82M",
41
+ voice="af_heart",
42
+ input="Today is a wonderful day to build something people love!",
43
+ ) as response:
44
+ await LocalAudioPlayer().play(response)
45
+
46
+ if __name__ == "__main__":
47
+ asyncio.run(main())
48
+ ```
49
+
50
+ ### RVC
51
+
52
+ ```python
53
+ import asyncio
54
+
55
+ from openai import AsyncOpenAI
56
+ from openai.helpers import LocalAudioPlayer
57
+
58
+ openai = AsyncOpenAI()
59
+
60
+ async def main() -> None:
61
+ async with openai.audio.speech.with_streaming_response.create(
62
+ model="hexgrad/Kokoro-82M",
63
+ voice="af_heart",
64
+ input="Today is a wonderful day to build something people love!",
65
+ extra_body={
66
+ "params": {
67
+ "use_gpu": True,
68
+ "rvc_params": {
69
+ "pitch_up_key": "0",
70
+ "index_path": "CaitArcane\\added_IVF65_Flat_nprobe_1_CaitArcane_v2",
71
+ "pitch_collection_method": "harvest",
72
+ "model_path": "CaitArcane\\CaitArcane",
73
+ "index_rate": 0.66,
74
+ "filter_radius": 3,
75
+ "resample_sr": 0,
76
+ "rms_mix_rate": 1,
77
+ "protect": 0.33,
78
+ },
79
+ },
80
+ },
81
+ ) as response:
82
+ await LocalAudioPlayer().play(response)
83
+
84
+ if __name__ == "__main__":
85
+ asyncio.run(main())
86
+ ```
87
+
88
+ ### Chatterbox
89
+
90
+ ```python
91
+ from openai import OpenAI
92
+
93
+ client = OpenAI(api_key="sk-1234567890", base_url="http://localhost:7778/v1")
94
+
95
+ with client.audio.speech.with_streaming_response.create(
96
+ model="chatterbox",
97
+ # voice="random",
98
+ voice="voices/irohazaka.wav",
99
+ input="Today is a wonderful day to build something people love!",
100
+ # speed=1.0, # not implemented
101
+ extra_body={
102
+ "params": {
103
+ "exaggeration": 0.5,
104
+ "cfg_weight": 0.5,
105
+ "temperature": 0.8,
106
+ },
107
+ },
108
+ ) as response:
109
+ audio = response.read()
110
+ with open("audio.mp3", "wb") as f:
111
+ f.write(audio)
112
+ ```
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,62 @@
1
+ import setuptools
2
+ from pathlib import Path
3
+
4
+ HERE = Path(__file__).parent
5
+ README = (HERE / "README.md").read_text(encoding="utf-8") if (HERE / "README.md").exists() else ""
6
+
7
+ setuptools.setup(
8
+ name="tts_webui_extension.openai_tts_api",
9
+ packages=setuptools.find_namespace_packages(),
10
+ version="0.13.0",
11
+ author="rsxdalv",
12
+ description="OpenAI compatible TTS API with support for multiple TTS models",
13
+ long_description=README,
14
+ long_description_content_type="text/markdown",
15
+ url="https://github.com/rsxdalv/tts_webui_extension.openai_tts_api",
16
+ project_urls={},
17
+ scripts=[],
18
+ install_requires=[
19
+ "openai",
20
+ "gradio",
21
+ "uvicorn",
22
+ "psutil",
23
+ "fastapi",
24
+ "pydantic",
25
+ "requests",
26
+ "scipy",
27
+ "numpy",
28
+ ],
29
+ # optional requirements
30
+ extras_require={
31
+ "kokoro": [
32
+ # "extension_kokoro @ git+https://github.com/rsxdalv/extension_kokoro@main",
33
+ "extension_kokoro", # Use this line if the package is available on PyPI
34
+ ],
35
+ "rvc": [
36
+ # "extension_rvc @ git+https://github.com/rsxdalv/extension_rvc@main",
37
+ "extension_rvc", # Use this line if the package is available on PyPI
38
+ ],
39
+ "chatterbox": [
40
+ # "extension_chatterbox @ git+https://github.com/rsxdalv/extension_chatterbox@main",
41
+ "extension_chatterbox", # Use this line if the package is available on PyPI
42
+ ],
43
+ "kitten-tts": [
44
+ # "extension_kitten_tts @ git+https://github.com/rsxdalv/extension_kitten_tts@main",
45
+ "extension_kitten_tts", # Use this line if the package is available on PyPI
46
+ ],
47
+ "styletts2": [
48
+ # "extension_styletts2 @ git+https://github.com/rsxdalv/extension_styletts2@main",
49
+ "extension_styletts2", # Use this line if the package is available on PyPI
50
+ ],
51
+ "f5-tts": [
52
+ # "extension_f5_tts @ git+https://github.com/rsxdalv/extension_f5_tts@main",
53
+ "extension_f5_tts", # Use this line if the package is available on PyPI
54
+ ],
55
+ },
56
+ classifiers=[
57
+ "Programming Language :: Python :: 3",
58
+ "License :: OSI Approved :: MIT License",
59
+ "Operating System :: OS Independent",
60
+ ],
61
+ )
62
+
@@ -0,0 +1,6 @@
1
+ """
2
+ API routes package.
3
+ """
4
+ from . import audio, models, info
5
+
6
+ __all__ = ["audio", "models", "info"]
@@ -0,0 +1,60 @@
1
+ """
2
+ Audio routes for speech generation and transcription.
3
+ """
4
+ import logging
5
+ import uuid
6
+
7
+ from fastapi import APIRouter, BackgroundTasks, HTTPException, Request, Response
8
+ from fastapi.responses import StreamingResponse
9
+
10
+ from ..models import CreateSpeechRequest
11
+ from ..services import (
12
+ generate_speech,
13
+ generate_speech_stream,
14
+ get_content_type,
15
+ transcribe_audio,
16
+ )
17
+
18
+ logger = logging.getLogger(__name__)
19
+
20
+ router = APIRouter(prefix="/v1/audio", tags=["audio"])
21
+
22
+
23
+ @router.post("/speech")
24
+ async def create_speech(
25
+ request: CreateSpeechRequest, background_tasks: BackgroundTasks
26
+ ):
27
+ """Generate speech from text using various TTS models."""
28
+ try:
29
+ content_type = get_content_type(request.response_format)
30
+
31
+ if request.stream and request.model == "chatterbox":
32
+ # Return streaming response for chatterbox
33
+ return StreamingResponse(
34
+ generate_speech_stream(request),
35
+ media_type=content_type,
36
+ headers={
37
+ "Content-Disposition": f"attachment; filename=speech_{uuid.uuid4()}.{request.response_format}",
38
+ "Transfer-Encoding": "chunked",
39
+ },
40
+ )
41
+ else:
42
+ # Return regular response for non-streaming models or when streaming is disabled
43
+ audio_data = generate_speech(request)
44
+ return Response(
45
+ content=audio_data,
46
+ media_type=content_type,
47
+ headers={
48
+ "Content-Disposition": f"attachment; filename=speech_{uuid.uuid4()}.{request.response_format}"
49
+ },
50
+ )
51
+
52
+ except Exception as e:
53
+ logger.error(f"Error generating speech: {e}", exc_info=True)
54
+ raise HTTPException(status_code=500, detail=str(e))
55
+
56
+
57
+ @router.post("/transcriptions")
58
+ async def transcribe_audio_endpoint(request: Request):
59
+ """Transcribe audio to text using Whisper."""
60
+ return await transcribe_audio(request)
@@ -0,0 +1,42 @@
1
+ """
2
+ Information and documentation routes.
3
+ """
4
+ import logging
5
+
6
+ from fastapi import APIRouter
7
+
8
+ logger = logging.getLogger(__name__)
9
+
10
+ router = APIRouter(tags=["info"])
11
+
12
+
13
+ @router.get("/")
14
+ async def root():
15
+ """API information and usage examples."""
16
+ return {
17
+ "info": "OpenAI-compatible Text-to-Speech API with Streaming Support",
18
+ "documentation": "/docs",
19
+ "example": {
20
+ "curl_regular": """
21
+ curl -X POST http://localhost:7778/v1/audio/speech \\
22
+ -H "Content-Type: application/json" \\
23
+ -d '{
24
+ "model": "tts-1",
25
+ "input": "Hello world! This is a test of the text-to-speech API.",
26
+ "voice": "alloy"
27
+ }' \\
28
+ --output speech.mp3
29
+ """,
30
+ "curl_streaming": """
31
+ curl -X POST http://localhost:7778/v1/audio/speech \\
32
+ -H "Content-Type: application/json" \\
33
+ -d '{
34
+ "model": "chatterbox",
35
+ "input": "Hello world! This is a streaming test.",
36
+ "voice": "random",
37
+ "stream": true
38
+ }' \\
39
+ --output speech_stream.wav
40
+ """,
41
+ },
42
+ }
@@ -0,0 +1,51 @@
1
+ """
2
+ Routes for managing models and voices.
3
+ """
4
+ import logging
5
+
6
+ from fastapi import APIRouter, HTTPException
7
+
8
+ from ..services import get_voices_by_model, get_available_models
9
+
10
+ logger = logging.getLogger(__name__)
11
+
12
+ router = APIRouter(prefix="/v1/audio", tags=["models", "voices"])
13
+
14
+
15
+ @router.get("/models")
16
+ async def get_models():
17
+ """Get available TTS models."""
18
+ return {"models": get_available_models()}
19
+
20
+
21
+ @router.get("/voices/{model}")
22
+ async def get_voices(model: str):
23
+ """Get available voices for a specific model."""
24
+ try:
25
+ voices = get_voices_by_model(model)
26
+ return {"voices": voices}
27
+ except Exception as e:
28
+ logger.error(f"Error getting voices for model {model}: {e}")
29
+ raise HTTPException(status_code=500, detail=str(e))
30
+
31
+
32
+ @router.get("/voices")
33
+ async def get_all_voices():
34
+ """Get all available voices from all models."""
35
+ try:
36
+ voices = []
37
+ for model in ["chatterbox", "kokoro", "global_preset", "styletts2", "f5-tts"]:
38
+ try:
39
+ voices.extend(get_voices_by_model(model))
40
+ except Exception as e:
41
+ logger.warning(f"Could not get voices for model {model}: {e}")
42
+ pass
43
+
44
+ for voice in voices:
45
+ voice["id"] = voice.pop("value")
46
+ voice["name"] = voice.pop("label")
47
+
48
+ return {"voices": voices}
49
+ except Exception as e:
50
+ logger.error(f"Error getting voices: {e}")
51
+ raise HTTPException(status_code=500, detail=str(e))
@@ -0,0 +1,15 @@
1
+ def get_metadata():
2
+ return {
3
+ "package_name": "extension_openai_tts_api",
4
+ "name": "OpenAI TTS API",
5
+ "requirements": "git+https://github.com/rsxdalv/extension_openai_tts_api@main",
6
+ "description": "OpenAI compatible TTS API with support for multiple TTS models",
7
+ "extension_type": "interface",
8
+ "extension_class": "tools",
9
+ "author": "hexgrad",
10
+ "extension_author": "rsxdalv",
11
+ "license": "MIT",
12
+ "website": "https://huggingface.co/hexgrad/Kokoro-82M",
13
+ "extension_website": "https://github.com/rsxdalv/extension_openai_tts_api",
14
+ "extension_platform_version": "0.0.1",
15
+ }