HirCoir commited on
Commit
9bd30eb
1 Parent(s): 28871b0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -21
app.py CHANGED
@@ -6,6 +6,7 @@ import os
6
  import random
7
  import string
8
  import re
 
9
 
10
  app = Flask(__name__)
11
 
@@ -20,7 +21,7 @@ models_replacements = {
20
  },
21
  "Español México | Kamora Neuronal": {
22
  "model_path": "kamora.onnx",
23
- "replacements": [('\n', '')] # Modified to remove newlines
24
  },
25
  "Español México | Claude": {
26
  "model_path": "es_MX-claude-14947-epoch-high.onnx",
@@ -40,24 +41,10 @@ models_replacements = {
40
  }
41
  }
42
 
43
- def filter_text(text, replacements):
44
- for replacement in replacements:
45
- text = text.replace(replacement[0], replacement[1])
46
- # Agrega una barra invertida adicional antes de cada caracter especial
47
- special_chars = ['"', "'", '\\']
48
- for char in special_chars:
49
- text = text.replace(char, '\\' + char)
50
- # Elimina los saltos de línea
51
- text = text.replace('\n', '')
52
- # Define una función de reemplazo usando una función lambda
53
- replace_func = lambda m: "\\" + m.group(0)
54
- # Crea una expresión regular con los caracteres que deseas reemplazar
55
- regex_pattern = r'(["\'])'
56
- # Realiza el reemplazo utilizando la función sub de re
57
- filtered_text = re.sub(regex_pattern, replace_func, text)
58
- return filtered_text
59
-
60
-
61
 
62
  def convert_text_to_speech(parrafo, model):
63
  # Limit text to 500 characters
@@ -66,8 +53,7 @@ def convert_text_to_speech(parrafo, model):
66
  model_info = models_replacements.get(model)
67
  if model_info:
68
  model_path = model_info.get("model_path")
69
- replacements = model_info.get("replacements")
70
- parrafo_filtrado = filter_text(parrafo, replacements)
71
  random_name = ''.join(random.choices(string.ascii_letters + string.digits, k=8)) + '.wav'
72
  output_file = os.path.join(file_folder, random_name)
73
  app.logger.info("Audio file created at: %s", output_file)
 
6
  import random
7
  import string
8
  import re
9
+ import shlex
10
 
11
  app = Flask(__name__)
12
 
 
21
  },
22
  "Español México | Kamora Neuronal": {
23
  "model_path": "kamora.onnx",
24
+ "replacements": [('\n', '')]
25
  },
26
  "Español México | Claude": {
27
  "model_path": "es_MX-claude-14947-epoch-high.onnx",
 
41
  }
42
  }
43
 
44
+ def filter_text(text):
45
+ # Escapa caracteres especiales
46
+ escaped_text = shlex.quote(text)
47
+ return escaped_text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
 
49
  def convert_text_to_speech(parrafo, model):
50
  # Limit text to 500 characters
 
53
  model_info = models_replacements.get(model)
54
  if model_info:
55
  model_path = model_info.get("model_path")
56
+ parrafo_filtrado = filter_text(parrafo)
 
57
  random_name = ''.join(random.choices(string.ascii_letters + string.digits, k=8)) + '.wav'
58
  output_file = os.path.join(file_folder, random_name)
59
  app.logger.info("Audio file created at: %s", output_file)