Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -12,7 +12,7 @@ app = Flask(__name__)
|
|
12 |
|
13 |
# Define los nombres asignados a modelos específicos, en caso de no existir no se muestran
|
14 |
model_names = {
|
15 |
-
|
16 |
"model_path": "es_ES-kamora-7539-high.onnx",
|
17 |
"replacements": [('\n', '. ')]
|
18 |
},
|
@@ -44,20 +44,32 @@ def filter_text(text, model_name):
|
|
44 |
logging.error(f"No se encontró el modelo '{model_name}'.")
|
45 |
return None
|
46 |
|
|
|
47 |
# Define una función para convertir texto a voz
|
48 |
def convert_text_to_speech(text, model_name):
|
49 |
filtered_text = filter_text(text, model_name)[:500] # Limitar el texto a 500 caracteres
|
50 |
if filtered_text is None:
|
51 |
return None
|
52 |
|
53 |
-
|
54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
|
56 |
@app.route('/')
|
57 |
def index():
|
58 |
-
|
59 |
-
|
60 |
-
|
|
|
61 |
return render_template('index.html', model_options=model_options)
|
62 |
|
63 |
@app.route('/convert', methods=['POST'])
|
@@ -70,9 +82,9 @@ def convert_text():
|
|
70 |
def remove_file(response):
|
71 |
try:
|
72 |
os.remove(output_file)
|
73 |
-
|
74 |
except Exception as error:
|
75 |
-
|
76 |
return response
|
77 |
|
78 |
with open(output_file, 'rb') as audio_file:
|
|
|
12 |
|
13 |
# Define los nombres asignados a modelos específicos, en caso de no existir no se muestran
|
14 |
model_names = {
|
15 |
+
"Español México | Kamora Neuronal": {
|
16 |
"model_path": "es_ES-kamora-7539-high.onnx",
|
17 |
"replacements": [('\n', '. ')]
|
18 |
},
|
|
|
44 |
logging.error(f"No se encontró el modelo '{model_name}'.")
|
45 |
return None
|
46 |
|
47 |
+
|
48 |
# Define una función para convertir texto a voz
|
49 |
def convert_text_to_speech(text, model_name):
|
50 |
filtered_text = filter_text(text, model_name)[:500] # Limitar el texto a 500 caracteres
|
51 |
if filtered_text is None:
|
52 |
return None
|
53 |
|
54 |
+
random_name = ''.join(random.choices(string.ascii_letters + string.digits, k=8)) + '.wav'
|
55 |
+
output_file = os.path.join(file_folder, random_name)
|
56 |
+
app.logger.info("Audio file created at: %s", output_file)
|
57 |
+
piper_exe = os.path.join(file_folder, 'piper') # Adjusted the path for piper
|
58 |
+
|
59 |
+
if os.path.isfile(piper_exe):
|
60 |
+
comando = f'echo {filtered_text} | "{piper_exe}" -m {model_name} -f {output_file}'
|
61 |
+
subprocess.run(comando, shell=True)
|
62 |
+
return output_file
|
63 |
+
else:
|
64 |
+
return "The piper.exe file was not found in the correct directory."
|
65 |
+
|
66 |
|
67 |
@app.route('/')
|
68 |
def index():
|
69 |
+
model_folder = file_folder # Adjusted the model folder to file_folder
|
70 |
+
model_options = [file for file in os.listdir(model_folder) if file.endswith('.onnx')]
|
71 |
+
# Log the contents of the current folder
|
72 |
+
app.logger.info("Contents of current folder: %s", os.listdir(file_folder))
|
73 |
return render_template('index.html', model_options=model_options)
|
74 |
|
75 |
@app.route('/convert', methods=['POST'])
|
|
|
82 |
def remove_file(response):
|
83 |
try:
|
84 |
os.remove(output_file)
|
85 |
+
app.logger.info("Audio file deleted: %s", output_file)
|
86 |
except Exception as error:
|
87 |
+
app.logger.error("Error deleting file: %s", error)
|
88 |
return response
|
89 |
|
90 |
with open(output_file, 'rb') as audio_file:
|