This repository has been archived on 2025-08-26. You can view files and clone it, but cannot push or open issues or pull requests.
Files
enginex_bi_series-sherpa-onnx/nodejs-examples/test-offline-tts-vits-en.js

44 lines
1.2 KiB
JavaScript
Raw Permalink Normal View History

2024-03-03 20:00:36 +08:00
// Copyright (c) 2023-2024 Xiaomi Corporation (authors: Fangjun Kuang)
2023-11-21 23:20:08 +08:00
const sherpa_onnx = require('sherpa-onnx');
function createOfflineTts() {
2024-03-03 20:00:36 +08:00
let offlineTtsVitsModelConfig = {
model: './vits-piper-en_US-amy-low/en_US-amy-low.onnx',
tokens: './vits-piper-en_US-amy-low/tokens.txt',
dataDir: './vits-piper-en_US-amy-low/espeak-ng-data',
noiseScale: 0.667,
noiseScaleW: 0.8,
lengthScale: 1.0,
};
let offlineTtsModelConfig = {
offlineTtsVitsModelConfig: offlineTtsVitsModelConfig,
numThreads: 1,
debug: 1,
provider: 'cpu',
};
2023-11-21 23:20:08 +08:00
2024-03-03 20:00:36 +08:00
let offlineTtsConfig = {
offlineTtsModelConfig: offlineTtsModelConfig,
maxNumSentences: 1,
};
2023-11-21 23:20:08 +08:00
2024-03-03 20:00:36 +08:00
return sherpa_onnx.createOfflineTts(offlineTtsConfig);
2023-11-21 23:20:08 +08:00
}
2024-03-03 20:00:36 +08:00
2023-11-21 23:20:08 +08:00
const tts = createOfflineTts();
const speakerId = 0;
2023-11-21 23:20:08 +08:00
const speed = 1.0;
2024-03-03 20:00:36 +08:00
const audio = tts.generate({
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.”',
sid: speakerId,
speed: speed
});
tts.save('./test-vits-en.wav', audio);
console.log('Saved to test-vits-en.wav successfully.');
2024-03-03 20:00:36 +08:00
2023-11-21 23:20:08 +08:00
tts.free();