Spaces:
Sleeping
Sleeping
Upload infertest.py
Browse files17 unmodified lines1819202122232479 unmodified lines10410510610610710810911011111211310710810911511611711811912012112212312411011111211311411511611711811912012112612212312412517 unmodified linesimport base64import tempfileimport osimport werkzeugapp = Flask(__name__)
now_dir = os.getcwd()79 unmodified lines
@app.route('/convert_voice', methods=['POST'])def api_convert_voice(): data = request.json spk_id = data['spk_id'] #input_audio_path = data['input_audio_path'] voice_transform = data['voice_transform'] audio_data = data['audio'] # Base64-encoded audio data spk_id = request.form['spk_id'] voice_transform = request.form['voice_transform']
# Decode the base64 audio audio_bytes = base64.b64decode(audio_data) # Create a temporary file to save the decoded audio temp_audio_path = os.path.join(tmp, f"{spk_id}_input_audio.mp3") with open(temp_audio_path, 'wb') as temp_audio_file: temp_audio_file.write(audio_bytes) print(spk_id) # The file part if 'file' not in request.files: return jsonify({"error": "No file part"}), 400 file = request.files['file'] if file.filename == '': return jsonify({"error": "No selected file"}), 400
# Save the file to a temporary path filename = werkzeug.utils.secure_filename(file.filename) input_audio_path = os.path.join(TEMP_DIR, f"{spk_id}_input_audio.{filename.split('.')[-1]}") file.save(input_audio_path) output_path = convert_voice(spk_id, temp_audio_file, voice_transform) output_path = convert_voice(spk_id, input_audio_path, voice_transform) print(output_path) if os.path.exists(output_path): return send_file(output_path, as_attachment=True)infertest.py+15-19