smjain commited on
Commit
d4d5bd6
1 Parent(s): de7dce7

Upload myinfer_latest.py

Browse files
Files changed (1) hide show
  1. myinfer_latest.py +25 -6
myinfer_latest.py CHANGED
@@ -25,7 +25,7 @@ from pydub import AudioSegment
25
  import uuid
26
  from threading import Semaphore
27
  from threading import Lock
28
-
29
 
30
 
31
 
@@ -84,6 +84,8 @@ if os.path.isfile("rmvpe.pt"):
84
  f0method_mode.insert(2, "rmvpe")
85
  f0method_info = "PM is fast, Harvest is good but extremely slow, Rvmpe is alternative to harvest (might be better), and Crepe effect is good but requires GPU (Default: PM)"
86
 
 
 
87
  def load_hubert():
88
  global hubert_model
89
  models, _, _ = checkpoint_utils.load_model_ensemble_and_task(
@@ -168,7 +170,7 @@ def api_convert_voice():
168
  file = request.files['file']
169
  if file.filename == '':
170
  return jsonify({"error": "No selected file"}), 400
171
- created_files = []
172
  # Save the file to a temporary path
173
  unique_id = str(uuid.uuid4())
174
  print(unique_id)
@@ -177,7 +179,7 @@ def api_convert_voice():
177
  input_audio_path = os.path.join(tmp, f"{spk_id}_input_audio_{unique_id}.{filename.split('.')[-1]}")
178
  file.save(input_audio_path)
179
 
180
- created_files.append(input_audio_path)
181
 
182
  #split audio
183
  cut_vocal_and_inst(input_audio_path,spk_id,unique_id)
@@ -185,7 +187,16 @@ def api_convert_voice():
185
  vocal_path = f"output/{spk_id}_{unique_id}/{split_model}/{spk_id}_input_audio_{unique_id}/vocals.wav"
186
  inst = f"output/{spk_id}_{unique_id}/{split_model}/{spk_id}_input_audio_{unique_id}/no_vocals.wav"
187
  print("*****before making call to convert ", unique_id)
188
- output_path = convert_voice(spk_id, vocal_path, voice_transform,unique_id)
 
 
 
 
 
 
 
 
 
189
  output_path1= combine_vocal_and_inst(output_path,inst,unique_id)
190
 
191
  processed_audio_storage[unique_id] = output_path1
@@ -193,7 +204,7 @@ def api_convert_voice():
193
 
194
  print(output_path1)
195
 
196
- created_files.extend([vocal_path, inst, output_path])
197
  return jsonify({"message": "File processed successfully", "audio_id": unique_id}), 200
198
  finally:
199
  request_semaphore.release()
@@ -225,7 +236,15 @@ def get_processed_audio(audio_id):
225
  return send_file(file_path, as_attachment=True)
226
  return jsonify({"error": "File not found."}), 404
227
 
228
-
 
 
 
 
 
 
 
 
229
  def convert_voice(spk_id, input_audio_path, voice_transform,unique_id):
230
  get_vc(spk_id,0.5)
231
  print("*****before makinf call to vc ", unique_id)
 
25
  import uuid
26
  from threading import Semaphore
27
  from threading import Lock
28
+ from multiprocessing import Process, Queue
29
 
30
 
31
 
 
84
  f0method_mode.insert(2, "rmvpe")
85
  f0method_info = "PM is fast, Harvest is good but extremely slow, Rvmpe is alternative to harvest (might be better), and Crepe effect is good but requires GPU (Default: PM)"
86
 
87
+
88
+
89
  def load_hubert():
90
  global hubert_model
91
  models, _, _ = checkpoint_utils.load_model_ensemble_and_task(
 
170
  file = request.files['file']
171
  if file.filename == '':
172
  return jsonify({"error": "No selected file"}), 400
173
+ #created_files = []
174
  # Save the file to a temporary path
175
  unique_id = str(uuid.uuid4())
176
  print(unique_id)
 
179
  input_audio_path = os.path.join(tmp, f"{spk_id}_input_audio_{unique_id}.{filename.split('.')[-1]}")
180
  file.save(input_audio_path)
181
 
182
+ #created_files.append(input_audio_path)
183
 
184
  #split audio
185
  cut_vocal_and_inst(input_audio_path,spk_id,unique_id)
 
187
  vocal_path = f"output/{spk_id}_{unique_id}/{split_model}/{spk_id}_input_audio_{unique_id}/vocals.wav"
188
  inst = f"output/{spk_id}_{unique_id}/{split_model}/{spk_id}_input_audio_{unique_id}/no_vocals.wav"
189
  print("*****before making call to convert ", unique_id)
190
+ output_queue = Queue()
191
+
192
+ # Create and start the process
193
+ p = Process(target=worker, args=(spk_id, input_audio_path, voice_transform, unique_id, output_queue))
194
+ p.start()
195
+
196
+ # Wait for the process to finish and get the result
197
+ p.join()
198
+ output_path = output_queue.get()
199
+ #output_path = convert_voice(spk_id, vocal_path, voice_transform,unique_id)
200
  output_path1= combine_vocal_and_inst(output_path,inst,unique_id)
201
 
202
  processed_audio_storage[unique_id] = output_path1
 
204
 
205
  print(output_path1)
206
 
207
+ #created_files.extend([vocal_path, inst, output_path])
208
  return jsonify({"message": "File processed successfully", "audio_id": unique_id}), 200
209
  finally:
210
  request_semaphore.release()
 
236
  return send_file(file_path, as_attachment=True)
237
  return jsonify({"error": "File not found."}), 404
238
 
239
+ def worker(spk_id, input_audio_path, voice_transform, unique_id, output_queue):
240
+ """
241
+ Worker function to be executed in a separate process.
242
+ """
243
+ # Call the convert_voice function
244
+ output_audio_path = convert_voice(spk_id, input_audio_path, voice_transform, unique_id)
245
+
246
+ # Put the result in the queue to be retrieved by the main process
247
+ output_queue.put(output_audio_path)
248
  def convert_voice(spk_id, input_audio_path, voice_transform,unique_id):
249
  get_vc(spk_id,0.5)
250
  print("*****before makinf call to vc ", unique_id)