leonelhs commited on
Commit
ce18f8b
·
verified ·
1 Parent(s): 7eaf5e3

Initial commit for Kokoro TTS API for spanish languaje

Files changed (2) hide show
  1. app.py +82 -0
  2. requirements.txt +5 -0
app.py ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #######################################################################################
2
+ #
3
+ # MIT License
4
+ #
5
+ # Copyright (c) [2025] [leonelhs@gmail.com]
6
+ #
7
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ # of this software and associated documentation files (the "Software"), to deal
9
+ # in the Software without restriction, including without limitation the rights
10
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ # copies of the Software, and to permit persons to whom the Software is
12
+ # furnished to do so, subject to the following conditions:
13
+ #
14
+ # The above copyright notice and this permission notice shall be included in all
15
+ # copies or substantial portions of the Software.
16
+ #
17
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ # SOFTWARE.
24
+ #
25
+ #######################################################################################
26
+
27
+ # This file implements an API endpoint for the Spanish Kokoro Text-to-Speech (TTS) system.
28
+ # It provides functionality to generate TTS audio from input Spanish text using the Kokoro voice model.
29
+
30
+
31
+ # Source code is based on or inspired by several projects.
32
+ # For more details and proper attribution, please refer to the following resources:
33
+ #
34
+ # - [Kokoro-82M] - [https://huggingface.co/hexgrad/Kokoro-82M]
35
+ # - [Kokoro-onnx] - [https://github.com/thewh1teagle/kokoro-onnx]
36
+ # - [Misaki] - [https://github.com/hexgrad/misaki]
37
+
38
+ import os
39
+ import gradio as gr
40
+ from misaki import espeak
41
+ from misaki.espeak import EspeakG2P
42
+ from kokoro_onnx import Kokoro
43
+ from huggingface_hub import snapshot_download
44
+
45
+ KOKORO_REPO_ID = "leonelhs/kokoro-thewh1teagle"
46
+
47
+ VOICES = {
48
+ '🚺 Dora':'ef_dora',
49
+ '🚹 Alex':'em_alex',
50
+ '🚹 Santa':'em_santa'
51
+ }
52
+
53
+ snapshot = snapshot_download(repo_id=KOKORO_REPO_ID)
54
+
55
+ # Misaki G2P with espeak-ng fallback
56
+ fallback = espeak.EspeakFallback(british=False)
57
+ g2p = EspeakG2P(language="es")
58
+
59
+ # Kokoro
60
+ model_path = os.path.join(snapshot, "kokoro-v1.0.onnx")
61
+ voices_path = os.path.join(snapshot, "voices-v1.0.bin")
62
+ kokoro = Kokoro(model_path, voices_path)
63
+
64
+ def predict(text, voice='ef_dora', speed=1):
65
+ phonemes, _ = g2p(text)
66
+ samples, sample_rate = kokoro.create(phonemes, voice, speed, is_phonemes=True)
67
+ return sample_rate, samples
68
+
69
+ app = gr.Interface(
70
+ predict,
71
+ [
72
+ gr.Textbox(label='Input Text'),
73
+ gr.Dropdown(list(VOICES.items()), value='ef_dora', label='Voice'),
74
+ gr.Slider(minimum=0.5, maximum=2, value=1, step=0.1, label='Speed')
75
+ ],
76
+ gr.Audio(label='Output Audio', interactive=False, streaming=False, autoplay=True),
77
+ description="Kokoro TTS 🇪🇸 API Endpoint",
78
+ )
79
+
80
+ app.launch(share=False, debug=True, show_error=True)
81
+ app.queue()
82
+
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ kokoro-onnx
2
+ gradio~=5.44.1
3
+ misaki~=0.9.4
4
+ onnxruntime~=1.22.1
5
+ huggingface-hub~=0.34.4