import streamlit as st import subprocess import tempfile import sys import os from os.path import exists import requests import tarfile from PIL import Image BASE_PATH = os.getcwd() # /home/user/app URL_PIPER_DOWNLOAD = "https://github.com/rhasspy/piper/releases/download/v1.2.0/piper_amd64.tar.gz" URL_TV_HESSISCH_ONNX = "https://huggingface.co./Thorsten-Voice/Hessisch/resolve/main/Thorsten-Voice_Hessisch_Piper_high-Sep2023.onnx" URL_TV_HESSISCH_JSON = "https://huggingface.co./Thorsten-Voice/Hessisch/raw/main/Thorsten-Voice_Hessisch_Piper_high-Sep2023.onnx.json" TV_HESSISCH_FILENAME = "Thorsten-Voice_Hessisch_Piper_high-Sep2023" FOLDER_TV_HESSISCH_MODEL = os.path.join(BASE_PATH, "Model") TMP_PIPER_FILENAME = os.path.join(BASE_PATH, "piper.tgz") ########################## # CHECK OR INSTALL PIPER # ########################## if os.path.exists(os.path.join(BASE_PATH,"piper")) == False: # Piper not downloaded and extracted yet, let's do this first. response = requests.get(URL_PIPER_DOWNLOAD) if response.status_code == 200: with open(TMP_PIPER_FILENAME, 'wb') as f: f.write(response.content) with tarfile.open(TMP_PIPER_FILENAME, 'r:gz') as tar: tar.extractall(BASE_PATH) else: st.markdown(f"Failed to download Piper TTS from {URL_PIPER_DOWNLOAD} (Status code: {response.status_code})") ################################################################### # CHECK OR DOWNLOAD Thorsten-Voice HESSISCH PIPER TTS MODEL FILES # ################################################################### if os.path.exists(os.path.join(FOLDER_TV_HESSISCH_MODEL,TV_HESSISCH_FILENAME + '.onnx')) == False: if not os.path.exists(FOLDER_TV_HESSISCH_MODEL): os.makedirs(FOLDER_TV_HESSISCH_MODEL) # Download Model (ONNX-file) # ############################## response = requests.get(URL_TV_HESSISCH_ONNX) if response.status_code == 200: with open(os.path.join(FOLDER_TV_HESSISCH_MODEL,TV_HESSISCH_FILENAME + '.onnx'), 'wb') as f: f.write(response.content) else: st.markdown(f"Failed to download model file {TV_HESSISCH_FILENAME} (Status code: {response.status_code})") # Download Model (JSON-file) # ############################## response = requests.get(URL_TV_HESSISCH_JSON) if response.status_code == 200: with open(os.path.join(FOLDER_TV_HESSISCH_MODEL,TV_HESSISCH_FILENAME + '.onnx.json'), 'wb') as f: f.write(response.content) else: st.markdown(f"Failed to download model CONFIG JSON file {TV_HESSISCH_FILENAME} (Status code: {response.status_code})") hide_streamlit_style = """ """ st.markdown(hide_streamlit_style, unsafe_allow_html=True) image = Image.open('Thorsten-Voice_transparent.png') #st.image(image, width=400) st.image(image) st.title('Guude! Thorsten-Voice babbelt jetzt ach uff (Süd)Hessisch!') st.markdown('Schön, dass Du meine kostenlose und hessisch babbelnde Stimme selbst ausprobieren möchtest. ' + 'Du willst mehr Infos? Dann schau gerne hier: https://www.Thorsten-Voice.de/guude') with st.form("my_form"): text = st.text_area("Was soll ich dann babbele?",max_chars=250) submitted = st.form_submit_button("Schwätz los!") if submitted: with st.spinner("Stress ned rum, ich denk noch nach ..."): filename = tempfile.NamedTemporaryFile(suffix=".wav", delete=False) cmd = "echo '" + text + "' | /home/user/app/piper/piper --model '" + os.path.join(FOLDER_TV_HESSISCH_MODEL, TV_HESSISCH_FILENAME) + ".onnx' --output_file " + filename.name result = subprocess.run(cmd, shell=True) audio_file = open(filename.name, 'rb') audio_bytes = audio_file.read() st.audio(audio_bytes,format="audio/wav") try: st.download_button('Gebabbel runterladen', audio_bytes, file_name='Thorsten-Voice_Hessisch.wav') except: pass st.markdown('**Unkreativ? Hier etwas Inspiration:**') st.markdown('* "Guude Günther, ich wünsche Dir alles Liebe und Gute zu deinem Geburtstag, alter Babbsack."') st.markdown('* "Erbarme, zu spät, die Hesse komme."') st.markdown('* "Die aktuelle Temperatur beträgt 12 Grad bei einer Regenwahrscheinlichkeit von 80%. Pack am besten einen Regenschirm ein."') st.markdown('* "Ebbelwoi und grie Soß ist super, desdewegen sollte das jeder einmal im Leben probiert haben."') st.markdown('* _Nutze Thorsten-Voice auch gerne für deine Tik-Toks, Insta-Stories und Youtube Videos._') st.header('Ei subba, kann ich dich unterstützen?') st.markdown('Ja, das kannst Du!') st.markdown('Ich hätte sehr gerne den silbernen Youtube Play-Button für 100.000 Abonnenten auf ' + 'meinem [**"Thorsten-Voice" Youtube Kanal**](https://www.youtube.com/c/ThorstenMueller?sub_confirmation=1). ' + 'Mit einem Abo würdest Du mich also wirklich unterstützen. ' + 'Natürlich darfst du von dem Projekt auch gerne Freunden erzählen oder es in den sozialen Medien teilen. ' + 'Danke schön 🥰.') #image = Image.open('Ziel_Thorsten-Voice_Playbutton.png') #st.image(image,caption='Fotomontage vom silbernen Youtube Playbutton für Thorsten-Voice Kanal. Bildquelle: Wikipedia') st.markdown('---') st.markdown('🇺🇸 _Thanks to Michael Hansen for providing [Piper TTS](https://github.com/rhasspy/piper) on which this "hessische" Thorsten-Voice model relies._')