Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -39,6 +39,10 @@ def speech_to_text(audio_data, tgt_lang):
|
|
| 39 |
s2t_model = torch.jit.load("unity_on_device_s2t.ptl")
|
| 40 |
with torch.no_grad():
|
| 41 |
text = s2t_model(audio_input, tgt_lang=languages[tgt_lang])
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
return text
|
| 43 |
|
| 44 |
def speech_to_speech_translation(audio_data, tgt_lang):
|
|
@@ -46,11 +50,25 @@ def speech_to_speech_translation(audio_data, tgt_lang):
|
|
| 46 |
audio_input, _ = torchaudio.load(file_path)
|
| 47 |
s2st_model = torch.jit.load("unity_on_device_s2t.ptl")
|
| 48 |
with torch.no_grad():
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
output_file = "/tmp/result.wav"
|
| 51 |
torchaudio.save(output_file, waveform.unsqueeze(0), sample_rate=16000)
|
| 52 |
return text, output_file
|
| 53 |
|
|
|
|
| 54 |
def create_interface():
|
| 55 |
with gr.Blocks(theme='ParityError/Anime') as interface:
|
| 56 |
gr.Markdown(welcome_message)
|
|
|
|
| 39 |
s2t_model = torch.jit.load("unity_on_device_s2t.ptl")
|
| 40 |
with torch.no_grad():
|
| 41 |
text = s2t_model(audio_input, tgt_lang=languages[tgt_lang])
|
| 42 |
+
|
| 43 |
+
# Print the model's output for debugging
|
| 44 |
+
print("Speech to Text Model Output:", text)
|
| 45 |
+
|
| 46 |
return text
|
| 47 |
|
| 48 |
def speech_to_speech_translation(audio_data, tgt_lang):
|
|
|
|
| 50 |
audio_input, _ = torchaudio.load(file_path)
|
| 51 |
s2st_model = torch.jit.load("unity_on_device_s2t.ptl")
|
| 52 |
with torch.no_grad():
|
| 53 |
+
model_output = s2st_model(audio_input, tgt_lang=languages[tgt_lang])
|
| 54 |
+
|
| 55 |
+
# Print the model's output for debugging
|
| 56 |
+
print("Speech to Speech Translation Model Output:", model_output)
|
| 57 |
+
|
| 58 |
+
# Check the structure of model_output and unpack accordingly
|
| 59 |
+
if len(model_output) == 3:
|
| 60 |
+
text, units, waveform = model_output
|
| 61 |
+
elif len(model_output) == 2:
|
| 62 |
+
text, waveform = model_output
|
| 63 |
+
units = None # or some default value
|
| 64 |
+
else:
|
| 65 |
+
raise ValueError("Unexpected model output format")
|
| 66 |
+
|
| 67 |
output_file = "/tmp/result.wav"
|
| 68 |
torchaudio.save(output_file, waveform.unsqueeze(0), sample_rate=16000)
|
| 69 |
return text, output_file
|
| 70 |
|
| 71 |
+
|
| 72 |
def create_interface():
|
| 73 |
with gr.Blocks(theme='ParityError/Anime') as interface:
|
| 74 |
gr.Markdown(welcome_message)
|