File size: 3,131 Bytes
4300fed
 
 
b01a4fc
4300fed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9790b0a
4300fed
e77c996
 
1fb1a4d
4300fed
 
 
 
 
e77c996
103de4f
0d25e21
4300fed
 
 
 
73e2e10
4300fed
e77c996
b01a4fc
4300fed
 
 
 
 
e77c996
e116204
e77c996
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
import torch
import os
from . import utils
cwd = os.getcwd()

DOWNLOAD_CKPT_URLS = {
    'EN': 'https://myshell-public-repo-hosting.s3.amazonaws.com/openvoice/basespeakers/EN/checkpoint.pth',
    'EN_V2': 'https://myshell-public-repo-hosting.s3.amazonaws.com/openvoice/basespeakers/EN_V2/checkpoint.pth',
    'FR': 'https://myshell-public-repo-hosting.s3.amazonaws.com/openvoice/basespeakers/FR/checkpoint.pth',
    'JP': 'https://myshell-public-repo-hosting.s3.amazonaws.com/openvoice/basespeakers/JP/checkpoint.pth',
    'ES': 'https://myshell-public-repo-hosting.s3.amazonaws.com/openvoice/basespeakers/ES/checkpoint.pth',
    'ZH': 'https://myshell-public-repo-hosting.s3.amazonaws.com/openvoice/basespeakers/ZH/checkpoint.pth',
    'KR': 'https://myshell-public-repo-hosting.s3.amazonaws.com/openvoice/basespeakers/KR/checkpoint.pth',
}

DOWNLOAD_CONFIG_URLS = {
    'EN': 'https://myshell-public-repo-hosting.s3.amazonaws.com/openvoice/basespeakers/EN/config.json',
    'EN_V2': 'https://myshell-public-repo-hosting.s3.amazonaws.com/openvoice/basespeakers/EN_V2/config.json',
    'FR': 'https://myshell-public-repo-hosting.s3.amazonaws.com/openvoice/basespeakers/FR/config.json',
    'JP': 'https://myshell-public-repo-hosting.s3.amazonaws.com/openvoice/basespeakers/JP/config.json',
    'ES': 'https://myshell-public-repo-hosting.s3.amazonaws.com/openvoice/basespeakers/ES/config.json',
    'ZH': 'https://myshell-public-repo-hosting.s3.amazonaws.com/openvoice/basespeakers/ZH/config.json',
    'KR': 'https://myshell-public-repo-hosting.s3.amazonaws.com/openvoice/basespeakers/KR/config.json',
}

def load_or_download_config(locale):
    language = locale.split('-')[0].upper()
    print(f"language={language}, locale={locale}")
    assert language in DOWNLOAD_CONFIG_URLS

    #config_path = os.path.expanduser(f'~/.local/share/openvoice/basespeakers/{language}/config.json')
    config_path = os.path.join(cwd, f"openvoice/basespeakers/{language}/config.json")
    try:
        return utils.get_hparams_from_file(config_path)
    except:
        # download
        os.makedirs(os.path.dirname(config_path), exist_ok=True)
        #os.system(f'wget {DOWNLOAD_CONFIG_URLS[language]} -O {config_path}')
        print(f"URL = {DOWNLOAD_CONFIG_URLS[language]}")
        os.system(f"curl -o {config_path} {DOWNLOAD_CONFIG_URLS[language]}")
    return utils.get_hparams_from_file(config_path)

def load_or_download_model(locale, device):
    language = locale.split('-')[0].upper()
    print(f"language={language}, locale={locale}")
    assert language in DOWNLOAD_CKPT_URLS
    #ckpt_path = os.path.expanduser(f'~/.local/share/openvoice/basespeakers/{language}/checkpoint.pth')
    ckpt_path = os.path.join(cwd, f"openvoice/basespeakers/{language}/checkpoint.pth")
    try:
        return torch.load(ckpt_path, map_location=device)
    except:
        # download
        os.makedirs(os.path.dirname(ckpt_path), exist_ok=True)
        #os.system(f'wget {DOWNLOAD_CKPT_URLS[language]} -O {ckpt_path}')
        os.system(f"curl -o {ckpt_path} {DOWNLOAD_CKPT_URLS[language]}")
    return torch.load(ckpt_path, map_location=device)