forked from jianchang512/clone-voice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
109 lines (91 loc) · 4.4 KB
/
test.py
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
import datetime
import json
import logging
import re
import shutil
import threading
import time
from dotenv import load_dotenv
load_dotenv()
import os
def setorget_proxy():
proxy = os.environ.get("http_proxy", '') or os.environ.get("HTTP_PROXY", '')
if proxy:
os.environ['AIOHTTP_PROXY'] = "http://" + proxy.replace('http://', '')
return proxy
if not proxy:
proxy = os.getenv('HTTP_PROXY', '')
if proxy:
os.environ['HTTP_PROXY'] = "http://" + proxy.replace('http://', '')
os.environ['HTTPS_PROXY'] = "http://" + proxy.replace('http://', '')
os.environ['AIOHTTP_PROXY'] = "http://" + proxy.replace('http://', '')
return proxy
return proxy
#print(setorget_proxy())
import aiohttp
from flask import Flask, request, render_template, jsonify, send_file
import glob
import hashlib
import torch
from pydub import AudioSegment
from logging.handlers import RotatingFileHandler
from TTS.api import TTS
import queue
import webbrowser
'''
shutil.copytree("./venv/Lib/site-packages/numpy-1.26.2.dist-info","./dist/app/_internal/numpy-1.26.2.dist-info",dirs_exist_ok=True)
shutil.copytree("./venv/Lib/site-packages/packaging-23.2.dist-info","./dist/app/_internal/packaging-23.2.dist-info",dirs_exist_ok=True)
shutil.copytree("./venv/Lib/site-packages/PyYAML-6.0.1.dist-info","./dist/app/_internal/PyYAML-6.0.1.dist-info",dirs_exist_ok=True)
shutil.copytree("./venv/Lib/site-packages/regex-2023.10.3.dist-info","./dist/app/_internal/regex-2023.10.3.dist-info",dirs_exist_ok=True)
shutil.copytree("./venv/Lib/site-packages/requests-2.31.0.dist-info","./dist/app/_internal/requests-2.31.0.dist-info",dirs_exist_ok=True)
shutil.copytree("./venv/Lib/site-packages/safetensors-0.4.0.dist-info","./dist/app/_internal/safetensors-0.4.0.dist-info",dirs_exist_ok=True)
shutil.copytree("./venv/Lib/site-packages/torch","./dist/app/_internal/torch",dirs_exist_ok=True)
shutil.copytree("./venv/Lib/site-packages/torch-2.1.1.dist-info","./dist/app/_internal/torch-2.1.1.dist-info",dirs_exist_ok=True)
shutil.copytree("./venv/Lib/site-packages/tqdm-4.66.1.dist-info","./dist/app/_internal/tqdm-4.66.1.dist-info",dirs_exist_ok=True)
shutil.copytree("./venv/Lib/site-packages/trainer","./dist/app/_internal/trainer",dirs_exist_ok=True)
shutil.copytree("./venv/Lib/site-packages/trainer-0.0.32.dist-info","./dist/app/_internal/trainer-0.0.32.dist-info",dirs_exist_ok=True)
shutil.copytree("./venv/Lib/site-packages/transformers","./dist/app/_internal/transformers",dirs_exist_ok=True)
shutil.copytree("./venv/Lib/site-packages/transformers-4.35.2.dist-info","./dist/app/_internal/transformers-4.35.2.dist-info",dirs_exist_ok=True)
shutil.copytree("./venv/Lib/site-packages/TTS-0.20.6.dist-info","./dist/app/_internal/TTS-0.20.6.dist-info",dirs_exist_ok=True)
shutil.copytree("./venv/Lib/site-packages/TTS","./dist/app/_internal/TTS",dirs_exist_ok=True)
shutil.copytree("./tts","./dist/app/tts",dirs_exist_ok=True)
shutil.copytree("./tts_cache","./dist/app/tts_cache",dirs_exist_ok=True)
shutil.copytree("./static","./dist/app/static",dirs_exist_ok=True)
shutil.copytree("./templates","./dist/app/templates",dirs_exist_ok=True)
'''
# print(setorget_proxy())
# device = "cuda" if torch.cuda.is_available() else "cpu"
# try:
ROOT_DIR = os.getcwd()
os.environ['TTS_HOME'] = ROOT_DIR
#exit()
device = "cuda" if torch.cuda.is_available() else "cpu"
tts = TTS(model_name='voice_conversion_models/multilingual/vctk/freevc24').to(device)
# except aiohttp.client_exceptions.ClientOSError as e:
# if not setorget_proxy():
# print(f'请在 .env 文件中正确设置 http 代理,以便能从 https://huggingface.co 下载模型')
# else:
# print(f'你设置的代理不可用,请设置正确的代理,以便能从 https://huggingface.co 下载模型')
# except Exception as e:
# print(e)
# try:
# n=os.getcwd()
# except Exception as e:
# pass
# try:
# print(f'{n=}')
# except:
# pass
#device = "cuda" if torch.cuda.is_available() else "cpu"
#tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2").to(device)
import py7zr
import os
def extract_7z(archive_path, extract_dir):
with py7zr.SevenZipFile(archive_path, mode='r') as z:
z.extractall(extract_dir)
def main():
archive_path = 'tts/11.7z' # 压缩包路径
extract_dir = 'tts' # 解压目录
if not os.path.exists(extract_dir):
os.makedirs(extract_dir)
extract_7z(archive_path, extract_dir)