""" Copyright 2023 Balacoon Voice Conversion service interactive demo """ import glob import logging import os import gradio as gr from vc_service_request import vc_service_request script_dir = os.path.dirname(os.path.abspath(__file__)) def main(): logging.basicConfig(level=logging.INFO) with gr.Blocks() as demo: gr.Markdown( """

Balacoon🦝 Voice Conversion

Welcome to the live demo of Balacoon's Voice Conversion service. Check out our [website](https://balacoon.com/demo/#voice-conversion) to learn more. Voice Conversion allows you to transform your own voice into the voice of another person using just a single sample. For optimal results, we recommend using clean audio files in English. Here's how it works: 1. Begin by recording your voice. 2. Select an audio sample that represents the target voice you want to convert to. 3. Click the "Convert" button and listen to the result! If you are interested to plug in Voice Conversion service into your own application, don't hesitate to get in touch with us at [contact@balacoon.com](mailto:contact@balacoon.com) """ ) 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", label="Or upload audio to convert" ) with gr.Column(variant="panel"): tgt_audio_file = gr.Audio( source="upload", label="Select audio with target voice" ) tgt_examples_paths = glob.glob( os.path.join(script_dir, "references", "*.wav") ) gr.Examples( tgt_examples_paths, inputs=[tgt_audio_file], ) 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 return vc_service_request(src_, tgt_) convert_btn.click( voice_conversion, inputs=[src_audio_mic, src_audio_file, tgt_audio_file], outputs=result_audio, ) demo.queue(concurrency_count=1).launch() if __name__ == "__main__": main()