Spaces:
Sleeping
Sleeping
Upload infertest.py
Browse files- infertest.py +15 -19
infertest.py
CHANGED
|
@@ -18,6 +18,7 @@ from flask import Flask, request, jsonify, send_file
|
|
| 18 |
import base64
|
| 19 |
import tempfile
|
| 20 |
import os
|
|
|
|
| 21 |
app = Flask(__name__)
|
| 22 |
|
| 23 |
now_dir = os.getcwd()
|
|
@@ -103,27 +104,22 @@ def clean():
|
|
| 103 |
|
| 104 |
@app.route('/convert_voice', methods=['POST'])
|
| 105 |
def api_convert_voice():
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
spk_id = data['spk_id']
|
| 109 |
-
#input_audio_path = data['input_audio_path']
|
| 110 |
-
voice_transform = data['voice_transform']
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
audio_data = data['audio'] # Base64-encoded audio data
|
| 114 |
|
| 115 |
-
#
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
|
|
|
| 125 |
|
| 126 |
-
output_path = convert_voice(spk_id,
|
| 127 |
print(output_path)
|
| 128 |
if os.path.exists(output_path):
|
| 129 |
return send_file(output_path, as_attachment=True)
|
|
|
|
| 18 |
import base64
|
| 19 |
import tempfile
|
| 20 |
import os
|
| 21 |
+
import werkzeug
|
| 22 |
app = Flask(__name__)
|
| 23 |
|
| 24 |
now_dir = os.getcwd()
|
|
|
|
| 104 |
|
| 105 |
@app.route('/convert_voice', methods=['POST'])
|
| 106 |
def api_convert_voice():
|
| 107 |
+
spk_id = request.form['spk_id']
|
| 108 |
+
voice_transform = request.form['voice_transform']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
|
| 110 |
+
# The file part
|
| 111 |
+
if 'file' not in request.files:
|
| 112 |
+
return jsonify({"error": "No file part"}), 400
|
| 113 |
+
file = request.files['file']
|
| 114 |
+
if file.filename == '':
|
| 115 |
+
return jsonify({"error": "No selected file"}), 400
|
| 116 |
+
|
| 117 |
+
# Save the file to a temporary path
|
| 118 |
+
filename = werkzeug.utils.secure_filename(file.filename)
|
| 119 |
+
input_audio_path = os.path.join(TEMP_DIR, f"{spk_id}_input_audio.{filename.split('.')[-1]}")
|
| 120 |
+
file.save(input_audio_path)
|
| 121 |
|
| 122 |
+
output_path = convert_voice(spk_id, input_audio_path, voice_transform)
|
| 123 |
print(output_path)
|
| 124 |
if os.path.exists(output_path):
|
| 125 |
return send_file(output_path, as_attachment=True)
|