File size: 2,029 Bytes
05005db
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89e3b9d
 
 
 
05005db
 
 
 
 
 
17d49c8
 
05005db
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import gradio as gr
import logging
import yaml
import soundfile as sf
import os
from pathlib import Path
from vec2wav2.bin.vc import VoiceConverter, configure_logging, vc_args

# Create Gradio interface
def create_interface():
    args = vc_args()
    logger = configure_logging(args.verbose)
    voice_converter = VoiceConverter(
        expdir=args.expdir,
        token_extractor=args.token_extractor,
        prompt_extractor=args.prompt_extractor,
        prompt_output_layer=args.prompt_output_layer,
        checkpoint=args.checkpoint, 
        script_logger=logger
    )
    with gr.Blocks(title="Voice Conversion") as demo:
        gr.Markdown("# vec2wav 2.0 Voice Conversion Demo")
        gr.Markdown("Upload source audio and target speaker audio to convert the voice.")
        gr.Markdown("MPEG format is not supported. Please convert it to **WAV** format before uploading.")
        gr.Markdown("Note that this space is running on a free CPU server. We recommend running this locally for faster results.")
        gr.Markdown("For more information, visit the [vec2wav 2.0 GitHub repository](https://github.com/cantabile-kwok/vec2wav2.0).")
        
        with gr.Row():
            source_audio = gr.Audio(label="Source Audio", type="filepath")
            target_audio = gr.Audio(label="Target Speaker Audio", type="filepath")
        
        examples = [
            ["examples/TheresaMay.wav", "examples/OptimusPrime.wav"],
            ["examples/Zuckerberg.wav", "examples/Rachel.wav"]
        ]
        gr.Examples(examples, label="Examples", inputs=[source_audio, target_audio])

        convert_btn = gr.Button("Convert Voice")
        output_audio = gr.Audio(label="Converted Audio")

        convert_btn.click(
            fn=voice_converter.voice_conversion,
            inputs=[source_audio, target_audio],
            outputs=output_audio
        )

    return demo

if __name__ == "__main__":
    demo = create_interface()
    demo.launch(share=True)