-
Notifications
You must be signed in to change notification settings - Fork 475
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
e34a1a2
commit 4ab24c0
Showing
7 changed files
with
379 additions
and
18 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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
!run-*.sh | ||
piper |
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,55 @@ | ||
{ Copyright (c) 2024 Xiaomi Corporation } | ||
program piper; | ||
{ | ||
This file shows how to use the text to speech API of sherpa-onnx | ||
with Piper models. | ||
It generates speech fro text and saves it to a wave file. | ||
If you want to play it while it is generating, please see | ||
./piper-playback.pas | ||
} | ||
|
||
{$mode objfpc} | ||
{$ASSERTIONS ON} | ||
|
||
uses | ||
SysUtils, | ||
sherpa_onnx; | ||
|
||
function GetOfflineTts: TSherpaOnnxOfflineTts; | ||
var | ||
Config: TSherpaOnnxOfflineTtsConfig; | ||
begin | ||
Config.Model.Vits.Model := './vits-piper-en_US-libritts_r-medium/en_US-libritts_r-medium.onnx'; | ||
Config.Model.Vits.Tokens := './vits-piper-en_US-libritts_r-medium/tokens.txt'; | ||
Config.Model.Vits.DataDir := './vits-piper-en_US-libritts_r-medium/espeak-ng-data'; | ||
Config.Model.NumThreads := 1; | ||
Config.Model.Debug := False; | ||
Config.MaxNumSentences := 1; | ||
|
||
Result := TSherpaOnnxOfflineTts.Create(Config); | ||
end; | ||
|
||
var | ||
Tts: TSherpaOnnxOfflineTts; | ||
Audio: TSherpaOnnxGeneratedAudio; | ||
|
||
Text: AnsiString; | ||
Speed: Single = 1.0; {Use a large value to speak faster} | ||
SpeakerId: Integer = 0; | ||
|
||
begin | ||
Tts := GetOfflineTts; | ||
|
||
WriteLn('There are ', Tts.GetNumSpeakers, ' speakers'); | ||
|
||
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.'; | ||
|
||
Audio := Tts.Generate(Text, SpeakerId, Speed); | ||
SherpaOnnxWriteWave('./libritts_r-generated.wav', Audio.Samples, Audio.SampleRate); | ||
WriteLn('Saved to ./libritts_r-generated.wav'); | ||
|
||
FreeAndNil(Tts); | ||
end. | ||
|
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,41 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -ex | ||
|
||
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) | ||
SHERPA_ONNX_DIR=$(cd $SCRIPT_DIR/../.. && pwd) | ||
|
||
echo "SHERPA_ONNX_DIR: $SHERPA_ONNX_DIR" | ||
|
||
if [[ ! -f ../../build/install/lib/libsherpa-onnx-c-api.dylib && ! -f ../../build/install/lib/libsherpa-onnx-c-api.so && ! -f ../../build/install/lib/sherpa-onnx-c-api.dll ]]; then | ||
mkdir -p ../../build | ||
pushd ../../build | ||
cmake \ | ||
-DCMAKE_INSTALL_PREFIX=./install \ | ||
-DSHERPA_ONNX_ENABLE_PYTHON=OFF \ | ||
-DSHERPA_ONNX_ENABLE_TESTS=OFF \ | ||
-DSHERPA_ONNX_ENABLE_CHECK=OFF \ | ||
-DBUILD_SHARED_LIBS=ON \ | ||
-DSHERPA_ONNX_ENABLE_PORTAUDIO=OFF \ | ||
.. | ||
|
||
cmake --build . --target install --config Release | ||
popd | ||
fi | ||
|
||
if [[ ! -f ./vits-piper-en_US-libritts_r-medium/tokens.txt ]]; then | ||
curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/tts-models/vits-piper-en_US-libritts_r-medium.tar.bz2 | ||
tar xf vits-piper-en_US-libritts_r-medium.tar.bz2 | ||
rm vits-piper-en_US-libritts_r-medium.tar.bz2 | ||
fi | ||
|
||
fpc \ | ||
-dSHERPA_ONNX_USE_SHARED_LIBS \ | ||
-Fu$SHERPA_ONNX_DIR/sherpa-onnx/pascal-api \ | ||
-Fl$SHERPA_ONNX_DIR/build/install/lib \ | ||
./piper.pas | ||
|
||
export LD_LIBRARY_PATH=$SHERPA_ONNX_DIR/build/install/lib:$LD_LIBRARY_PATH | ||
export DYLD_LIBRARY_PATH=$SHERPA_ONNX_DIR/build/install/lib:$DYLD_LIBRARY_PATH | ||
|
||
./piper |
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
Oops, something went wrong.