File size: 1,657 Bytes
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
#!/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.")
        
        with gr.Row():
            source_audio = gr.Audio(label="Source Audio", type="filepath")
            target_audio = gr.Audio(label="Target Speaker Audio", type="filepath")
        
        examples = [
            ["examples/Zuckerberg.wav", "examples/Rachel.wav"],
            ["examples/TheresaMay.wav", "examples/OptimusPrime.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)