Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions c-api-examples/kokoro-tts-en-c-api.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ rm kokoro-en-v0_19.tar.bz2
#include "sherpa-onnx/c-api/c-api.h"

static int32_t ProgressCallback(const float *samples, int32_t num_samples,
float progress) {
float progress, void *arg) {
fprintf(stderr, "Progress: %.3f%%\n", progress * 100);
// return 1 to continue generating
// return 0 to stop generating
Expand Down Expand Up @@ -60,15 +60,19 @@ int32_t main(int32_t argc, char *argv[]) {
// 6->am_michael, 7->bf_emma, 8->bf_isabella, 9->bm_george, 10->bm_lewis
int32_t sid = 0;
float speed = 1.0; // larger -> faster in speech speed
SherpaOnnxGenerationConfig cfg = {0};
cfg.silence_scale = 0.2f;
cfg.sid = sid;
cfg.speed = speed;
Comment on lines +63 to +66

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The initialization of SherpaOnnxGenerationConfig can be made more concise and readable by using C99 designated initializers. This avoids initializing the struct to zero and then assigning members individually.

Suggested change
SherpaOnnxGenerationConfig cfg = {0};
cfg.silence_scale = 0.2f;
cfg.sid = sid;
cfg.speed = speed;
SherpaOnnxGenerationConfig cfg = {.silence_scale = 0.2f, .sid = sid, .speed = speed};


#if 0
// If you don't want to use a callback, then please enable this branch
const SherpaOnnxGeneratedAudio *audio =
SherpaOnnxOfflineTtsGenerate(tts, text, sid, speed);
SherpaOnnxOfflineTtsGenerateWithConfig(tts, text, &cfg, NULL, NULL);
#else
const SherpaOnnxGeneratedAudio *audio =
SherpaOnnxOfflineTtsGenerateWithProgressCallback(tts, text, sid, speed,
ProgressCallback);
SherpaOnnxOfflineTtsGenerateWithConfig(tts, text, &cfg, ProgressCallback,
NULL);
#endif

SherpaOnnxWriteWave(audio->samples, audio->n, audio->sample_rate, filename);
Expand Down
12 changes: 8 additions & 4 deletions c-api-examples/kokoro-tts-zh-en-c-api.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ rm kokoro-multi-lang-v1_0.tar.bz2
#include "sherpa-onnx/c-api/c-api.h"

static int32_t ProgressCallback(const float *samples, int32_t num_samples,
float progress) {
float progress, void *arg) {
fprintf(stderr, "Progress: %.3f%%\n", progress * 100);
// return 1 to continue generating
// return 0 to stop generating
Expand Down Expand Up @@ -58,15 +58,19 @@ int32_t main(int32_t argc, char *argv[]) {
const SherpaOnnxOfflineTts *tts = SherpaOnnxCreateOfflineTts(&config);
int32_t sid = 0; // there are 53 speakers
float speed = 1.0; // larger -> faster in speech speed
SherpaOnnxGenerationConfig cfg = {0};
cfg.silence_scale = 0.2f;
cfg.sid = sid;
cfg.speed = speed;
Comment on lines +61 to +64

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The initialization of SherpaOnnxGenerationConfig can be made more concise and readable by using C99 designated initializers. This avoids initializing the struct to zero and then assigning members individually.

Suggested change
SherpaOnnxGenerationConfig cfg = {0};
cfg.silence_scale = 0.2f;
cfg.sid = sid;
cfg.speed = speed;
SherpaOnnxGenerationConfig cfg = {.silence_scale = 0.2f, .sid = sid, .speed = speed};


#if 0
// If you don't want to use a callback, then please enable this branch
const SherpaOnnxGeneratedAudio *audio =
SherpaOnnxOfflineTtsGenerate(tts, text, sid, speed);
SherpaOnnxOfflineTtsGenerateWithConfig(tts, text, &cfg, NULL, NULL);
#else
const SherpaOnnxGeneratedAudio *audio =
SherpaOnnxOfflineTtsGenerateWithProgressCallback(tts, text, sid, speed,
ProgressCallback);
SherpaOnnxOfflineTtsGenerateWithConfig(tts, text, &cfg, ProgressCallback,
NULL);
#endif

SherpaOnnxWriteWave(audio->samples, audio->n, audio->sample_rate, filename);
Expand Down
8 changes: 6 additions & 2 deletions cxx-api-examples/kokoro-tts-en-cxx-api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,16 @@ int32_t main(int32_t argc, char *argv[]) {
auto tts = OfflineTts::Create(config);
int32_t sid = 0;
float speed = 1.0; // larger -> faster in speech speed
GenerationConfig gen_config;
gen_config.sid = sid;
gen_config.speed = speed;
gen_config.silence_scale = 0.2f;
Comment on lines 58 to +63

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The sid and speed variables are only used to initialize gen_config and are then discarded. You can make the code more direct by removing these intermediate variables and assigning the values directly to the gen_config members.

Suggested change
int32_t sid = 0;
float speed = 1.0; // larger -> faster in speech speed
GenerationConfig gen_config;
gen_config.sid = sid;
gen_config.speed = speed;
gen_config.silence_scale = 0.2f;
GenerationConfig gen_config;
gen_config.sid = 0;
gen_config.speed = 1.0; // larger -> faster in speech speed
gen_config.silence_scale = 0.2f;


#if 0
// If you don't want to use a callback, then please enable this branch
GeneratedAudio audio = tts.Generate(text, sid, speed);
GeneratedAudio audio = tts.Generate(text, gen_config);
#else
GeneratedAudio audio = tts.Generate(text, sid, speed, ProgressCallback);
GeneratedAudio audio = tts.Generate(text, gen_config, ProgressCallback);
#endif

WriteWave(filename, {audio.samples, audio.sample_rate});
Expand Down
8 changes: 6 additions & 2 deletions cxx-api-examples/kokoro-tts-zh-en-cxx-api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,16 @@ int32_t main(int32_t argc, char *argv[]) {
auto tts = OfflineTts::Create(config);
int32_t sid = 50;
float speed = 1.0; // larger -> faster in speech speed
GenerationConfig gen_config;
gen_config.sid = sid;
gen_config.speed = speed;
gen_config.silence_scale = 0.2f;
Comment on lines 59 to +64

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The sid and speed variables are only used to initialize gen_config and are then discarded. You can make the code more direct by removing these intermediate variables and assigning the values directly to the gen_config members.

Suggested change
int32_t sid = 50;
float speed = 1.0; // larger -> faster in speech speed
GenerationConfig gen_config;
gen_config.sid = sid;
gen_config.speed = speed;
gen_config.silence_scale = 0.2f;
GenerationConfig gen_config;
gen_config.sid = 50;
gen_config.speed = 1.0; // larger -> faster in speech speed
gen_config.silence_scale = 0.2f;


#if 0
// If you don't want to use a callback, then please enable this branch
GeneratedAudio audio = tts.Generate(text, sid, speed);
GeneratedAudio audio = tts.Generate(text, gen_config);
#else
GeneratedAudio audio = tts.Generate(text, sid, speed, ProgressCallback);
GeneratedAudio audio = tts.Generate(text, gen_config, ProgressCallback);
#endif

WriteWave(filename, {audio.samples, audio.sample_rate});
Expand Down
8 changes: 6 additions & 2 deletions dart-api-examples/tts/bin/kokoro-en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ void main(List<String> arguments) async {
voices: voices,
tokens: tokens,
dataDir: dataDir,
lengthScale: 1 / speed,
);

final modelConfig = sherpa_onnx.OfflineTtsModelConfig(
Expand All @@ -74,7 +73,12 @@ void main(List<String> arguments) async {
);

final tts = sherpa_onnx.OfflineTts(config);
final audio = tts.generate(text: text, sid: sid, speed: speed);
final genConfig = sherpa_onnx.OfflineTtsGenerationConfig(
sid: sid,
speed: speed,
silenceScale: config.silenceScale,
);
final audio = tts.generateWithConfig(text: text, config: genConfig);
tts.free();

sherpa_onnx.writeWave(
Expand Down
8 changes: 6 additions & 2 deletions dart-api-examples/tts/bin/kokoro-zh-en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ void main(List<String> arguments) async {
voices: voices,
tokens: tokens,
dataDir: dataDir,
lengthScale: 1 / speed,
lexicon: lexicon,
);

Expand All @@ -82,7 +81,12 @@ void main(List<String> arguments) async {
);

final tts = sherpa_onnx.OfflineTts(config);
final audio = tts.generate(text: text, sid: sid, speed: speed);
final genConfig = sherpa_onnx.OfflineTtsGenerationConfig(
sid: sid,
speed: speed,
silenceScale: config.silenceScale,
);
final audio = tts.generateWithConfig(text: text, config: genConfig);
tts.free();

sherpa_onnx.writeWave(
Expand Down
18 changes: 11 additions & 7 deletions dotnet-examples/kokoro-tts-play/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,13 @@ static void Main(string[] args)
"thing in the world was to lose touch with someone.";

// mapping of sid to voice name
// 0->af, 1->af_bella, 2->af_nicole, 3->af_sarah, 4->af_sky, 5->am_adam
// 6->am_michael, 7->bf_emma, 8->bf_isabella, 9->bm_george, 10->bm_lewis
var sid = 0;
// 0->af, 1->af_bella, 2->af_nicole, 3->af_sarah, 4->af_sky, 5->am_adam
// 6->am_michael, 7->bf_emma, 8->bf_isabella, 9->bm_george, 10->bm_lewis
var sid = 0;
OfflineTtsGenerationConfig genConfig = new OfflineTtsGenerationConfig();
genConfig.Sid = sid;
genConfig.Speed = speed;
Comment on lines +41 to +43

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For more concise and idiomatic C# code, you can use an object initializer to set the properties of OfflineTtsGenerationConfig upon instantiation.

    var genConfig = new OfflineTtsGenerationConfig { Sid = sid, Speed = speed };

genConfig.SilenceScale = 0.2f;


Console.WriteLine(PortAudio.VersionInfo.versionText);
Expand Down Expand Up @@ -73,7 +77,7 @@ static void Main(string[] args)
// https://learn.microsoft.com/en-us/dotnet/standard/collections/thread-safe/blockingcollection-overview
var dataItems = new BlockingCollection<float[]>();

var MyCallback = (IntPtr samples, int n, float progress) =>
var MyCallback = (IntPtr samples, int n, float progress, IntPtr arg) =>
{
Console.WriteLine($"Progress {progress*100}%");

Expand Down Expand Up @@ -165,9 +169,9 @@ IntPtr userData

stream.Start();

var callback = new OfflineTtsCallbackProgress(MyCallback);
var audio = tts.GenerateWithCallbackProgress(text, speed, sid, callback);
var callback = new OfflineTtsCallbackProgressWithArg(MyCallback);

var audio = tts.GenerateWithConfig(text, genConfig, callback);
var outputFilename = "./generated-kokoro-0.wav";
var ok = audio.SaveToWaveFile(outputFilename);

Expand Down
26 changes: 18 additions & 8 deletions dotnet-examples/kokoro-tts/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ static void TestZhEn()

var sid = 50;

var MyCallback = (IntPtr samples, int n, float progress) =>
OfflineTtsGenerationConfig genConfig = new OfflineTtsGenerationConfig();
genConfig.Sid = sid;
genConfig.Speed = speed;
Comment on lines +41 to +43

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For more concise and idiomatic C# code, you can use an object initializer to set the properties of OfflineTtsGenerationConfig upon instantiation.

    OfflineTtsGenerationConfig genConfig = new OfflineTtsGenerationConfig { Sid = sid, Speed = speed };

genConfig.SilenceScale = 0.2f;

var MyCallback = (IntPtr samples, int n, float progress, IntPtr arg) =>
{
float[] data = new float[n];
Marshal.Copy(samples, data, 0, n);
Expand All @@ -51,9 +56,9 @@ static void TestZhEn()
return 1;
};

var callback = new OfflineTtsCallbackProgress(MyCallback);
var audio = tts.GenerateWithCallbackProgress(text, speed, sid, callback);
var callback = new OfflineTtsCallbackProgressWithArg(MyCallback);

var audio = tts.GenerateWithConfig(text, genConfig, callback);

var outputFilename = "./generated-kokoro-zh-en.wav";
var ok = audio.SaveToWaveFile(outputFilename);
Expand Down Expand Up @@ -93,7 +98,12 @@ static void TestEn()
// 6->am_michael, 7->bf_emma, 8->bf_isabella, 9->bm_george, 10->bm_lewis
var sid = 0;

var MyCallback = (IntPtr samples, int n, float progress) =>
OfflineTtsGenerationConfig genConfig = new OfflineTtsGenerationConfig();
genConfig.Sid = sid;
genConfig.Speed = speed;
Comment on lines +101 to +103

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For more concise and idiomatic C# code, you can use an object initializer to set the properties of OfflineTtsGenerationConfig upon instantiation.

    OfflineTtsGenerationConfig genConfig = new OfflineTtsGenerationConfig { Sid = sid, Speed = speed };

genConfig.SilenceScale = 0.2f;

var MyCallback = (IntPtr samples, int n, float progress, IntPtr arg) =>
{
float[] data = new float[n];
Marshal.Copy(samples, data, 0, n);
Expand All @@ -106,9 +116,9 @@ static void TestEn()
return 1;
};

var callback = new OfflineTtsCallbackProgress(MyCallback);
var audio = tts.GenerateWithCallbackProgress(text, speed, sid, callback);
var callback = new OfflineTtsCallbackProgressWithArg(MyCallback);

var audio = tts.GenerateWithConfig(text, genConfig, callback);

var outputFilename = "./generated-kokoro-en.wav";
var ok = audio.SaveToWaveFile(outputFilename);
Expand Down
6 changes: 5 additions & 1 deletion java-api-examples/NonStreamingTtsKokoroEn.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,12 @@ public static void main(String[] args) {

int sid = 0;
float speed = 1.0f;
GenerationConfig genConfig = new GenerationConfig();
genConfig.setSid(sid);
genConfig.setSpeed(speed);
genConfig.setSilenceScale(0.2f);
Comment on lines 39 to +44

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The sid and speed variables are only used for initializing genConfig. You can simplify the code by removing these variables and setting the values directly.

Suggested change
int sid = 0;
float speed = 1.0f;
GenerationConfig genConfig = new GenerationConfig();
genConfig.setSid(sid);
genConfig.setSpeed(speed);
genConfig.setSilenceScale(0.2f);
GenerationConfig genConfig = new GenerationConfig();
genConfig.setSid(0);
genConfig.setSpeed(1.0f);
genConfig.setSilenceScale(0.2f);

long start = System.currentTimeMillis();
GeneratedAudio audio = tts.generate(text, sid, speed);
GeneratedAudio audio = tts.generateWithConfigAndCallback(text, genConfig, samples -> {});
long stop = System.currentTimeMillis();

float timeElapsedSeconds = (stop - start) / 1000.0f;
Expand Down
6 changes: 5 additions & 1 deletion java-api-examples/NonStreamingTtsKokoroZhEn.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ public static void main(String[] args) {

int sid = 0; // this model has 53 speakers. You can use sid in the range 0-52
float speed = 1.0f;
GenerationConfig genConfig = new GenerationConfig();
genConfig.setSid(sid);
genConfig.setSpeed(speed);
genConfig.setSilenceScale(0.2f);
Comment on lines 41 to +46

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The sid and speed variables are only used for initializing genConfig. You can simplify the code by removing these variables and setting the values directly. The comment for sid can be moved to clarify the direct assignment.

Suggested change
int sid = 0; // this model has 53 speakers. You can use sid in the range 0-52
float speed = 1.0f;
GenerationConfig genConfig = new GenerationConfig();
genConfig.setSid(sid);
genConfig.setSpeed(speed);
genConfig.setSilenceScale(0.2f);
// this model has 53 speakers. You can use sid in the range 0-52
GenerationConfig genConfig = new GenerationConfig();
genConfig.setSid(0);
genConfig.setSpeed(1.0f);
genConfig.setSilenceScale(0.2f);

long start = System.currentTimeMillis();
GeneratedAudio audio = tts.generate(text, sid, speed);
GeneratedAudio audio = tts.generateWithConfigAndCallback(text, genConfig, samples -> {});
long stop = System.currentTimeMillis();

float timeElapsedSeconds = (stop - start) / 1000.0f;
Expand Down
8 changes: 7 additions & 1 deletion nodejs-addon-examples/test_tts_non_streaming_kokoro_en.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,15 @@ const tts = createOfflineTts();
const text =
'Today as always, men fall into two groups: slaves and free men. Whoever does not have two-thirds of his day for himself, is a slave, whatever he may be: a statesman, a businessman, an official, or a scholar.';

const generationConfig = new sherpa_onnx.GenerationConfig({
sid: 6,
speed: 1.0,
silenceScale: 0.2,
});


let start = Date.now();
const audio = tts.generate({text: text, sid: 6, speed: 1.0});
const audio = tts.generate({text, generationConfig});
let stop = Date.now();
const elapsed_seconds = (stop - start) / 1000;
const duration = audio.samples.length / audio.sampleRate;
Expand Down
8 changes: 7 additions & 1 deletion nodejs-addon-examples/test_tts_non_streaming_kokoro_zh_en.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,14 @@ const tts = createOfflineTts();
const text =
'中英文语音合成测试。This is generated by next generation Kaldi using Kokoro without Misaki. 你觉得中英文说的如何呢?';

const generationConfig = new sherpa_onnx.GenerationConfig({
sid: 48,
speed: 1.0,
silenceScale: 0.2,
});

let start = Date.now();
const audio = tts.generate({text: text, sid: 48, speed: 1.0});
const audio = tts.generate({text, generationConfig});
let stop = Date.now();
const elapsed_seconds = (stop - start) / 1000;
const duration = audio.samples.length / audio.sampleRate;
Expand Down
7 changes: 6 additions & 1 deletion nodejs-examples/test-offline-tts-kokoro-en.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,15 @@ function createOfflineTts() {
const tts = createOfflineTts();
const speakerId = 0;
const speed = 1.0;
const generationConfig = {
sid: speakerId,
speed: speed,
silenceScale: 0.2,
};
Comment on lines +31 to +35

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

You can use ES6 property value shorthand for speed to make the object initialization more concise.

Suggested change
const generationConfig = {
sid: speakerId,
speed: speed,
silenceScale: 0.2,
};
const generationConfig = {
sid: speakerId,
speed,
silenceScale: 0.2,
};

const text =
'Today as always, men fall into two groups: slaves and free men. Whoever does not have two-thirds of his day for himself, is a slave, whatever he may be: a statesman, a businessman, an official, or a scholar.';

const audio = tts.generate({text: text, sid: speakerId, speed: speed});
const audio = tts.generateWithConfig(text, generationConfig);
tts.save('./test-kokoro-en.wav', audio);
console.log('Saved to test-kokoro-en.wav successfully.');
tts.free();
7 changes: 6 additions & 1 deletion nodejs-examples/test-offline-tts-kokoro-zh-en.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,15 @@ function createOfflineTts() {
const tts = createOfflineTts();
const speakerId = 49;
const speed = 1.0;
const generationConfig = {
sid: speakerId,
speed: speed,
silenceScale: 0.2,
};
Comment on lines +33 to +37

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

You can use ES6 property value shorthand for speed to make the object initialization more concise.

Suggested change
const generationConfig = {
sid: speakerId,
speed: speed,
silenceScale: 0.2,
};
const generationConfig = {
sid: speakerId,
speed,
silenceScale: 0.2,
};

const text =
'中英文语音合成测试。This is generated by next generation Kaldi using Kokoro without Misaki. 你觉得中英文说的如何呢?';

const audio = tts.generate({text: text, sid: speakerId, speed: speed});
const audio = tts.generateWithConfig(text, generationConfig);
tts.save('./test-kokoro-zh-en-49.wav', audio);
console.log('Saved to test-kokoro-zh-en-49.wav successfully.');
tts.free();
13 changes: 9 additions & 4 deletions pascal-api-examples/tts/kokoro-en-playback.pas
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@
Param: TPaStreamParameters;
Stream: PPaStream;
Wave: TSherpaOnnxWave;
GenerationConfig: TSherpaOnnxGenerationConfig;

function GenerateCallback(
Samples: pcfloat; N: cint32;
Arg: Pointer): cint; cdecl;
Progress: cfloat; Arg: Pointer): cint; cdecl;
begin
EnterCriticalSection(CriticalSection);
try
Expand Down Expand Up @@ -207,8 +208,13 @@ function GetOfflineTts: TSherpaOnnxOfflineTts;

Text := 'Friends fell out often because life was changing so fast. The easiest thing in the world was to lose touch with someone.';

Audio := Tts.Generate(Text, SpeakerId, Speed,
PSherpaOnnxGeneratedAudioCallbackWithArg(@GenerateCallback), nil);
GenerationConfig := Default(TSherpaOnnxGenerationConfig);
GenerationConfig.SilenceScale := 0.2;
GenerationConfig.Speed := Speed;
GenerationConfig.Sid := SpeakerId;

Audio := Tts.Generate(Text, GenerationConfig,
@GenerateCallback, nil);
FinishedGeneration := True;
SherpaOnnxWriteWave('./kokoro-en-playback-7.wav', Audio.Samples, Audio.SampleRate);
WriteLn('Saved to ./kokoro-en-playback-7.wav');
Expand Down Expand Up @@ -236,4 +242,3 @@ function GetOfflineTts: TSherpaOnnxOfflineTts;
Exit;
end;
end.

9 changes: 7 additions & 2 deletions pascal-api-examples/tts/kokoro-en.pas
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ function GetOfflineTts: TSherpaOnnxOfflineTts;
var
Tts: TSherpaOnnxOfflineTts;
Audio: TSherpaOnnxGeneratedAudio;
GenerationConfig: TSherpaOnnxGenerationConfig;

Text: AnsiString;
Speed: Single = 1.0; {Use a larger value to speak faster}
Expand All @@ -46,10 +47,14 @@ function GetOfflineTts: TSherpaOnnxOfflineTts;

Text := 'Friends fell out often because life was changing so fast. The easiest thing in the world was to lose touch with someone.';

Audio := Tts.Generate(Text, SpeakerId, Speed);
GenerationConfig := Default(TSherpaOnnxGenerationConfig);
GenerationConfig.SilenceScale := 0.2;
GenerationConfig.Speed := Speed;
GenerationConfig.Sid := SpeakerId;

Audio := Tts.Generate(Text, GenerationConfig, NIL, NIL);
SherpaOnnxWriteWave('./kokoro-en-8.wav', Audio.Samples, Audio.SampleRate);
WriteLn('Saved to ./kokoro-en-8.wav');

FreeAndNil(Tts);
end.

Loading
Loading