|
Download code/PYTHON.md from changh95/Kokoro-82M: direct link, hf CLI and curl.
- Browser
- Download file 2.24 kB
-
https://huggingface.co/changh95/Kokoro-82M/resolve/main/code/PYTHON.md
- Command line
-
hf download hf://changh95/Kokoro-82M/code/PYTHON.md
-
curl -L -o PYTHON.md https://huggingface.co/changh95/Kokoro-82M/resolve/main/code/PYTHON.md
2.24 kB
Kokoro-82M on Tenstorrent p150: Python API
from tt_kokoro.api import KokoroTTS
tts = KokoroTTS.from_env() # KOKORO_* environment (see the configuration table of the model card)
audio, sr, meta = tts.synthesize("Hello world! This is Kokoro on a p150.", voice="af_heart", speed=1.0, seed=7,
timestamps=True)
# audio: float32 numpy [samples] at 24 kHz; meta: chunks (graphemes, phonemes, seconds, words), seed, timings
params = tts.validate(text=long_text, voice="bf_emma:0.6,bf_isabella:0.4", lang="b", stream=True)
for chunk in tts.run(params): # one chunk per sentence (chunking="sentence", the streaming default)
play(chunk.audio) # chunk.graphemes, chunk.phonemes, chunk.pred_dur, chunk.words
tts.close()
Every request field of POST /tts is a keyword of validate / synthesize: text or phonemes, voice,
lang, speed, seed, noise (philox | torch), chunking (official | sentence), split_pattern,
response_format, sample_rate, stream, timestamps, durations.
Engines (KOKORO_ENGINE, read at construction): mk (default: ttnn stages + the MK-RNN megakernel for the six LSTM
recurrences), ttnn (baseline: recurrences on the host CPU), host / KOKORO_BACKEND=cpu (the clean-room fp32
reference on the CPU, no device). Per stage: fe=..,rnn=..,frame=..,gen=...
Layout of code/tt_kokoro/:
| path | content |
|---|---|
api.py, config.py |
the API, request validation, the server configuration |
frontend.py, voices.py |
G2P (misaki) + the official chunking; voice packs, blends, style rows |
reference/ |
the clean-room fp32 model (model.py) and the noise sources (noise.py) |
tt/device.py, tt/ttnn_ops.py |
the device engine (ttnn stages) |
tt/mk_rnn/ |
MK-RNN: the BiLSTM recurrence megakernel (kernels/mr_*.cpp, program.py) |
server/ |
FastAPI app, device worker, fake engine, stdlib smoke test |
tests/ |
host tests (test_host_*, fake engine, goldens when available) |
Host tests: TT_VISIBLE_DEVICES=none python -m pytest code/tt_kokoro/tests/test_host_*.py (weights:
KOKORO_WEIGHTS=<local hexgrad/Kokoro-82M snapshot>; goldens: KOKORO_GOLDEN).