Jaward commited on
Commit
728cf94
·
verified ·
1 Parent(s): 3e0e4fa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -26
app.py CHANGED
@@ -10,7 +10,6 @@ import torch
10
  import random
11
  from openai import OpenAI
12
  import subprocess
13
- import pandas as pd
14
 
15
  default_lang = "en"
16
 
@@ -98,46 +97,29 @@ LANGUAGE_CODES = {
98
  "Spanish": "spa",
99
  "French": "fra",
100
  "German": "deu",
101
- "Chinese": "cmn",
102
- "Italian": "ita"
103
  }
104
 
105
- MODEL_DIR = "/path/to/SeamlessExpressive/model" # Update this path
106
- OUTPUT_DIR = "tmp/"
107
-
108
  def translate_speech(audio_file, target_language):
109
  """
110
- Translate input speech (audio file) to the specified target language using facebook/seamless-expressive model.
111
  """
112
  language_code = LANGUAGE_CODES[target_language]
113
-
114
- # Create a temporary TSV file
115
- temp_tsv = tempfile.NamedTemporaryFile(mode='w+', delete=False, suffix='.tsv')
116
- df = pd.DataFrame({'id': ['1'], 'audio': [audio_file]})
117
- df.to_csv(temp_tsv.name, sep='\t', index=False)
118
- temp_tsv.close()
119
-
120
- output_file = os.path.join(OUTPUT_DIR, "translated_audio.wav")
121
 
122
  command = [
123
- "python", "src/seamless_communication/cli/expressivity/evaluate/pretssel_inference.py",
124
- temp_tsv.name,
125
- "--gated-model-dir", MODEL_DIR,
126
- "--task", "s2st",
127
  "--tgt_lang", language_code,
128
- "--audio_root_dir", "",
129
- "--output_path", OUTPUT_DIR,
130
  "--model_name", "seamless_expressivity",
131
  "--vocoder_name", "vocoder_pretssel",
132
- "--text_unk_blocking", "True",
133
- "--duration_factor", "1.0"
134
  ]
135
 
136
  subprocess.run(command, check=True)
137
 
138
- # Clean up the temporary TSV file
139
- os.unlink(temp_tsv.name)
140
-
141
  if os.path.exists(output_file):
142
  print(f"File created successfully: {output_file}")
143
  else:
 
10
  import random
11
  from openai import OpenAI
12
  import subprocess
 
13
 
14
  default_lang = "en"
15
 
 
97
  "Spanish": "spa",
98
  "French": "fra",
99
  "German": "deu",
100
+ "Italian": "ita",
101
+ "Chinese": "cmn"
102
  }
103
 
 
 
 
104
  def translate_speech(audio_file, target_language):
105
  """
106
+ Translate input speech (audio file) to the specified target language.
107
  """
108
  language_code = LANGUAGE_CODES[target_language]
109
+ output_file = "translated_audio.wav"
 
 
 
 
 
 
 
110
 
111
  command = [
112
+ "expressivity_predict",
113
+ audio_file,
 
 
114
  "--tgt_lang", language_code,
 
 
115
  "--model_name", "seamless_expressivity",
116
  "--vocoder_name", "vocoder_pretssel",
117
+ "--gated-model-dir", "seamlessmodel",
118
+ "--output_path", output_file
119
  ]
120
 
121
  subprocess.run(command, check=True)
122
 
 
 
 
123
  if os.path.exists(output_file):
124
  print(f"File created successfully: {output_file}")
125
  else: