import gradio as gr import logging import os from TTS.api import TTS import time tts = TTS(model_name="voice_conversion_models/multilingual/vctk/freevc24", progress_bar=False, gpu=False) logging.basicConfig(level=logging.INFO) count = 0 def main(): global count count += 1 if count > 50: time.sleep(5) os.system("rm -R /tmp/*") count = 0 with gr.Blocks() as demo: with gr.Row(): with gr.Column(variant="panel"): src_audio_mic = gr.Audio(source="microphone", label="Record your voice") src_audio_file = gr.Audio( source="upload", type="filepath", label="Or upload audio to convert" ) with gr.Column(variant="panel"): tgt_audio_file = gr.Audio( source="upload", type="filepath", label="Select audio with target voice" ) with gr.Row(): convert_btn = gr.Button("Convert") with gr.Row(): result_audio = gr.Audio() def voice_conversion(src_from_mic_, src_from_file_, tgt_from_file_): """ helper function which checks where source come from """ src_ = None if src_from_mic_: src_ = src_from_mic_ elif src_from_file_: src_ = src_from_file_ tgt_ = tgt_from_file_ if not src_ or not tgt_: logging.warning("source or target are not provided") return print(src_) print(tgt_) tts.voice_conversion_to_file(source_wav=src_, target_wav=tgt_, file_path="output.wav") return "output.wav" convert_btn.click( voice_conversion, inputs=[src_audio_mic, src_audio_file, tgt_audio_file], outputs=result_audio, ) demo.queue(concurrency_count=1).launch(show_api=False, show_error=True) if __name__ == "__main__": main()