File size: 1,387 Bytes
ea9c1e1
535db75
ea9c1e1
 
81e8d61
ea9c1e1
535db75
 
 
 
 
 
 
 
ea9c1e1
 
81e8d61
 
ea9c1e1
 
 
 
 
 
81e8d61
 
 
 
 
 
ea9c1e1
81e8d61
 
ea9c1e1
 
 
 
 
 
81e8d61
f466968
ea9c1e1
 
 
1c67364
 
 
ea9c1e1
535db75
ea9c1e1
ee60cd3
ea9c1e1
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
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()