Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from deep_translator import GoogleTranslator
|
3 |
+
#import deepl
|
4 |
+
from transformers import pipeline
|
5 |
+
import os
|
6 |
+
from gtts import gTTS
|
7 |
+
|
8 |
+
pipe = pipeline(model="freeja/lab2-whisper-sv")
|
9 |
+
|
10 |
+
def transcribe_audio(audio,language):
|
11 |
+
transcribed = pipe(audio,"text")
|
12 |
+
result = "Transcribed text\n"
|
13 |
+
result += transcribed + "\n"
|
14 |
+
result += "Translated text\n"
|
15 |
+
trans_text = translate_audio(transcribed,language)
|
16 |
+
result += trans_text
|
17 |
+
text_to_speech(trans_text,language)
|
18 |
+
result += text_to_speech
|
19 |
+
return result
|
20 |
+
|
21 |
+
|
22 |
+
def translate_audio(text,language):
|
23 |
+
#translate = deepl.Translator
|
24 |
+
language_dict = {"English":"en","Spanish":"es","German":"de","French":"fr","Italian":"it"}
|
25 |
+
lang = language_dict[language]
|
26 |
+
translated_text = GoogleTranslator(source='sv', target=lang).translate(text)
|
27 |
+
return translated_text
|
28 |
+
|
29 |
+
def text_to_speech(text,language):
|
30 |
+
language_dict = {"English":"en","Spanish":"es","German":"de","French":"fr","Italian":"it"}
|
31 |
+
lang = language_dict[language]
|
32 |
+
gTTS(text,lang,slow=False)
|
33 |
+
|
34 |
+
|
35 |
+
|
36 |
+
face = gr.Interface(
|
37 |
+
fn=transcribe_audio,
|
38 |
+
inputs=[
|
39 |
+
gr.Audio(source="microphone", type="filepath", label="Transcribe from Microphone"),
|
40 |
+
gr.Dropdown(["English","Spanish","Dutch","French","Italian"], value="English", label="Translate to ")
|
41 |
+
],
|
42 |
+
outputs="text",
|
43 |
+
title="Whisper Small Swedish",
|
44 |
+
description="Realtime demo for Swedish speech recognition with translation using a fine-tuned Whisper small model"
|
45 |
+
|
46 |
+
)
|