Spaces:
Sleeping
Sleeping
import os | |
import subprocess | |
import gradio as gr | |
# Supported languages | |
LANGUAGE_CODES = { | |
"English": "eng", | |
"Spanish": "spa", | |
"French": "fra", | |
"German": "deu", | |
"Italian": "ita", | |
"Chinese": "cmn" | |
} | |
def translate_speech(audio_file, target_language): | |
""" | |
Translate input speech (audio file) to the specified target language. | |
Args: | |
audio_file (str): Path to the input audio file. | |
target_language (str): The target language for translation. | |
Returns: | |
str: Path to the translated audio file. | |
""" | |
language_code = LANGUAGE_CODES[target_language] | |
output_file = "translated_audio.wav" | |
command = [ | |
"expressivity_predict", | |
audio_file, | |
"--tgt_lang", language_code, | |
"--model_name", "seamless_expressivity", | |
"--vocoder_name", "vocoder_pretssel", | |
"--gated-model-dir", "seamlessmodel", | |
"--output_path", output_file | |
] | |
subprocess.run(command, check=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 | |
def create_interface(): | |
"""Create and configure the Gradio interface.""" | |
inputs = [ | |
gr.Audio(type="filepath", label="Audio File"), | |
gr.Dropdown(list(LANGUAGE_CODES.keys()), label="Target Language") | |
] | |
return gr.Interface( | |
fn=translate_speech, | |
inputs=inputs, | |
outputs=gr.Audio(label="Translated Audio"), | |
title="Seamless Expressive Speech-To-Speech Translator", | |
description="Hear how you sound in another language.", | |
) | |
if __name__ == "__main__": | |
iface = create_interface() | |
iface.launch() |