VSPAN commited on
Commit
89df75e
·
verified ·
1 Parent(s): f9f89f2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -2
app.py CHANGED
@@ -4,7 +4,8 @@ import asyncio
4
  import tempfile
5
  import re
6
  import emoji
7
- from flask import Flask, request, jsonify, render_template_string
 
8
 
9
  app = Flask(__name__)
10
 
@@ -217,6 +218,7 @@ HTML_TEMPLATE = """
217
  @app.route('/get_voices', methods=['GET'])
218
  async def get_voices_route():
219
  voices = await get_voices()
 
220
  return jsonify(voices)
221
 
222
  @app.route('/tts', methods=['POST'])
@@ -229,8 +231,10 @@ async def tts_route():
229
 
230
  audio, warning = await text_to_speech(text, voice, rate, pitch)
231
  if warning:
 
232
  return jsonify({'warning': warning})
233
  else:
 
234
  return jsonify({'audio': audio})
235
 
236
  @app.route('/')
@@ -239,7 +243,13 @@ def index():
239
 
240
  @app.route('/music/<path:path>')
241
  def serve_music(path):
242
- return app.send_static_file(f'music/{path}')
 
 
 
 
 
 
243
 
244
  if __name__ == "__main__":
245
  app.run(debug=True)
 
4
  import tempfile
5
  import re
6
  import emoji
7
+ from flask import Flask, request, jsonify, render_template_string, send_from_directory, abort
8
+ import os
9
 
10
  app = Flask(__name__)
11
 
 
218
  @app.route('/get_voices', methods=['GET'])
219
  async def get_voices_route():
220
  voices = await get_voices()
221
+ app.logger.info(f"Voices: {voices}")
222
  return jsonify(voices)
223
 
224
  @app.route('/tts', methods=['POST'])
 
231
 
232
  audio, warning = await text_to_speech(text, voice, rate, pitch)
233
  if warning:
234
+ app.logger.warning(f"Warning: {warning}")
235
  return jsonify({'warning': warning})
236
  else:
237
+ app.logger.info(f"Audio file generated: {audio}")
238
  return jsonify({'audio': audio})
239
 
240
  @app.route('/')
 
243
 
244
  @app.route('/music/<path:path>')
245
  def serve_music(path):
246
+ music_path = os.path.join('music', path)
247
+ if os.path.exists(music_path):
248
+ app.logger.info(f"Serving music file: {music_path}")
249
+ return send_from_directory('music', path)
250
+ else:
251
+ app.logger.error(f"Music file not found: {music_path}")
252
+ return "Файл не найден", 404
253
 
254
  if __name__ == "__main__":
255
  app.run(debug=True)