Spaces:
Running
on
Zero
Running
on
Zero
Delete inference_cli.py
Browse files- inference_cli.py +0 -55
inference_cli.py
DELETED
@@ -1,55 +0,0 @@
|
|
1 |
-
import argparse
|
2 |
-
import os
|
3 |
-
import soundfile as sf
|
4 |
-
|
5 |
-
from tools.i18n.i18n import I18nAuto
|
6 |
-
from GPT_SoVITS.inference_webui import change_gpt_weights, change_sovits_weights, get_tts_wav
|
7 |
-
|
8 |
-
i18n = I18nAuto()
|
9 |
-
|
10 |
-
def synthesize(GPT_model_path, SoVITS_model_path, ref_audio_path, ref_text_path, ref_language, target_text_path, target_language, output_path):
|
11 |
-
# Read reference text
|
12 |
-
with open(ref_text_path, 'r', encoding='utf-8') as file:
|
13 |
-
ref_text = file.read()
|
14 |
-
|
15 |
-
# Read target text
|
16 |
-
with open(target_text_path, 'r', encoding='utf-8') as file:
|
17 |
-
target_text = file.read()
|
18 |
-
|
19 |
-
# Change model weights
|
20 |
-
change_gpt_weights(gpt_path=GPT_model_path)
|
21 |
-
change_sovits_weights(sovits_path=SoVITS_model_path)
|
22 |
-
|
23 |
-
# Synthesize audio
|
24 |
-
synthesis_result = get_tts_wav(ref_wav_path=ref_audio_path,
|
25 |
-
prompt_text=ref_text,
|
26 |
-
prompt_language=i18n(ref_language),
|
27 |
-
text=target_text,
|
28 |
-
text_language=i18n(target_language), top_p=1, temperature=1)
|
29 |
-
|
30 |
-
result_list = list(synthesis_result)
|
31 |
-
|
32 |
-
if result_list:
|
33 |
-
last_sampling_rate, last_audio_data = result_list[-1]
|
34 |
-
output_wav_path = os.path.join(output_path, "output.wav")
|
35 |
-
sf.write(output_wav_path, last_audio_data, last_sampling_rate)
|
36 |
-
print(f"Audio saved to {output_wav_path}")
|
37 |
-
|
38 |
-
def main():
|
39 |
-
parser = argparse.ArgumentParser(description="GPT-SoVITS Command Line Tool")
|
40 |
-
parser.add_argument('--gpt_model', required=True, help="Path to the GPT model file")
|
41 |
-
parser.add_argument('--sovits_model', required=True, help="Path to the SoVITS model file")
|
42 |
-
parser.add_argument('--ref_audio', required=True, help="Path to the reference audio file")
|
43 |
-
parser.add_argument('--ref_text', required=True, help="Path to the reference text file")
|
44 |
-
parser.add_argument('--ref_language', required=True, choices=["中文", "英文", "日文"], help="Language of the reference audio")
|
45 |
-
parser.add_argument('--target_text', required=True, help="Path to the target text file")
|
46 |
-
parser.add_argument('--target_language', required=True, choices=["中文", "英文", "日文", "中英混合", "日英混合", "多语种混合"], help="Language of the target text")
|
47 |
-
parser.add_argument('--output_path', required=True, help="Path to the output directory")
|
48 |
-
|
49 |
-
args = parser.parse_args()
|
50 |
-
|
51 |
-
synthesize(args.gpt_model, args.sovits_model, args.ref_audio, args.ref_text, args.ref_language, args.target_text, args.target_language, args.output_path)
|
52 |
-
|
53 |
-
if __name__ == '__main__':
|
54 |
-
main()
|
55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|