Skip to content

Commit 46417b4

Browse files
authored
Refactor vocabulary loading and clean up tokenizer methods (#136)
* Refactor vocabulary loading and clean up tokenizer methods * Refactor example scripts and clean up code formatting * vocab * Fix vocab loading to return the entire JSON object instead of just the 'vocab' key * Add voice configuration download and update vocab loading from config.json * Refactor config file handling and improve code formatting * Simplify GitHub Actions workflow by removing codespell step and renaming job * beta * Add configuration file for istftnet and update .gitignore to include it * Bump version to 0.4.6-beta.1 in pyproject.toml * Enhance Kokoro initialization by adding vocab_config parameter and update examples to include config.json * Update Chinese example to use new voice and adjust vocab_config handling in Kokoro class * tests * config * add 1.1 in chinses misaki example
1 parent 8534fd9 commit 46417b4

File tree

16 files changed

+225
-161
lines changed

16 files changed

+225
-161
lines changed

.github/workflows/check.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@ on:
99
branches: [main]
1010
workflow_dispatch:
1111
jobs:
12-
codespell_and_ruff:
12+
ruff:
1313
runs-on: ubuntu-latest
1414
steps:
15-
- uses: actions/checkout@v4
16-
- uses: codespell-project/actions-codespell@v2
17-
- uses: astral-sh/ruff-action@v3
18-
- run: ruff format --diff
15+
- uses: actions/checkout@v4
16+
- uses: astral-sh/ruff-action@v3
17+
- run: ruff format --diff

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ wheels/
1313
*.wav
1414
*.json
1515
!.vscode/*.json
16+
!src/kokoro_onnx/config.json
1617
espeak-ng-data/
1718
*.tar.gz
1819
*.dylib

examples/chinese.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
Download these files
1313
https://github.com/thewh1teagle/kokoro-onnx/releases/download/model-files-v1.1/kokoro-v1.1-zh.onnx
1414
https://github.com/thewh1teagle/kokoro-onnx/releases/download/model-files-v1.1/voices-v1.1-zh.bin
15+
https://huggingface.co/hexgrad/Kokoro-82M-v1.1-zh/raw/main/config.json
1516
4. Run
1617
uv run main.py
1718
"""
@@ -21,11 +22,11 @@
2122
from misaki import zh
2223

2324
# Misaki G2P with espeak-ng fallback
24-
g2p = zh.ZHG2P()
25+
g2p = zh.ZHG2P(version="1.1")
2526

2627
text = "千里之行,始于足下。"
27-
voice = "af_maple"
28-
kokoro = Kokoro("kokoro-v1.1-zh.onnx", "voices-v1.1-zh.bin")
28+
voice = "zf_001"
29+
kokoro = Kokoro("kokoro-v1.1-zh.onnx", "voices-v1.1-zh.bin", vocab_config="config.json")
2930
phonemes, _ = g2p(text)
3031
samples, sample_rate = kokoro.create(phonemes, voice=voice, speed=1.0, is_phonemes=True)
3132
sf.write("audio.wav", samples, sample_rate)

examples/french.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919

2020
import soundfile as sf
2121
from kokoro_onnx import Kokoro
22-
from misaki import en, espeak
22+
from misaki import espeak
2323
from misaki.espeak import EspeakG2P
2424

2525
# Misaki G2P with espeak-ng fallback
2626
fallback = espeak.EspeakFallback(british=False)
27-
g2p = EspeakG2P(language='fr-fr')
27+
g2p = EspeakG2P(language="fr-fr")
2828

2929
# Kokoro
3030
kokoro = Kokoro("kokoro-v1.0.onnx", "voices-v1.0.bin")

examples/hindi.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919

2020
import soundfile as sf
2121
from kokoro_onnx import Kokoro
22-
from misaki import en, espeak
22+
from misaki import espeak
2323
from misaki.espeak import EspeakG2P
2424

2525
# Misaki G2P with espeak-ng fallback
2626
fallback = espeak.EspeakFallback(british=False)
27-
g2p = EspeakG2P(language='hi')
27+
g2p = EspeakG2P(language="hi")
2828

2929
# Kokoro
3030
kokoro = Kokoro("kokoro-v1.0.onnx", "voices-v1.0.bin")

examples/italian.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919

2020
import soundfile as sf
2121
from kokoro_onnx import Kokoro
22-
from misaki import en, espeak
22+
from misaki import espeak
2323
from misaki.espeak import EspeakG2P
2424

2525
# Misaki G2P with espeak-ng fallback
2626
fallback = espeak.EspeakFallback(british=False)
27-
g2p = EspeakG2P(language='it')
27+
g2p = EspeakG2P(language="it")
2828

2929
# Kokoro
3030
kokoro = Kokoro("kokoro-v1.0.onnx", "voices-v1.0.bin")

examples/japanse.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
Download these files
1313
https://github.com/thewh1teagle/kokoro-onnx/releases/download/model-files-v1.1/kokoro-v1.1-zh.onnx
1414
https://github.com/thewh1teagle/kokoro-onnx/releases/download/model-files-v1.1/voices-v1.1-zh.bin
15+
https://huggingface.co/hexgrad/Kokoro-82M-v1.1-zh/raw/main/config.json
1516
4. Run
1617
uv run main.py
1718
"""
@@ -25,7 +26,7 @@
2526

2627
text = "「人生を夢見るな。夢を生きろ。」"
2728
voice = "jf_alpha"
28-
kokoro = Kokoro("kokoro-v1.0.onnx", "voices-v1.0.bin")
29+
kokoro = Kokoro("kokoro-v1.0.onnx", "voices-v1.0.bin", vocab_config="config.json")
2930
phonemes, _ = g2p(text)
3031
samples, sample_rate = kokoro.create(phonemes, voice=voice, speed=1.0, is_phonemes=True)
3132
sf.write("audio.wav", samples, sample_rate)

examples/portuguese.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919

2020
import soundfile as sf
2121
from kokoro_onnx import Kokoro
22-
from misaki import en, espeak
22+
from misaki import espeak
2323
from misaki.espeak import EspeakG2P
2424

2525
# Misaki G2P with espeak-ng fallback
2626
fallback = espeak.EspeakFallback(british=False)
27-
g2p = EspeakG2P(language='pt-br')
27+
g2p = EspeakG2P(language="pt-br")
2828

2929
# Kokoro
3030
kokoro = Kokoro("kokoro-v1.0.onnx", "voices-v1.0.bin")

examples/spanish.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919

2020
import soundfile as sf
2121
from kokoro_onnx import Kokoro
22-
from misaki import en, espeak
22+
from misaki import espeak
2323
from misaki.espeak import EspeakG2P
2424

2525
# Misaki G2P with espeak-ng fallback
2626
fallback = espeak.EspeakFallback(british=False)
27-
g2p = EspeakG2P(language='es')
27+
g2p = EspeakG2P(language="es")
2828

2929
# Kokoro
3030
kokoro = Kokoro("kokoro-v1.0.onnx", "voices-v1.0.bin")

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "kokoro-onnx"
3-
version = "0.4.5"
3+
version = "0.4.6-beta.1"
44
description = "TTS with kokoro and onnx runtime"
55
readme = "README.md"
66
authors = [

0 commit comments

Comments
 (0)