improve piper script and better quaility for language guessing

main
pluja 2023-04-28 17:50:01 +02:00
rodzic 7e57200991
commit 0b9cc55857
4 zmienionych plików z 77 dodań i 85 usunięć

Wyświetl plik

@ -1,7 +1,7 @@
#!/bin/bash
echo "Installing piper for text to voice conversion..."
bash /app/piper/init-piper.sh
bash /app/piper/get-piper.sh
echo "Bot starting..."
python3 -u /app/main.py

Wyświetl plik

@ -107,11 +107,11 @@ def generate_settings_markup(chat_id: str) -> InlineKeyboardMarkup:
return InlineKeyboardMarkup(inline_keyboard=keyboard)
async def text_to_voice(text: str, language: str = DEFAULT_VOICE_LANGUAGE) -> BytesIO:
async def text_to_voice(text: str, language: str = None) -> BytesIO:
binary_path = "./piper/piper"
if language is None:
language = detect(text[0:80])
language = detect(text[0:100])
model_path = f"./piper/voices/{language}.onnx"
@ -441,4 +441,4 @@ if __name__ == "__main__":
settings_callback, lambda c: c.data.startswith("setting_")
)
executor.start_polling(dp, skip_updates=True)
executor.start_polling(dp, skip_updates=True, fast=True)

73
piper/get-piper.sh 100755
Wyświetl plik

@ -0,0 +1,73 @@
#!/bin/bash
source .env
if [ "$ENABLE_TTS" = 1 ]; then
echo "Installing piper for text to voice conversion..."
echo "Downloading piper v0.0.2.."
wget -q https://github.com/rhasspy/piper/releases/download/v0.0.2/piper_amd64.tar.gz && \
echo "Extracting piper" && \
tar -xf piper_amd64.tar.gz && \
rm piper_amd64.tar.gz && \
chmod -R 777 ./piper/ && \
mkdir piper/voices
# Download voices for all or selected languages
if [[ "$VOICE_LANGUAGE_LIST" == "*" ]]; then
langs=( "en" "es" "fr" "it" "pt" "ca" "de" "nl" "no" )
else
IFS=',' read -r -a langs <<< "$VOICE_LANGUAGE_LIST"
fi
echo "Downloading tts voices from VOICE_LANGUAGE_LIST..."
echo "This can take a while..."
for lang in "${langs[@]}"; do
case $lang in
"en" )
voice_file="voice-en-us-ryan-high.tar.gz"
;;
"es" )
voice_file="voice-es-mls_10246-low.tar.gz"
;;
"fr" )
voice_file="voice-fr-siwis-medium.tar.gz"
;;
"it" )
voice_file="voice-it-riccardo_fasol-x-low.tar.gz"
;;
"pt" )
voice_file="voice-pt-br-edresson-low.tar.gz"
;;
"ca" )
voice_file="voice-ca-upc_ona-x-low.tar.gz"
;;
"de" )
voice_file="voice-de-thorsten-low.tar.gz"
;;
"nl" )
voice_file="voice-nl-rdh-medium.tar.gz"
;;
"no" )
voice_file="voice-no-talesyntese-medium.tar.gz"
;;
* )
echo "Ignoring unrecognized language code: $lang"
continue
;;
esac
echo "Downloading $lang voice..."
wget -q https://github.com/rhasspy/piper/releases/download/v0.0.2/$voice_file && \
tar -xf $voice_file && \
rm $voice_file && \
mv $lang-*.onnx piper/voices/$lang.onnx && \
mv $lang-*.onnx.json piper/voices/$lang.onnx.json
echo "Done"
done
echo "Done. Piper installed!"
else
echo "TTS Disabled. No work to do..."
fi

Wyświetl plik

@ -1,81 +0,0 @@
#!/bin/bash
source .env
if [ "$ENABLE_TTS" = 1 ]; then
echo "Installing piper for text to voice conversion..."
echo "Downloading piper v0.0.2.."
wget -q https://github.com/rhasspy/piper/releases/download/v0.0.2/piper_amd64.tar.gz
echo "Extracting piper"
tar -xf piper_amd64.tar.gz
echo "Installing piper"
rm -rf piper_amd64
rm piper_amd64.tar.gz
chmod -R 777 ./piper/
mkdir piper/voices
echo "Downloading tts voices from VOICE_LANGUAGE_LIST..."
echo "This can take a while..."
# Check if "en" is in $VOICE_LANGUAGE_LIST and download the english voice from the repo
for lang in $(echo $VOICE_LANGUAGE_LIST | tr "," " "); do
if [ "$lang" = "en" ] ; then
echo "Downloading english voice..."
wget -q https://github.com/rhasspy/piper/releases/download/v0.0.2/voice-en-us-ryan-high.tar.gz
tar -xf voice-en-us-ryan-high.tar.gz
mv en-us-ryan-high.onnx en.onnx
mv en-us-ryan-high.onnx.json en.onnx.json
rm -rf voice-en-us-ryan-high.tar.gz
echo "Done"
fi
if [ "$lang" = "es" ] ; then
echo "Downloading spanish voice..."
wget -q https://github.com/rhasspy/piper/releases/download/v0.0.2/voice-es-mls_10246-low.tar.gz
tar -xf voice-es-mls_10246-low.tar.gz
mv es-mls_10246-low.onnx es.onnx
mv es-mls_10246-low.onnx.json es.onnx.json
rm -rf voice-es-mls_10246-low.tar.gz
echo "Done"
fi
if [ "$lang" = "fr" ] ; then
echo "Downloading french voice..."
wget -q https://github.com/rhasspy/piper/releases/download/v0.0.2/voice-fr-siwis-medium.tar.gz
tar -xf voice-fr-siwis-medium.tar.gz
mv fr-siwis-medium.onnx fr.onnx
mv fr-siwis-medium.onnx.json fr.onnx.json
rm -rf voice-fr-siwis-medium.tar.gz
echo "Done"
fi
if [ "$lang" = "it" ]; then
echo "Downloading italian voice..."
wget -q https://github.com/rhasspy/piper/releases/download/v0.0.2/voice-it-riccardo_fasol-x-low.tar.gz
tar -xf voice-it-riccardo_fasol-x-low.tar.gz
mv it-riccardo_fasol-x-low.onnx it.onnx
mv it-riccardo_fasol-x-low.onnx.json it.onnx.json
rm -rf voice-it-riccardo_fasol-x-low.tar.gz
echo "Done"
fi
if [ "$lang" = "pt" ]; then
echo "Downloading portuguese voice..."
wget -q https://github.com/rhasspy/piper/releases/download/v0.0.2/voice-pt-br-edresson-low.tar.gz
tar -xf voice-pt-br-edresson-low.tar.gz
mv pt-br-edresson-low.onnx pt.onnx
mv pt-br-edresson-low.onnx.json pt.onnx.json
rm -rf voice-pt-br-edresson-low.tar.gz
echo "Done"
fi
if [ "$lang" = "ca" ] ; then
echo "Downloading catalan voice..."
wget -q https://github.com/rhasspy/piper/releases/download/v0.0.2/voice-ca-upc_ona-x-low.tar.gz
tar -xf voice-ca-upc_ona-x-low.tar.gz
mv ca-upc_ona-x-low.onnx ca.onnx
mv ca-upc_ona-x-low.onnx.json ca.onnx.json
rm -rf voice-ca-upc_ona-x-low.tar.gz
echo "Done"
fi
done
echo "Moving voices to piper/voices/"
mv *.onnx* piper/voices/
echo "Done. Piper installed!"
else
echo "TTS Disabled. No work to do..."
fi