Spaces:
Runtime error
Runtime error
StormblessedKal
commited on
Commit
•
42fe613
1
Parent(s):
508fd98
debug_1
Browse files- src/__pycache__/predict.cpython-310.pyc +0 -0
- src/__pycache__/se_extractor.cpython-310.pyc +0 -0
- src/predict.py +62 -82
- src/rp_handler.py +2 -0
src/__pycache__/predict.cpython-310.pyc
CHANGED
Binary files a/src/__pycache__/predict.cpython-310.pyc and b/src/__pycache__/predict.cpython-310.pyc differ
|
|
src/__pycache__/se_extractor.cpython-310.pyc
CHANGED
Binary files a/src/__pycache__/se_extractor.cpython-310.pyc and b/src/__pycache__/se_extractor.cpython-310.pyc differ
|
|
src/predict.py
CHANGED
@@ -260,63 +260,7 @@ class Predictor:
|
|
260 |
return {"voice_clone_1":f"https://demovidelyusergenerations.s3.amazonaws.com/{gen_id}-voice-clone-1.mp3",
|
261 |
"voice_clone_2":f"https://demovidelyusergenerations.s3.amazonaws.com/{gen_id}-voice-clone-2.mp3"
|
262 |
}
|
263 |
-
if method_type == 'voice_clone_with_emotions':
|
264 |
-
try:
|
265 |
-
print("INSIDE emotions")
|
266 |
-
base_speaker_tts,tone_color_converter = self.base_speaker_tts,self.tone_color_converter
|
267 |
-
reference_speaker = local_file_path
|
268 |
-
print("here 1")
|
269 |
-
target_se, audio_name = se_extractor.get_se(reference_speaker, tone_color_converter, target_dir=openvoice_dir, vad=False)
|
270 |
-
print("here 2")
|
271 |
-
src_path = os.path.join(results_dir,f"{gen_id}-tmp-emotions.wav")
|
272 |
-
openvoice_output = os.path.join(results_dir,f"{gen_id}-4.wav")
|
273 |
-
base_speaker_tts.tts(passage,src_path,speaker='default',language='English',speed=1.0,use_emotions=True)
|
274 |
-
source_se = torch.load(f'{self.ckpt_base}/en_style_se.pth').to(self.device)
|
275 |
-
tone_color_converter.convert(audio_src_path=src_path,src_se=source_se,tgt_se=target_se,output_path=openvoice_output,message='')
|
276 |
-
if process_audio:
|
277 |
-
(new_sr, wav1) = self._fn(openvoice_output,"Midpoint",32,0.5)
|
278 |
-
sf.write(openvoice_output,wav1,new_sr)
|
279 |
-
|
280 |
-
mp3_final_output_1 = str(openvoice_output).replace('wav','mp3')
|
281 |
-
self.convert_wav_to_mp3(openvoice_output,mp3_final_output_1)
|
282 |
-
print(mp3_final_output_1)
|
283 |
-
self.upload_file_to_s3(mp3_final_output_1,'demovidelyusergenerations',f"{gen_id}-voice-with-emotions.mp3")
|
284 |
-
shutil.rmtree(os.path.join(output_dir,gen_id))
|
285 |
-
return {"voice_clone_with_emotions":f"https://demovidelyusergenerations.s3.amazonaws.com/{gen_id}-voice-with-emotions.mp3"
|
286 |
-
}
|
287 |
-
except Exception as e:
|
288 |
-
return {"error":f"Unexpected error{e}"}
|
289 |
-
if method_type == 'voice_clone_with_multi_lang':
|
290 |
-
print("Inside multilang")
|
291 |
-
#voice clone with multi-lingugal
|
292 |
-
_,tone_color_converter = self.base_speaker_tts,self.tone_color_converter
|
293 |
-
reference_speaker = local_file_path
|
294 |
-
target_se, audio_name = se_extractor.get_se(reference_speaker, tone_color_converter, target_dir=openvoice_dir, vad=False)
|
295 |
-
src_path = 'openai_source_output.mp3'
|
296 |
-
source_se, audio_name = se_extractor.get_se(src_path, tone_color_converter, vad=True)
|
297 |
-
|
298 |
|
299 |
-
client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))
|
300 |
-
response = client.audio.speech.create(
|
301 |
-
model="tts-1",
|
302 |
-
voice="fable",
|
303 |
-
input=passage
|
304 |
-
)
|
305 |
-
|
306 |
-
openai_multi_lang_path = os.path.join(results_dir,f"{gen_id}-openai-gen.wav")
|
307 |
-
response.stream_to_file(openai_multi_lang_path)
|
308 |
-
multi_lang_with_voice_clone_path = os.path.join(results_dir,f"{gen_id}-voice-clone-multi-lang.wav")
|
309 |
-
|
310 |
-
source_se, audio_name = se_extractor.get_se(src_path, tone_color_converter, vad=True)
|
311 |
-
self.tone_color_converter.convert(audio_src_path=openai_multi_lang_path, src_se=source_se, tgt_se=target_se, output_path=multi_lang_with_voice_clone_path,message='')
|
312 |
-
|
313 |
-
mp3_final_output_1 = str(multi_lang_with_voice_clone_path).replace('wav','mp3')
|
314 |
-
self.convert_wav_to_mp3(multi_lang_with_voice_clone_path,mp3_final_output_1)
|
315 |
-
print(mp3_final_output_1)
|
316 |
-
self.upload_file_to_s3(mp3_final_output_1,'demovidelyusergenerations',f"{gen_id}-voice-clone-multi-lang.mp3")
|
317 |
-
shutil.rmtree(os.path.join(output_dir,gen_id))
|
318 |
-
return {"voice_clone_with_emotions":f"https://demovidelyusergenerations.s3.amazonaws.com/{gen_id}-voice-clone-multi-lang.mp3"
|
319 |
-
}
|
320 |
|
321 |
|
322 |
|
@@ -336,32 +280,68 @@ class Predictor:
|
|
336 |
s3_key = s3_url.split('/')[-1]
|
337 |
bucket_name = 'demovidelyuseruploads'
|
338 |
local_file_path = os.path.join(raw_dir,s3_key)
|
339 |
-
self.download_file_from_s3(self.s3_client,bucket_name,s3_key,local_file_path)
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
365 |
|
366 |
def _fn(self,path, solver, nfe, tau):
|
367 |
if path is None:
|
|
|
260 |
return {"voice_clone_1":f"https://demovidelyusergenerations.s3.amazonaws.com/{gen_id}-voice-clone-1.mp3",
|
261 |
"voice_clone_2":f"https://demovidelyusergenerations.s3.amazonaws.com/{gen_id}-voice-clone-2.mp3"
|
262 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
263 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
264 |
|
265 |
|
266 |
|
|
|
280 |
s3_key = s3_url.split('/')[-1]
|
281 |
bucket_name = 'demovidelyuseruploads'
|
282 |
local_file_path = os.path.join(raw_dir,s3_key)
|
283 |
+
self.download_file_from_s3(self.s3_client,bucket_name,s3_key,local_file_path)
|
284 |
+
#voice_clone with styletts2
|
285 |
+
model,sampler = self.model,self.sampler
|
286 |
+
result = self.process_audio_file(local_file_path,passage,model,sampler)
|
287 |
+
|
288 |
+
base_speaker_tts,tone_color_converter = self.base_speaker_tts,self.tone_color_converter
|
289 |
+
reference_speaker = local_file_path
|
290 |
+
target_se, audio_name = se_extractor.get_se(reference_speaker, tone_color_converter, target_dir=openvoice_dir, vad=False)
|
291 |
+
src_path = os.path.join(results_dir,f"{gen_id}-tmp.wav")
|
292 |
+
openvoice_output = os.path.join(results_dir,f"{gen_id}-voice-clone-2.wav")
|
293 |
+
base_speaker_tts.tts(passage,src_path,speaker='default',language='English',speed=1.0)
|
294 |
+
return {"status":"Done"}
|
295 |
+
|
296 |
+
|
297 |
+
def predict_with_multi_lang(self,s3_url,passage,process_audio):
|
298 |
+
print("In multi lang voice cloning")
|
299 |
+
output_dir = 'processed'
|
300 |
+
gen_id = str(uuid.uuid4())
|
301 |
+
os.makedirs(output_dir,exist_ok=True)
|
302 |
+
raw_dir = os.path.join(output_dir,gen_id,'raw')
|
303 |
+
segments_dir = os.path.join(output_dir,gen_id,'segments')
|
304 |
+
results_dir = os.path.join(output_dir,gen_id,'results')
|
305 |
+
openvoice_dir = os.path.join(output_dir,gen_id,'openvoice')
|
306 |
+
os.makedirs(raw_dir)
|
307 |
+
os.makedirs(segments_dir)
|
308 |
+
os.makedirs(results_dir)
|
309 |
+
|
310 |
+
|
311 |
+
s3_key = s3_url.split('/')[-1]
|
312 |
+
bucket_name = 'demovidelyuseruploads'
|
313 |
+
local_file_path = os.path.join(raw_dir,s3_key)
|
314 |
+
self.download_file_from_s3(self.s3_client,bucket_name,s3_key,local_file_path)
|
315 |
+
|
316 |
+
_,tone_color_converter = self.base_speaker_tts,self.tone_color_converter
|
317 |
+
reference_speaker = local_file_path
|
318 |
+
target_se, audio_name = se_extractor.get_se(reference_speaker, tone_color_converter, target_dir=openvoice_dir, vad=False)
|
319 |
+
src_path = 'openai_source_output.mp3'
|
320 |
+
source_se, audio_name = se_extractor.get_se(src_path, tone_color_converter, vad=True)
|
321 |
+
|
322 |
+
|
323 |
+
client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))
|
324 |
+
response = client.audio.speech.create(
|
325 |
+
model="tts-1",
|
326 |
+
voice="fable",
|
327 |
+
input=passage
|
328 |
+
)
|
329 |
+
|
330 |
+
openai_multi_lang_path = os.path.join(results_dir,f"{gen_id}-openai-gen.wav")
|
331 |
+
response.stream_to_file(openai_multi_lang_path)
|
332 |
+
multi_lang_with_voice_clone_path = os.path.join(results_dir,f"{gen_id}-voice-clone-multi-lang.wav")
|
333 |
+
|
334 |
+
source_se, audio_name = se_extractor.get_se(src_path, tone_color_converter, vad=True)
|
335 |
+
self.tone_color_converter.convert(audio_src_path=openai_multi_lang_path, src_se=source_se, tgt_se=target_se, output_path=multi_lang_with_voice_clone_path,message='')
|
336 |
+
|
337 |
+
mp3_final_output_1 = str(multi_lang_with_voice_clone_path).replace('wav','mp3')
|
338 |
+
self.convert_wav_to_mp3(multi_lang_with_voice_clone_path,mp3_final_output_1)
|
339 |
+
print(mp3_final_output_1)
|
340 |
+
self.upload_file_to_s3(mp3_final_output_1,'demovidelyusergenerations',f"{gen_id}-voice-clone-multi-lang.mp3")
|
341 |
+
shutil.rmtree(os.path.join(output_dir,gen_id))
|
342 |
+
return {"voice_clone_with_emotions":f"https://demovidelyusergenerations.s3.amazonaws.com/{gen_id}-voice-clone-multi-lang.mp3"
|
343 |
+
}
|
344 |
+
|
345 |
|
346 |
def _fn(self,path, solver, nfe, tau):
|
347 |
if path is None:
|
src/rp_handler.py
CHANGED
@@ -53,6 +53,8 @@ def run_voice_clone_job(job):
|
|
53 |
result = MODEL.predict(s3_url,passage,process_audio)
|
54 |
if method_type == 'voice_clone_with_emotions':
|
55 |
result = MODEL.predict_with_emotions(s3_url,passage,process_audio)
|
|
|
|
|
56 |
|
57 |
return result
|
58 |
|
|
|
53 |
result = MODEL.predict(s3_url,passage,process_audio)
|
54 |
if method_type == 'voice_clone_with_emotions':
|
55 |
result = MODEL.predict_with_emotions(s3_url,passage,process_audio)
|
56 |
+
if method_type == 'voice_clone_with_multi_lang':
|
57 |
+
result = MODEL.predict_with_multi_lang(s3_url,passage,process_audio)
|
58 |
|
59 |
return result
|
60 |
|