File size: 1,735 Bytes
535db75 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
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() |