Spaces:
Runtime error
Runtime error
Commit
•
d195d40
1
Parent(s):
cc4c3a2
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,7 @@ import os
|
|
3 |
import whisper
|
4 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
5 |
from gtts import gTTS
|
|
|
6 |
|
7 |
# Load models
|
8 |
model_stt = whisper.load_model("base")
|
@@ -36,13 +37,22 @@ def speech_to_speech(input_audio, to_lang):
|
|
36 |
output_file = "output_audio.mp3"
|
37 |
tts.save(output_file)
|
38 |
|
39 |
-
|
|
|
|
|
|
|
40 |
|
41 |
languages = ["ru", "fr", "es", "de"] # Example languages: Russian, French, Spanish, German
|
42 |
-
file_input = gr.inputs.File(label="Upload Audio")
|
43 |
dropdown = gr.inputs.Dropdown(languages, label="Translation Language")
|
44 |
-
audio_output = gr.outputs.Audio(label="Translated Voice")
|
45 |
-
|
46 |
-
|
47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
|
|
|
3 |
import whisper
|
4 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
5 |
from gtts import gTTS
|
6 |
+
import numpy as np
|
7 |
|
8 |
# Load models
|
9 |
model_stt = whisper.load_model("base")
|
|
|
37 |
output_file = "output_audio.mp3"
|
38 |
tts.save(output_file)
|
39 |
|
40 |
+
# Load output audio as numpy array
|
41 |
+
audio_np = np.array(output_file)
|
42 |
+
|
43 |
+
return audio_np
|
44 |
|
45 |
languages = ["ru", "fr", "es", "de"] # Example languages: Russian, French, Spanish, German
|
46 |
+
file_input = gr.inputs.File(label="Upload Audio", accept="audio/*")
|
47 |
dropdown = gr.inputs.Dropdown(languages, label="Translation Language")
|
48 |
+
audio_output = gr.outputs.Audio(label="Translated Voice", type="numpy")
|
49 |
+
|
50 |
+
gr.Interface(
|
51 |
+
fn=speech_to_speech,
|
52 |
+
inputs=[file_input, dropdown],
|
53 |
+
outputs=audio_output,
|
54 |
+
title="Speech-to-Speech Translator",
|
55 |
+
description="Upload an audio file (MP3, WAV, or FLAC) and choose the target language for translation.",
|
56 |
+
theme="default"
|
57 |
+
).launch()
|
58 |
|