File size: 2,621 Bytes
fceee68
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import streamlit as st
import requests

API_URL_FASTSPEECH2 = "https://api-inference.huggingface.co/models/facebook/fastspeech2-en-ljspeech"
API_URL_DISTIL_WHISPER = "https://api-inference.huggingface.co/models/distil-whisper/distil-large-v3"
API_URL_WAV2VEC2 = "https://api-inference.huggingface.co/models/facebook/wav2vec2-large-960h"

def query(api_url, payload):
    response = requests.post(api_url, json=payload)
    if response.status_code == 200:
        return response.content
    else:
        st.error(f"Erreur {response.status_code}: {response.text}")
        return None

def query_audio(api_url, audio_file):
    response = requests.post(api_url, files={"file": audio_file})
    if response.status_code == 200:
        return response.json()
    else:
        st.error(f"Erreur {response.status_code}: {response.text}")
        return None

def main():
    
    st.title("Text to speech App")
    # Sidebar pour la navigation entre les modèles
    st.sidebar.image("img/istockphoto-1391947389-612x612.jpg")
    model_selection = st.sidebar.selectbox("Sélectionnez le modèle", ["Text-to-Speech (fastspeech2-en-ljspeech)", "Speech-to-Text (distil-whisper/distil-large-v3)"])

    if model_selection == "Text-to-Speech (fastspeech2-en-ljspeech)":
        st.subheader("Text-to-Speech (fastspeech2-en-ljspeech)")
        st.image("img/image2.png") 
        st.text("le modele prend environ 20s pou se charger veiller patienter quelques secondes")
        user_input_tts = st.text_area("Entrez le texte que vous souhaitez convertir en audio:")

        if st.button("Convertir le texte en audio avec fastspeech2-en-ljspeech"):
            payload_tts = {"inputs": user_input_tts}
            audio_bytes = query(API_URL_FASTSPEECH2, payload_tts)

            if audio_bytes:
                st.audio(audio_bytes, format="audio/wav", start_time=0)

    elif model_selection == "Speech-to-Text (distil-whisper/distil-large-v3)":
        st.subheader("Speech-to-Text (distil-whisper/distil-large-v3)")
        st.image("img/istockphoto-1391947389-612x612.jpg") 
        audio_file = st.file_uploader("Téléchargez votre fichier audio", type=["wav", "mp3", "flac"])

        if st.button("Convertir l'audio en texte avec distil-whisper/distil-large-v3") and audio_file is not None:
            result_stt = query_audio(API_URL_DISTIL_WHISPER, audio_file)

            if result_stt:
                st.subheader("Texte transcrit:")
                st.write(result_stt.get("text", "Aucune transcription trouvée."))

if __name__ == "__main__":
    main()