Spaces:
Runtime error
Runtime error
File size: 1,521 Bytes
2720f57 06a79e1 2720f57 ac45433 2720f57 c3dffed f60f6ff 550a372 1590fca 2720f57 c6750c3 2720f57 d72ad49 2720f57 d72ad49 |
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 |
import gradio as gr
from deep_translator import GoogleTranslator
#import deepl
from transformers import pipeline
import os
from gtts import gTTS
pipe = pipeline(model="CsanadT/whisper_small_sv")
def transcribe_audio(audio,language):
transcribed = pipe(audio)["text"]
result = "Transcribed text\n"
result += transcribed + "\n"
#result += "Translated text\n"
#trans_text = translate_audio(transcribed,language)
#result += trans_text
#text_to_speech(trans_text,language)
#result += text_to_speech
return transcribed
def translate_audio(text,language):
#translate = deepl.Translator
language_dict = {"English":"en","Spanish":"es","German":"de","French":"fr","Italian":"it"}
lang = language_dict[language]
translated_text = GoogleTranslator(source='sv', target=lang).translate(text)
return translated_text
def text_to_speech(text,language):
language_dict = {"English":"en","Spanish":"es","German":"de","French":"fr","Italian":"it"}
lang = language_dict[language]
gTTS(text,lang,slow=False)
iface = gr.Interface(
fn=transcribe_audio,
inputs=[
gr.Audio(source="microphone", type="filepath", label="Transcribe from Microphone"),
gr.Dropdown(["English","Spanish","Dutch","French","Italian"], value="English", label="Translate to ")
],
outputs="text",
title="Whisper Small Swedish",
description="Realtime demo for Swedish speech recognition with translation using a fine-tuned Whisper small model"
)
iface.launch() |