Skip to content

Commit 6982b86

Browse files
authored
Support extra languages in multi-lang kokoro tts (#2303)
1 parent a6095f5 commit 6982b86

28 files changed

Lines changed: 187 additions & 49 deletions

.github/workflows/test-build-wheel.yaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,18 @@ jobs:
3535
matrix:
3636
# See https://github.com/actions/runner-images
3737
include:
38-
- os: ubuntu-22.04
39-
python-version: "3.7"
40-
- os: ubuntu-22.04
38+
- os: ubuntu-latest
4139
python-version: "3.8"
42-
- os: ubuntu-22.04
40+
- os: ubuntu-latest
4341
python-version: "3.9"
44-
- os: ubuntu-22.04
42+
- os: ubuntu-latest
4543
python-version: "3.10"
46-
- os: ubuntu-22.04
44+
- os: ubuntu-latest
4745
python-version: "3.11"
48-
- os: ubuntu-22.04
46+
- os: ubuntu-latest
4947
python-version: "3.12"
48+
- os: ubuntu-latest
49+
python-version: "3.13"
5050

5151
- os: macos-13
5252
python-version: "3.8"
@@ -103,7 +103,7 @@ jobs:
103103
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
104104
cmake --version
105105
106-
export SHERPA_ONNX_MAKE_ARGS="VERBOSE=1 -j"
106+
export SHERPA_ONNX_MAKE_ARGS="VERBOSE=1 -j2"
107107
108108
python3 setup.py bdist_wheel
109109
ls -lh dist

README.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
### Supported functions
22

3-
|Speech recognition| Speech synthesis | Source separation |
3+
|Speech recognition| [Speech synthesis][tts-url] | [Source separation][ss-url] |
44
|------------------|------------------|-------------------|
55
| ✔️ | ✔️ | ✔️ |
66

7-
|Speaker identification| Speaker diarization | Speaker verification |
7+
|Speaker identification| [Speaker diarization][sd-url] | Speaker verification |
88
|----------------------|-------------------- |------------------------|
99
| ✔️ | ✔️ | ✔️ |
1010

11-
| Spoken Language identification | Audio tagging | Voice activity detection |
11+
| [Spoken Language identification][slid-url] | [Audio tagging][at-url] | [Voice activity detection][vad-url] |
1212
|--------------------------------|---------------|--------------------------|
1313
| ✔️ | ✔️ | ✔️ |
1414

15-
| Keyword spotting | Add punctuation | Speech enhancement |
15+
| [Keyword spotting][kws-url] | [Add punctuation][punct-url] | [Speech enhancement][se-url] |
1616
|------------------|-----------------|--------------------|
1717
| ✔️ | ✔️ | ✔️ |
1818

@@ -501,3 +501,12 @@ It uses sherpa-onnx for speech-to-text and text-to-speech.
501501
[spleeter]: https://github.com/deezer/spleeter
502502
[UVR]: https://github.com/Anjok07/ultimatevocalremovergui
503503
[gtcrn]: https://github.com/Xiaobin-Rong/gtcrn
504+
[tts-url]: https://k2-fsa.github.io/sherpa/onnx/tts/all-in-one.html
505+
[ss-url]: https://k2-fsa.github.io/sherpa/onnx/source-separation/index.html
506+
[sd-url]: https://k2-fsa.github.io/sherpa/onnx/speaker-diarization/index.html
507+
[slid-url]: https://k2-fsa.github.io/sherpa/onnx/spoken-language-identification/index.html
508+
[at-url]: https://k2-fsa.github.io/sherpa/onnx/audio-tagging/index.html
509+
[vad-url]: https://k2-fsa.github.io/sherpa/onnx/vad/index.html
510+
[kws-url]: https://k2-fsa.github.io/sherpa/onnx/kws/index.html
511+
[punct-url]: https://k2-fsa.github.io/sherpa/onnx/punctuation/index.html
512+
[se-url]: https://k2-fsa.github.io/sherpa/onnx/speech-enhancment/index.html

flutter/sherpa_onnx/lib/src/sherpa_onnx_bindings.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ final class SherpaOnnxOfflineTtsKokoroModelConfig extends Struct {
201201
external double lengthScale;
202202
external Pointer<Utf8> dictDir;
203203
external Pointer<Utf8> lexicon;
204+
external Pointer<Utf8> lang;
204205
}
205206

206207
final class SherpaOnnxOfflineTtsModelConfig extends Struct {

flutter/sherpa_onnx/lib/src/tts.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ class OfflineTtsKokoroModelConfig {
117117
this.lengthScale = 1.0,
118118
this.dictDir = '',
119119
this.lexicon = '',
120+
this.lang = '',
120121
});
121122

122123
factory OfflineTtsKokoroModelConfig.fromJson(Map<String, dynamic> json) {
@@ -128,12 +129,13 @@ class OfflineTtsKokoroModelConfig {
128129
lengthScale: (json['lengthScale'] as num?)?.toDouble() ?? 1.0,
129130
dictDir: json['dictDir'] as String? ?? '',
130131
lexicon: json['lexicon'] as String? ?? '',
132+
lang: json['lang'] as String? ?? '',
131133
);
132134
}
133135

134136
@override
135137
String toString() {
136-
return 'OfflineTtsKokoroModelConfig(model: $model, voices: $voices, tokens: $tokens, dataDir: $dataDir, lengthScale: $lengthScale, dictDir: $dictDir, lexicon: $lexicon)';
138+
return 'OfflineTtsKokoroModelConfig(model: $model, voices: $voices, tokens: $tokens, dataDir: $dataDir, lengthScale: $lengthScale, dictDir: $dictDir, lexicon: $lexicon, lang: $lang)';
137139
}
138140

139141
Map<String, dynamic> toJson() => {
@@ -144,6 +146,7 @@ class OfflineTtsKokoroModelConfig {
144146
'lengthScale': lengthScale,
145147
'dictDir': dictDir,
146148
'lexicon': lexicon,
149+
'lang': lang,
147150
};
148151

149152
final String model;
@@ -153,6 +156,7 @@ class OfflineTtsKokoroModelConfig {
153156
final double lengthScale;
154157
final String dictDir;
155158
final String lexicon;
159+
final String lang;
156160
}
157161

158162
class OfflineTtsModelConfig {
@@ -286,6 +290,7 @@ class OfflineTts {
286290
c.ref.model.kokoro.lengthScale = config.model.kokoro.lengthScale;
287291
c.ref.model.kokoro.dictDir = config.model.kokoro.dictDir.toNativeUtf8();
288292
c.ref.model.kokoro.lexicon = config.model.kokoro.lexicon.toNativeUtf8();
293+
c.ref.model.kokoro.lang = config.model.kokoro.lang.toNativeUtf8();
289294

290295
c.ref.model.numThreads = config.model.numThreads;
291296
c.ref.model.debug = config.model.debug ? 1 : 0;
@@ -302,6 +307,7 @@ class OfflineTts {
302307
calloc.free(c.ref.ruleFsts);
303308
calloc.free(c.ref.model.provider);
304309

310+
calloc.free(c.ref.model.kokoro.lang);
305311
calloc.free(c.ref.model.kokoro.lexicon);
306312
calloc.free(c.ref.model.kokoro.dictDir);
307313
calloc.free(c.ref.model.kokoro.dataDir);

harmony-os/SherpaOnnxHar/sherpa_onnx/src/main/cpp/non-streaming-tts.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ static SherpaOnnxOfflineTtsKokoroModelConfig GetOfflineTtsKokoroModelConfig(
7070
SHERPA_ONNX_ASSIGN_ATTR_FLOAT(length_scale, lengthScale);
7171
SHERPA_ONNX_ASSIGN_ATTR_STR(dict_dir, dictDir);
7272
SHERPA_ONNX_ASSIGN_ATTR_STR(lexicon, lexicon);
73+
SHERPA_ONNX_ASSIGN_ATTR_STR(lang, lang);
7374

7475
return c;
7576
}
@@ -177,6 +178,7 @@ static Napi::External<SherpaOnnxOfflineTts> CreateOfflineTtsWrapper(
177178
SHERPA_ONNX_DELETE_C_STR(c.model.kokoro.data_dir);
178179
SHERPA_ONNX_DELETE_C_STR(c.model.kokoro.dict_dir);
179180
SHERPA_ONNX_DELETE_C_STR(c.model.kokoro.lexicon);
181+
SHERPA_ONNX_DELETE_C_STR(c.model.kokoro.lang);
180182

181183
SHERPA_ONNX_DELETE_C_STR(c.model.provider);
182184

harmony-os/SherpaOnnxHar/sherpa_onnx/src/main/ets/components/NonStreamingTts.ets

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export class OfflineTtsKokoroModelConfig {
3636
public lengthScale: number = 1.0;
3737
public dictDir: string = '';
3838
public lexicon: string = '';
39+
public lang: string = '';
3940
}
4041

4142
export class OfflineTtsModelConfig {

scripts/dotnet/OfflineTtsKokoroModelConfig.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public OfflineTtsKokoroModelConfig()
1818

1919
DictDir = "";
2020
Lexicon = "";
21+
Lang = "";
2122
}
2223
[MarshalAs(UnmanagedType.LPStr)]
2324
public string Model;
@@ -38,5 +39,8 @@ public OfflineTtsKokoroModelConfig()
3839

3940
[MarshalAs(UnmanagedType.LPStr)]
4041
public string Lexicon;
42+
43+
[MarshalAs(UnmanagedType.LPStr)]
44+
public string Lang;
4145
}
4246
}

scripts/go/sherpa_onnx.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,7 @@ type OfflineTtsKokoroModelConfig struct {
857857
DataDir string // Path to espeak-ng-data directory
858858
DictDir string // Path to dict directory
859859
Lexicon string // Path to lexicon files
860+
Lang string // Example: es for Spanish, fr-fr for French. Can be empty
860861
LengthScale float32 // Please use 1.0 in general. Smaller -> Faster speech speed. Larger -> Slower speech speed
861862
}
862863

@@ -1006,6 +1007,9 @@ func NewOfflineTts(config *OfflineTtsConfig) *OfflineTts {
10061007
c.model.kokoro.lexicon = C.CString(config.Model.Kokoro.Lexicon)
10071008
defer C.free(unsafe.Pointer(c.model.kokoro.lexicon))
10081009

1010+
c.model.kokoro.lang = C.CString(config.Model.Kokoro.Lang)
1011+
defer C.free(unsafe.Pointer(c.model.kokoro.lang))
1012+
10091013
c.model.kokoro.length_scale = C.float(config.Model.Kokoro.LengthScale)
10101014

10111015
c.model.num_threads = C.int(config.Model.NumThreads)

sherpa-onnx/c-api/c-api.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,6 +1164,7 @@ static sherpa_onnx::OfflineTtsConfig GetOfflineTtsConfig(
11641164
SHERPA_ONNX_OR(config->model.kokoro.dict_dir, "");
11651165
tts_config.model.kokoro.lexicon =
11661166
SHERPA_ONNX_OR(config->model.kokoro.lexicon, "");
1167+
tts_config.model.kokoro.lang = SHERPA_ONNX_OR(config->model.kokoro.lang, "");
11671168

11681169
tts_config.model.num_threads = SHERPA_ONNX_OR(config->model.num_threads, 1);
11691170
tts_config.model.debug = config->model.debug;

sherpa-onnx/c-api/c-api.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -958,6 +958,7 @@ SHERPA_ONNX_API typedef struct SherpaOnnxOfflineTtsKokoroModelConfig {
958958
float length_scale; // < 1, faster in speech speed; > 1, slower in speed
959959
const char *dict_dir;
960960
const char *lexicon;
961+
const char *lang;
961962
} SherpaOnnxOfflineTtsKokoroModelConfig;
962963

963964
SHERPA_ONNX_API typedef struct SherpaOnnxOfflineTtsModelConfig {

0 commit comments

Comments
 (0)