Jaward commited on
Commit
535db75
1 Parent(s): 0e30afa
Files changed (2) hide show
  1. app.py +65 -0
  2. requirements.txt +7 -0
app.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import subprocess
3
+ import gradio as gr
4
+
5
+ # Supported languages
6
+ LANGUAGE_CODES = {
7
+ "English": "eng",
8
+ "Spanish": "spa",
9
+ "French": "fra",
10
+ "German": "deu",
11
+ "Italian": "ita",
12
+ "Chinese": "cmn"
13
+ }
14
+
15
+ def translate_speech(audio_file, target_language):
16
+ """
17
+ Translate input speech (audio file) to the specified target language.
18
+
19
+ Args:
20
+ audio_file (str): Path to the input audio file.
21
+ target_language (str): The target language for translation.
22
+
23
+ Returns:
24
+ str: Path to the translated audio file.
25
+ """
26
+ language_code = LANGUAGE_CODES[target_language]
27
+ output_file = "translated_audio.wav"
28
+
29
+ command = [
30
+ "expressivity_predict",
31
+ audio_file,
32
+ "--tgt_lang", language_code,
33
+ "--model_name", "seamless_expressivity",
34
+ "--vocoder_name", "vocoder_pretssel",
35
+ "--gated-model-dir", "seamlessmodel",
36
+ "--output_path", output_file
37
+ ]
38
+
39
+ subprocess.run(command, check=True)
40
+
41
+ if os.path.exists(output_file):
42
+ print(f"File created successfully: {output_file}")
43
+ else:
44
+ print(f"File not found: {output_file}")
45
+
46
+ return output_file
47
+
48
+ def create_interface():
49
+ """Create and configure the Gradio interface."""
50
+ inputs = [
51
+ gr.Audio(type="filepath", label="Audio File"),
52
+ gr.Dropdown(list(LANGUAGE_CODES.keys()), label="Target Language")
53
+ ]
54
+
55
+ return gr.Interface(
56
+ fn=translate_speech,
57
+ inputs=inputs,
58
+ outputs=gr.Audio(label="Translated Audio"),
59
+ title="Seamless Expressive Speech-To-Speech Translator",
60
+ description="Hear how you sound in another language.",
61
+ )
62
+
63
+ if __name__ == "__main__":
64
+ iface = create_interface()
65
+ iface.launch()
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ git+https://github.com/facebookresearch/seamless_communication.git
2
+ pydub
3
+ soundfile
4
+ torchaudio
5
+ torch
6
+ gradio
7
+ fairseq2 --pre --extra-index-url https://fair.pkg.atmeta.com/fairseq2/pt2.1.0/cu121