HirCoir commited on
Commit
811ad8f
1 Parent(s): d8ee0f6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -10
app.py CHANGED
@@ -9,6 +9,9 @@ import re
9
 
10
  app = Flask(__name__)
11
 
 
 
 
12
  def filter_text(text):
13
  filtered_text = re.sub(r'[^\w\s,.\(\):\u00C0-\u00FF]', '', text)
14
  filtered_text = filtered_text.replace('\n', ' ')
@@ -17,22 +20,21 @@ def filter_text(text):
17
 
18
  def convert_text_to_speech(parrafo, model):
19
  parrafo_filtrado = filter_text(parrafo)
20
- bundle_dir = os.path.abspath(os.path.dirname(__file__))
21
- random_name = '/app/'.join(random.choices(string.ascii_letters + string.digits, k=8)) + '.wav'
22
- output_file = os.path.join('.', random_name)
23
- app.logger.info("Archivo de audio creado en: %s", output_file)
24
- piper_exe = os.path.join(bundle_dir, './piper')
25
 
26
  if os.path.isfile(piper_exe):
27
  comando = f'echo {parrafo_filtrado} | "{piper_exe}" -m {model} -f {output_file}'
28
  subprocess.run(comando, shell=True)
29
  return output_file
30
  else:
31
- return "El archivo piper.exe no se encontró en el directorio correcto."
32
 
33
  @app.route('/')
34
  def index():
35
- model_folder = os.path.join('./')
36
  model_options = [file for file in os.listdir(model_folder) if file.endswith('.onnx')]
37
  return render_template('index.html', model_options=model_options)
38
 
@@ -46,9 +48,9 @@ def convert_text():
46
  def remove_file(response):
47
  try:
48
  os.remove(output_file)
49
- app.logger.info("Archivo de audio eliminado: %s", output_file)
50
  except Exception as error:
51
- app.logger.error("Error eliminando el archivo: %s", error)
52
  return response
53
 
54
  with open(output_file, 'rb') as audio_file:
@@ -60,6 +62,5 @@ def convert_text():
60
 
61
  return response
62
 
63
-
64
  if __name__ == '__main__':
65
  app.run(host='0.0.0.0', port=7860, debug=False)
 
9
 
10
  app = Flask(__name__)
11
 
12
+ # Define the folder where files are saved
13
+ file_folder = '/app/'
14
+
15
  def filter_text(text):
16
  filtered_text = re.sub(r'[^\w\s,.\(\):\u00C0-\u00FF]', '', text)
17
  filtered_text = filtered_text.replace('\n', ' ')
 
20
 
21
  def convert_text_to_speech(parrafo, model):
22
  parrafo_filtrado = filter_text(parrafo)
23
+ random_name = ''.join(random.choices(string.ascii_letters + string.digits, k=8)) + '.wav'
24
+ output_file = os.path.join(file_folder, random_name)
25
+ app.logger.info("Audio file created at: %s", output_file)
26
+ piper_exe = os.path.join(file_folder, 'piper')
 
27
 
28
  if os.path.isfile(piper_exe):
29
  comando = f'echo {parrafo_filtrado} | "{piper_exe}" -m {model} -f {output_file}'
30
  subprocess.run(comando, shell=True)
31
  return output_file
32
  else:
33
+ return "The piper.exe file was not found in the correct directory."
34
 
35
  @app.route('/')
36
  def index():
37
+ model_folder = os.path.join(file_folder)
38
  model_options = [file for file in os.listdir(model_folder) if file.endswith('.onnx')]
39
  return render_template('index.html', model_options=model_options)
40
 
 
48
  def remove_file(response):
49
  try:
50
  os.remove(output_file)
51
+ app.logger.info("Audio file deleted: %s", output_file)
52
  except Exception as error:
53
+ app.logger.error("Error deleting file: %s", error)
54
  return response
55
 
56
  with open(output_file, 'rb') as audio_file:
 
62
 
63
  return response
64
 
 
65
  if __name__ == '__main__':
66
  app.run(host='0.0.0.0', port=7860, debug=False)