import RVC from scipy.io import wavfile import numpy as np import os import uuid import io import requests class VoiceConverter: def __init__(self): self.models = RVC.names def single_run(self, input_audio, model_name, vc_transform, song, opt_input="opt", f0_method="crepe", filter_radius=3, file_index1="", file_index2="", index_rate1=0.75, resample_sr=0, rms_mix_rate=0.25, protect=0.33, f0_file=None): RVC.get_vc(model_name, protect, protect) spk_item = 0 vc_output1, vc_output2 = RVC.vc_single( spk_item, input_audio, vc_transform, f0_file, f0_method, file_index1, file_index2, index_rate1, filter_radius, resample_sr, rms_mix_rate, protect, song ) random_string = str(uuid.uuid4()) filename = os.path.basename(input_audio) name, extension = os.path.splitext(filename) new_file_name = f"{name}_{random_string}{extension}" sample_rate, audio_data = vc_output2 url = self.upload_audio(audio_data, sample_rate, new_file_name) return url def upload_audio(self, audio_data, sample_rate, filename): try: url = "https://tmpfiles.org/api/v1/upload" # 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(url, files=files) response.raise_for_status() return response.json() except Exception as e: raise RuntimeError(f"Failed to upload audio: {e}") def uvr(self, dir_wav_input, wav_inputs=None, model_choose=RVC.uvr5_names[0], opt_vocal_root="opt", opt_ins_root="opt", format0="wav"): agg = 10 vc_output4 = RVC.uvr( model_choose, dir_wav_input, opt_vocal_root, wav_inputs, opt_ins_root, agg, format0 ) for value in vc_output4: print(value) # converter.uvr('/home/teewhy/Downloads/around_the_world-atc.wav')