Spaces:
Sleeping
Sleeping
import os | |
import subprocess | |
import gradio as gr | |
from pathlib import Path | |
language_codes = { | |
"English": "eng", | |
"Spanish": "spa", | |
"French": "fra", | |
"German": "deu", | |
"Italian": "ita", | |
"Chinese": "cmn" | |
} | |
def translate_audio(audio_file, target_language="German"): | |
language_code = language_codes[target_language] | |
output_file = "translated_audio.wav" | |
command = ( | |
f"expressivity_predict {audio_file} --tgt_lang {language_code} " | |
f"--model_name seamless_expressivity --vocoder_name vocoder_pretssel " | |
f"--gated-model-dir seamlessmodel --output_path {output_file}" | |
) | |
subprocess.run(command, shell=True) | |
if os.path.exists(output_file): | |
print(f"File created successfully: {output_file}") | |
else: | |
print(f"File not found: {output_file}") | |
return output_file | |
inputs = [ | |
gr.Audio(sources=["microphone"], type="filepath", label="User"), | |
gr.Dropdown(["English", "Spanish", "French", "German", "Italian", "Chinese"], | |
label="Target Language", | |
value="German") | |
] | |
iface = gr.Interface( | |
fn=translate_audio, | |
inputs=inputs, | |
outputs=gr.Audio(label="Translated Speech", autoplay=True,), | |
title="Seamless Speech Translator", | |
description="Hear how you sound in another language" | |
) | |
# Run the application | |
if __name__ == "__main__": | |
iface.launch() | |