import RVC from scipy.io import wavfile import numpy as np import os import uuid import io import requests def get_models(): return RVC.names def single_run(input_audio0, model_name, vc_transform, opt_input="opt", f0method0 = "pm", filter_radius0 = 3, file_index1 = "", file_index2 = "", index_rate1 = 0.75, resample_sr0 = 0, rms_mix_rate0 = 0.25, protect0 = 0.33, f0_file = None): RVC.get_vc(model_name, protect0, protect0) spk_item = 0 # file_index2 = sorted(index_paths) # f0_file = gr.File(label=i18n("F0曲线文件, 可选, 一行一个音高, 代替默认F0及升降调")) vc_output1, vc_output2 = RVC.vc_single( spk_item, input_audio0, vc_transform, f0_file, f0method0, file_index1, file_index2, index_rate1, filter_radius0, resample_sr0, rms_mix_rate0, protect0 ) random_string = str(uuid.uuid4()) filename = os.path.basename(input_audio0) name, extension = os.path.splitext(filename) new_file_name = f"{name}_{random_string}{extension}" sample_rate, audio_data = vc_output2 # scaled_audio_data = np.int16(audio_data) # wavfile.write(new_file_name, sample_rate, scaled_audio_data) # response = requests.post(f"https://filebin.net/dajeii61xk3c4oxi/{new_file_name}" , files=files) url="https://filebin.net/dajeii61xk3c4oxi" print(upload_audio(url, audio_data, sample_rate, new_file_name)) return f"{url}/{new_file_name}" def upload_audio(url, audio_data, sample_rate, filename): try: # Convert audio data to WAV format in memory wav_bytes = io.BytesIO() scaled_audio_data = np.int16(audio_data) wavfile.write(wav_bytes, sample_rate, scaled_audio_data) wav_bytes.seek(0) files = {'file': (filename, wav_bytes)} response = requests.post(f"{url}/{filename}", files=files) response.raise_for_status() return response.json() except Exception as e: raise RuntimeError(f"Failed to upload audio: {e}") def uvr(dir_wav_input, wav_inputs = None, model_choose = RVC.uvr5_names[0], opt_vocal_root ="opt", opt_ins_root = "opt", format0 = "wav"): vc_output4 = RVC.uvr( dir_wav_input, ) for value in vc_output4: print(value) print(single_run("https://www.learningcontainer.com/wp-content/uploads/2020/02/Kalimba.mp3", "mymodelbilawal.pth", -2))