smjain commited on
Commit
5a065a9
1 Parent(s): 54230e1

Upload infertest.py

Browse files
Files changed (1) hide show
  1. 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
- data = request.json
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
- # Decode the base64 audio
116
- audio_bytes = base64.b64decode(audio_data)
117
-
118
- # Create a temporary file to save the decoded audio
119
- temp_audio_path = os.path.join(tmp, f"{spk_id}_input_audio.mp3")
120
-
121
- with open(temp_audio_path, 'wb') as temp_audio_file:
122
- temp_audio_file.write(audio_bytes)
123
- print(spk_id)
124
-
 
125
 
126
- output_path = convert_voice(spk_id, temp_audio_file, voice_transform)
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)