Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -3,20 +3,27 @@ import gradio as gr
|
|
3 |
from transformers import pipeline
|
4 |
|
5 |
title = "Transcribe speech several languages"
|
|
|
6 |
|
7 |
-
|
8 |
-
|
9 |
|
10 |
-
def transcribeFile(audio_path : str) -> str:
|
11 |
-
transcription =
|
12 |
-
|
|
|
|
|
|
|
|
|
13 |
|
14 |
def transcribeFileMulti(inputlang, audio_path : str) -> str:
|
15 |
if inputlang == "English":
|
16 |
-
transcription =
|
17 |
elif inputlang == "German":
|
18 |
-
transcription =
|
19 |
-
|
|
|
|
|
20 |
|
21 |
|
22 |
|
|
|
3 |
from transformers import pipeline
|
4 |
|
5 |
title = "Transcribe speech several languages"
|
6 |
+
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
7 |
|
8 |
+
asr_pipe_audio2Text_Ge = pipeline(task="automatic-speech-recognition", model="jonatasgrosman/wav2vec2-large-xlsr-53-german")
|
9 |
+
asr_pipe_whisper = pipeline(task="automatic-speech-recognition", model="openai/whisper-large", device=device)
|
10 |
|
11 |
+
#def transcribeFile(audio_path : str) -> str:
|
12 |
+
# transcription = asr_pipe_audio2Text_Ge(audio_path)
|
13 |
+
# return transcription["text"]
|
14 |
+
|
15 |
+
def translateAudio(audio_path):
|
16 |
+
translationOutput = asr_pipe_whisper(audio_path, max_new_tokens=256, generate_kwargs={"task":"translate"})
|
17 |
+
return translationOutput["text"]
|
18 |
|
19 |
def transcribeFileMulti(inputlang, audio_path : str) -> str:
|
20 |
if inputlang == "English":
|
21 |
+
transcription = asr_pipe_whisper(audio_path)
|
22 |
elif inputlang == "German":
|
23 |
+
transcription = asr_pipe_audio2Text_Ge(audio_path)
|
24 |
+
translation = translateAudio(audio_path)
|
25 |
+
output = transcription + translation
|
26 |
+
return output #transcription["text"]
|
27 |
|
28 |
|
29 |
|