File size: 3,470 Bytes
d673948
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
"""
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)

    badges = """
    <div style="display: flex">
    <span style="margin-right: 5px">

    [<img src="https://play.google.com/intl/en_us/badges/static/images/badges/en_badge_web_generic.png" width="200" height="77">](https://play.google.com/store/apps/details?id=com.app.vc)

    </span>
    </div>
    """

    with gr.Blocks() as demo:
        gr.Markdown(
            """
            <h1 align="center">Balacoon🦝 Voice Conversion</h1>


            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 providing your own audio files, please use WAVE PCM.
            Service works with 16kHz, 16 bit, mono audio.

            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)
            """
        )
        gr.Markdown(badges)

        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()