import gradio as gr from transformers import pipeline import numpy as np transcriber = pipeline("automatic-speech-recognition", model="jonatasgrosman/wav2vec2-large-xlsr-53-arabic") def transcribe(stream, new_chunk): sr, y = new_chunk y = y.astype(np.float32) y /= np.max(np.abs(y)) if stream is not None: stream = np.concatenate([stream, y]) else: stream = y return stream, transcriber({"sampling_rate": sr, "raw": stream})["text"] demo = gr.Interface( transcribe, ["state", gr.Audio(sources=["microphone"], streaming=True)], ["state", "text"], live=True, title="S2T: Transcription automatique en LIVE de l'arabe en text by PS-WADE", description="Parlez en arabe dans le microphone. La transcription commence en quelques secondes. Attendez un moment après avoir terminé pour voir le reste de la transcription" ) demo.launch(share=True, show_error=True) # import httpcore # import gradio as gr # from transformers import pipeline # import numpy as np # setattr(httpcore, 'SyncHTTPTransport', object) # from googletrans import Translator # import time # # Initialisation du modèle de transcription # transcriber = pipeline("automatic-speech-recognition", model="jonatasgrosman/wav2vec2-large-xlsr-53-arabic") # # Initialisation du traducteur # translator = Translator() # def transcribe_and_translate(stream, new_chunk): # sr, y = new_chunk # y = y.astype(np.float32) # y /= np.max(np.abs(y)) # if stream is not None: # stream = np.concatenate([stream, y]) # else: # stream = y # # Transcription du texte # transcription = transcriber({"sampling_rate": sr, "raw": stream})["text"] # # Traduction du texte transcrit # time.sleep(5) # translation = translator.translate(transcription, src='ar', dest='fr').text # return stream, transcription, translation # # Création de l'interface Gradio # demo = gr.Interface( # fn=transcribe_and_translate, # inputs=[ # gr.State(), # gr.Audio(sources=["microphone"], streaming=True) # ], # outputs=[ # gr.State(), # gr.Textbox(label="Texte en Arabe"), # gr.Textbox(label="Traduction en Français") # ], # live=True, # title="S2T: Transcription et traduction automatiques en LIVE de l'arabe en texte français by PS-WADE", # description="Parlez en arabe dans le microphone. La transcription et la traduction commencent en quelques secondes. Attendez un moment après avoir terminé pour voir le reste de la transcription et la traduction." # ) # # Lancement de l'application Gradio # demo.launch(share=True, show_error=True)