import os
import shutil
import tqdm
from gradio_client import Client
reference_audio_path = (
r"D:\data\音频\2025年05月14日 参考语言文本,需要大概十秒钟。.m4a"
)
reference_audio_text = "参考语言文本,需要大概十 秒钟。"
reference_audio_tmp_path = r"D:\CodeProjects\GPT-SoVITS-v4-20250422fix\TEMP\gradio\4c841149931f32360e312b31e81a5f81549e5584\reference_audio.m4a"
os.makedirs(os.path.dirname(reference_audio_tmp_path), exist_ok=True)
if os.path.exists(reference_audio_tmp_path):
os.remove(reference_audio_tmp_path)
shutil.copy2(reference_audio_path, reference_audio_tmp_path)
client = Client("http://localhost:9872")
output_dir = "output_audios"
os.makedirs(output_dir, exist_ok=True)
ref_wav_path = {
"name": reference_audio_path,
"path": reference_audio_tmp_path
}
prompt_language = "中文"
text_language = "中文"
how_to_cut = "按中文句号。切"
sample_steps = 8
texts = [
"湘江北去,橘子洲头。看万山红遍,层林尽染;",
"漫江碧透,百舸争流。鹰击长空,鱼翔浅底,万类霜天竞自由。",
"怅寥廓,问苍茫大地,谁主沉浮?",
"携来百侣曾游。忆往昔峥嵘岁月稠。",
"恰同学少年,风华正茂;书生意气,挥斥方遒。",
"指点江山,激扬文字,粪土当年万户侯。",
"曾记否,到中流击水,浪遏飞舟?",
]
for i, text in tqdm.tqdm(enumerate(texts)):
print(f"生成第 {i + 1} 条音频...")
result = client.predict(
ref_wav_path,
reference_audio_text,
prompt_language,
text,
text_language,
how_to_cut,
15,
1.0,
1.0,
False,
1.0,
False,
None,
sample_steps,
False,
0.3,
api_name="/get_tts_wav",
)
print(result)
ori_file = result
target_file = os.path.join(output_dir, f"{i} {text}.wav")
shutil.copy2(result, target_file)
print(target_file)