pluviouse commited on
Commit
e239ad9
·
verified ·
1 Parent(s): eea0cdd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -2
app.py CHANGED
@@ -3,6 +3,7 @@ from io import BytesIO
3
  from flask import Flask, request, jsonify, render_template, send_file, Response
4
  from bs4 import BeautifulSoup
5
  from scraper import voicevox
 
6
  import requests
7
 
8
  app = Flask(__name__)
@@ -15,17 +16,22 @@ def index():
15
  def voicevox_resp():
16
  text = request.args.get("text")
17
  speaker = request.args.get("speaker")
 
18
  if text is None:
19
  return jsonify({'error': "Please provided parameter 'text'"}), 400
20
  if speaker is None:
21
  speaker = 1
 
22
 
23
 
24
  try:
25
  data = voicevox(text, speaker=speaker)
26
  io = BytesIO(data)
27
-
28
- return send_file(io, as_attachment=True, mimetype="audio/mp3", download_name=f'rull-pyward_voicevox({text.strip()}).mp3')
 
 
 
29
  except Exception as e:
30
  return jsonify({'error': "Internal server error"}), 500
31
 
 
3
  from flask import Flask, request, jsonify, render_template, send_file, Response
4
  from bs4 import BeautifulSoup
5
  from scraper import voicevox
6
+ from utils import mp3_to_opus
7
  import requests
8
 
9
  app = Flask(__name__)
 
16
  def voicevox_resp():
17
  text = request.args.get("text")
18
  speaker = request.args.get("speaker")
19
+ opus = request.args.get("opus") == True
20
  if text is None:
21
  return jsonify({'error': "Please provided parameter 'text'"}), 400
22
  if speaker is None:
23
  speaker = 1
24
+
25
 
26
 
27
  try:
28
  data = voicevox(text, speaker=speaker)
29
  io = BytesIO(data)
30
+ if opus:
31
+ io = mp3_to_opus(io)
32
+ mime = "audio/opus" if opus else "audio/mp3"
33
+ ext = ".opus" if opus else ".mp3"
34
+ return send_file(io, as_attachment=True, mimetype=mime, download_name=f'rull-pyward_voicevox({text.strip()}){ext}')
35
  except Exception as e:
36
  return jsonify({'error': "Internal server error"}), 500
37