-
Notifications
You must be signed in to change notification settings - Fork 463
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
740d7ae
commit 031134b
Showing
21 changed files
with
691 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -94,7 +94,7 @@ jobs: | |
-DSHERPA_ONNX_ENABLE_BINARY=OFF \ | ||
.. | ||
make -j | ||
make -j2 | ||
make install | ||
cd .. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -105,3 +105,4 @@ sherpa-onnx-ced-* | |
node_modules | ||
package-lock.json | ||
sherpa-onnx-nemo-* | ||
sherpa-onnx-vits-* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
nodejs-addon-examples/test_tts_non_streaming_vits_coqui_de.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright (c) 2024 Xiaomi Corporation | ||
const sherpa_onnx = require('sherpa-onnx-node'); | ||
const performance = require('perf_hooks').performance; | ||
|
||
// please download model files from | ||
// https://github.com/k2-fsa/sherpa-onnx/releases/tag/tts-models | ||
function createOfflineTts() { | ||
const config = { | ||
model: { | ||
vits: { | ||
model: './vits-coqui-de-css10/model.onnx', | ||
tokens: './vits-coqui-de-css10/tokens.txt', | ||
}, | ||
debug: true, | ||
numThreads: 1, | ||
provider: 'cpu', | ||
}, | ||
maxNumStences: 1, | ||
}; | ||
return new sherpa_onnx.OfflineTts(config); | ||
} | ||
|
||
const tts = createOfflineTts(); | ||
|
||
const text = 'Alles hat ein Ende, nur die Wurst hat zwei.' | ||
|
||
let start = performance.now(); | ||
const audio = tts.generate({text: text, sid: 0, speed: 1.0}); | ||
let stop = performance.now(); | ||
const elapsed_seconds = (stop - start) / 1000; | ||
const duration = audio.samples.length / audio.sampleRate; | ||
const real_time_factor = elapsed_seconds / duration; | ||
console.log('Wave duration', duration.toFixed(3), 'secodns') | ||
console.log('Elapsed', elapsed_seconds.toFixed(3), 'secodns') | ||
console.log( | ||
`RTF = ${elapsed_seconds.toFixed(3)}/${duration.toFixed(3)} =`, | ||
real_time_factor.toFixed(3)) | ||
|
||
const filename = 'test-coqui-de.wav'; | ||
sherpa_onnx.writeWave( | ||
filename, {samples: audio.samples, sampleRate: audio.sampleRate}); | ||
|
||
console.log(`Saved to ${filename}`); |
46 changes: 46 additions & 0 deletions
46
nodejs-addon-examples/test_tts_non_streaming_vits_piper_en.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright (c) 2024 Xiaomi Corporation | ||
const sherpa_onnx = require('sherpa-onnx-node'); | ||
const performance = require('perf_hooks').performance; | ||
|
||
// please download model files from | ||
// https://github.com/k2-fsa/sherpa-onnx/releases/tag/tts-models | ||
function createOfflineTts() { | ||
const config = { | ||
model: { | ||
vits: { | ||
model: './vits-piper-en_GB-cori-medium/en_GB-cori-medium.onnx', | ||
tokens: './vits-piper-en_GB-cori-medium/tokens.txt', | ||
dataDir: './vits-piper-en_GB-cori-medium/espeak-ng-data', | ||
}, | ||
debug: true, | ||
numThreads: 1, | ||
provider: 'cpu', | ||
}, | ||
maxNumStences: 1, | ||
}; | ||
return new sherpa_onnx.OfflineTts(config); | ||
} | ||
|
||
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.' | ||
|
||
|
||
let start = performance.now(); | ||
const audio = tts.generate({text: text, sid: 0, speed: 1.0}); | ||
let stop = performance.now(); | ||
const elapsed_seconds = (stop - start) / 1000; | ||
const duration = audio.samples.length / audio.sampleRate; | ||
const real_time_factor = elapsed_seconds / duration; | ||
console.log('Wave duration', duration.toFixed(3), 'secodns') | ||
console.log('Elapsed', elapsed_seconds.toFixed(3), 'secodns') | ||
console.log( | ||
`RTF = ${elapsed_seconds.toFixed(3)}/${duration.toFixed(3)} =`, | ||
real_time_factor.toFixed(3)) | ||
|
||
const filename = 'test-piper-en.wav'; | ||
sherpa_onnx.writeWave( | ||
filename, {samples: audio.samples, sampleRate: audio.sampleRate}); | ||
|
||
console.log(`Saved to ${filename}`); |
48 changes: 48 additions & 0 deletions
48
nodejs-addon-examples/test_tts_non_streaming_vits_zh_aishell3.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright (c) 2024 Xiaomi Corporation | ||
const sherpa_onnx = require('sherpa-onnx-node'); | ||
const performance = require('perf_hooks').performance; | ||
|
||
// please download model files from | ||
// https://github.com/k2-fsa/sherpa-onnx/releases/tag/tts-models | ||
function createOfflineTts() { | ||
const config = { | ||
model: { | ||
vits: { | ||
model: './vits-icefall-zh-aishell3/model.onnx', | ||
tokens: './vits-icefall-zh-aishell3/tokens.txt', | ||
lexicon: './vits-icefall-zh-aishell3/lexicon.txt', | ||
}, | ||
debug: true, | ||
numThreads: 1, | ||
provider: 'cpu', | ||
}, | ||
maxNumStences: 1, | ||
ruleFsts: | ||
'./vits-icefall-zh-aishell3/date.fst,./vits-icefall-zh-aishell3/phone.fst,./vits-icefall-zh-aishell3/number.fst,./vits-icefall-zh-aishell3/new_heteronym.fst', | ||
ruleFars: './vits-icefall-zh-aishell3/rule.far', | ||
}; | ||
return new sherpa_onnx.OfflineTts(config); | ||
} | ||
|
||
const tts = createOfflineTts(); | ||
|
||
const text = | ||
'他在长沙出生,长白山长大,去过长江,现在他是一个银行的行长,主管行政工作。有困难,请拨110,或者13020240513。今天是2024年5月13号, 他上个月的工资是12345块钱。' | ||
|
||
let start = performance.now(); | ||
const audio = tts.generate({text: text, sid: 88, speed: 1.0}); | ||
let stop = performance.now(); | ||
const elapsed_seconds = (stop - start) / 1000; | ||
const duration = audio.samples.length / audio.sampleRate; | ||
const real_time_factor = elapsed_seconds / duration; | ||
console.log('Wave duration', duration.toFixed(3), 'secodns') | ||
console.log('Elapsed', elapsed_seconds.toFixed(3), 'secodns') | ||
console.log( | ||
`RTF = ${elapsed_seconds.toFixed(3)}/${duration.toFixed(3)} =`, | ||
real_time_factor.toFixed(3)) | ||
|
||
const filename = 'test-zh-aishell3.wav'; | ||
sherpa_onnx.writeWave( | ||
filename, {samples: audio.samples, sampleRate: audio.sampleRate}); | ||
|
||
console.log(`Saved to ${filename}`); |
48 changes: 48 additions & 0 deletions
48
nodejs-addon-examples/test_tts_non_streaming_vits_zh_ll.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright (c) 2024 Xiaomi Corporation | ||
const sherpa_onnx = require('sherpa-onnx-node'); | ||
const performance = require('perf_hooks').performance; | ||
|
||
// please download model files from | ||
// https://github.com/k2-fsa/sherpa-onnx/releases/tag/tts-models | ||
function createOfflineTts() { | ||
const config = { | ||
model: { | ||
vits: { | ||
model: './sherpa-onnx-vits-zh-ll/model.onnx', | ||
tokens: './sherpa-onnx-vits-zh-ll/tokens.txt', | ||
lexicon: './sherpa-onnx-vits-zh-ll/lexicon.txt', | ||
dictDir: './sherpa-onnx-vits-zh-ll/dict', | ||
}, | ||
debug: true, | ||
numThreads: 1, | ||
provider: 'cpu', | ||
}, | ||
maxNumStences: 1, | ||
ruleFsts: | ||
'./sherpa-onnx-vits-zh-ll/date.fst,./sherpa-onnx-vits-zh-ll/phone.fst,./sherpa-onnx-vits-zh-ll/number.fst', | ||
}; | ||
return new sherpa_onnx.OfflineTts(config); | ||
} | ||
|
||
const tts = createOfflineTts(); | ||
|
||
const text = | ||
'当夜幕降临,星光点点,伴随着微风拂面,我在静谧中感受着时光的流转,思念如涟漪荡漾,梦境如画卷展开,我与自然融为一体,沉静在这片宁静的美丽之中,感受着生命的奇迹与温柔。2024年5月13号,拨打110或者18920240513。123456块钱。' | ||
|
||
let start = performance.now(); | ||
const audio = tts.generate({text: text, sid: 2, speed: 1.0}); | ||
let stop = performance.now(); | ||
const elapsed_seconds = (stop - start) / 1000; | ||
const duration = audio.samples.length / audio.sampleRate; | ||
const real_time_factor = elapsed_seconds / duration; | ||
console.log('Wave duration', duration.toFixed(3), 'secodns') | ||
console.log('Elapsed', elapsed_seconds.toFixed(3), 'secodns') | ||
console.log( | ||
`RTF = ${elapsed_seconds.toFixed(3)}/${duration.toFixed(3)} =`, | ||
real_time_factor.toFixed(3)) | ||
|
||
const filename = 'test-zh-ll.wav'; | ||
sherpa_onnx.writeWave( | ||
filename, {samples: audio.samples, sampleRate: audio.sampleRate}); | ||
|
||
console.log(`Saved to ${filename}`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const addon = require('./addon.js'); | ||
|
||
class OfflineTts { | ||
constructor(config) { | ||
this.handle = addon.createOfflineTts(config); | ||
this.config = config; | ||
|
||
this.numSpeakers = addon.getOfflineTtsNumSpeakers(this.handle); | ||
this.sampleRate = addon.getOfflineTtsSampleRate(this.handle); | ||
} | ||
|
||
/* | ||
input obj: {text: "xxxx", sid: 0, speed: 1.0} | ||
where text is a string, sid is a int32, speed is a float | ||
return an object {samples: Float32Array, sampleRate: <a number>} | ||
*/ | ||
generate(obj) { | ||
return addon.offlineTtsGenerate(this.handle, obj); | ||
} | ||
} | ||
|
||
module.exports = { | ||
OfflineTts, | ||
} |
Oops, something went wrong.