File size: 916 Bytes
853cf78
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0dabde8
853cf78
 
 
 
0dabde8
853cf78
 
 
 
 
 
 
 
 
 
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
import torch
from dreamvoice import DreamVoice_Plugin
from dreamvoice.openvoice_utils import se_extractor
from openvoice.api import ToneColorConverter


# init dreamvoice
dreamvoice = DreamVoice_Plugin(device='cuda')

# init openvoice
ckpt_converter = 'checkpoints_v2/converter'
device = "cuda:0" if torch.cuda.is_available() else "cpu"
openvoice = ToneColorConverter(f'{ckpt_converter}/config.json', device=device)
openvoice.load_ckpt(f'{ckpt_converter}/checkpoint.pth')

# generate speaker
prompt = 'female voice, bright and cute'
target_se = dreamvoice.gen_spk(prompt)
target_se = target_se.unsqueeze(-1)

# content source
source_path = 'segment_1.mp3'
source_se = se_extractor(source_path, openvoice).to(device)

# voice conversion
encode_message = "@MyShell"
openvoice.convert(
    audio_src_path=source_path,
    src_se=source_se,
    tgt_se=target_se,
    output_path='output.wav',
    message=encode_message)