25 lines
1.1 KiB
Nix
25 lines
1.1 KiB
Nix
# The speech server and clients, with node, and the sox, whisper, and piper the server's scripts use.
|
|
# bin/speech-server HOST PORT MODEL VOICE [PIPER_OPTION...]
|
|
# bin/hear-client URL < clip.wav
|
|
# bin/speak-client URL < text > speech.wav
|
|
{ callPackage, runCommand, nodejs-slim, sox, whisper-cpp, piper-tts }:
|
|
let
|
|
js = callPackage ./default.nix { };
|
|
dir = "${js}/lib/node_modules/pdtv26-speech";
|
|
in
|
|
runCommand "pdtv26-speech" { } ''
|
|
mkdir -p $out/bin
|
|
substitute ${./hear.sh} $out/bin/hear.sh --subst-var-by sox ${sox} --subst-var-by whisper ${whisper-cpp}
|
|
substitute ${./speak.sh} $out/bin/speak.sh --subst-var-by piper ${piper-tts}
|
|
chmod +x $out/bin/hear.sh $out/bin/speak.sh
|
|
cat > $out/bin/speech-server <<EOF
|
|
#!/bin/sh
|
|
host=\$1 port=\$2 model=\$3 voice=\$4; shift 4
|
|
exec ${nodejs-slim}/bin/node ${dir}/server.js "\$host" "\$port" $out/bin/hear.sh "\$model" $out/bin/speak.sh "\$voice" "\$@"
|
|
EOF
|
|
for c in hear-client speak-client; do
|
|
printf '#!/bin/sh\nexec %s %s/%s.js "$@"\n' ${nodejs-slim}/bin/node ${dir} $c > $out/bin/$c
|
|
done
|
|
chmod +x $out/bin/speech-server $out/bin/hear-client $out/bin/speak-client
|
|
''
|