Varosa commited on
Commit
83bd913
1 Parent(s): f466042

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +65 -0
app.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Import libraries
2
+ import io
3
+ import os
4
+ import json
5
+ import subprocess
6
+ import mmap
7
+ import numpy
8
+ import soundfile
9
+ import torchaudio
10
+ import torch
11
+ import gradio as gr
12
+ from collections import defaultdict
13
+ from pathlib import Path
14
+ from pydub import AudioSegment
15
+ from seamless_communication.inference import Translator
16
+ from seamless_communication.streaming.dataloaders.s2tt import SileroVADSilenceRemover
17
+
18
+
19
+ # Mapping of language names to their respective codes
20
+ language_codes = {
21
+ "English": "eng",
22
+ "Spanish": "spa",
23
+ "French": "fra",
24
+ "German": "deu",
25
+ "Italian": "ita",
26
+ "Chinese": "cmn"
27
+ }
28
+
29
+ # Function to handle the translation to target language
30
+ def translate_audio(audio_file, target_language):
31
+ language_code = language_codes[target_language]
32
+ output_file = "translated_audio.wav"
33
+
34
+ command = f"expressivity_predict {audio_file} --tgt_lang {language_code} \
35
+ --model_name seamless_expressivity --vocoder_name vocoder_pretssel \
36
+ --gated-model-dir seamlessmodel --output_path {output_file}"
37
+ subprocess.run(command, shell=True)
38
+
39
+ if os.path.exists(output_file):
40
+ print(f"File created successfully: {output_file}")
41
+ else:
42
+ print(f"File not found: {output_file}")
43
+
44
+ return output_file
45
+
46
+
47
+ # Define inputs
48
+ inputs = [
49
+ gr.Audio(type = "filepath", label = "Audio_file"),
50
+ gr.Dropdown(["English", "Spanish", "French", "German", "Italian", "Chinese"], label = "Target_Language")
51
+ ]
52
+
53
+
54
+ # Create Gradio interface
55
+ iface = gr.Interface(
56
+ fn=translate_audio,
57
+ inputs= inputs,
58
+ outputs=gr.Audio(label="Translated Audio"),
59
+ title="Seamless Expressive Audio Translator",
60
+ description="Translate your audio into different languages with expressive styles."
61
+ )
62
+
63
+ # Run the application
64
+ if __name__ == "__main__":
65
+ iface.launch()