Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -38,29 +38,25 @@ def speech_to_text(audio_data, tgt_lang):
|
|
| 38 |
audio_input, _ = torchaudio.load(file_path)
|
| 39 |
s2t_model = torch.jit.load("unity_on_device.ptl")
|
| 40 |
with torch.no_grad():
|
| 41 |
-
|
|
|
|
|
|
|
| 42 |
|
| 43 |
-
|
| 44 |
-
print("Speech to Text Model Output:", text)
|
| 45 |
-
|
| 46 |
-
return text
|
| 47 |
|
| 48 |
def speech_to_speech_translation(audio_data, tgt_lang):
|
| 49 |
file_path = save_audio(audio_data)
|
| 50 |
audio_input, _ = torchaudio.load(file_path)
|
| 51 |
s2st_model = torch.jit.load("unity_on_device.ptl")
|
| 52 |
-
|
| 53 |
with torch.no_grad():
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
print("Translated Text:",
|
| 58 |
print("Units:", units)
|
| 59 |
print("Waveform Shape:", waveform.shape)
|
| 60 |
|
| 61 |
-
|
| 62 |
-
torchaudio.save(output_file, waveform.unsqueeze(0), sample_rate=16000)
|
| 63 |
-
return text, output_file
|
| 64 |
|
| 65 |
|
| 66 |
def create_interface():
|
|
|
|
| 38 |
audio_input, _ = torchaudio.load(file_path)
|
| 39 |
s2t_model = torch.jit.load("unity_on_device.ptl")
|
| 40 |
with torch.no_grad():
|
| 41 |
+
model_output = s2t_model(audio_input, tgt_lang=languages[tgt_lang])
|
| 42 |
+
transcribed_text = model_output[0] if model_output else ""
|
| 43 |
+
print("Speech to Text Model Output:", transcribed_text)
|
| 44 |
|
| 45 |
+
return transcribed_text
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
def speech_to_speech_translation(audio_data, tgt_lang):
|
| 48 |
file_path = save_audio(audio_data)
|
| 49 |
audio_input, _ = torchaudio.load(file_path)
|
| 50 |
s2st_model = torch.jit.load("unity_on_device.ptl")
|
|
|
|
| 51 |
with torch.no_grad():
|
| 52 |
+
translated_text, units, waveform = s2st_model(audio_input, tgt_lang=languages[tgt_lang])
|
| 53 |
+
output_file = "/tmp/result.wav"
|
| 54 |
+
torchaudio.save(output_file, waveform.unsqueeze(0), sample_rate=16000)
|
| 55 |
+
print("Translated Text:", translated_text)
|
| 56 |
print("Units:", units)
|
| 57 |
print("Waveform Shape:", waveform.shape)
|
| 58 |
|
| 59 |
+
return translated_text, output_file
|
|
|
|
|
|
|
| 60 |
|
| 61 |
|
| 62 |
def create_interface():
|