Spaces:
Runtime error
Runtime error
Update webui.py
Browse files
webui.py
CHANGED
|
@@ -1,3 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import json
|
| 2 |
import logging
|
| 3 |
import spaces
|
|
@@ -326,4 +422,4 @@ with gr.Blocks(title="IndexTTS Demo") as demo:
|
|
| 326 |
|
| 327 |
if __name__ == "__main__":
|
| 328 |
demo.queue(20)
|
| 329 |
-
demo.launch(server_name=
|
|
|
|
| 1 |
+
|
| 2 |
+
'''
|
| 3 |
+
pip install protobuf==3.20.0
|
| 4 |
+
pip uninstall torch torchvision torchaudio
|
| 5 |
+
pip install -U torch torchvision torchaudio
|
| 6 |
+
|
| 7 |
+
'''
|
| 8 |
+
|
| 9 |
+
'''
|
| 10 |
+
import os
|
| 11 |
+
from gradio_client import Client, handle_file
|
| 12 |
+
from shutil import copy2
|
| 13 |
+
|
| 14 |
+
# 初始化Gradio客户端
|
| 15 |
+
client = Client("http://localhost:7860/")
|
| 16 |
+
|
| 17 |
+
# 请替换为您准备好的参考音频文件路径
|
| 18 |
+
reference_audio = '马正阳英文念白_vocals.wav'
|
| 19 |
+
|
| 20 |
+
# 莎士比亚名言列表(英文原文),这里只是示例,您可以自行增删
|
| 21 |
+
shakespeare_quotes = [
|
| 22 |
+
"To be, or not to be: that is the question.",
|
| 23 |
+
"All the world's a stage, and all the men and women merely players.",
|
| 24 |
+
"There is nothing either good or bad, but thinking makes it so.",
|
| 25 |
+
"The course of true love never did run smooth.",
|
| 26 |
+
"Love is blind and lovers cannot see the pretty follies that themselves commit.",
|
| 27 |
+
"All that glisters is not gold.",
|
| 28 |
+
"Brevity is the soul of wit.",
|
| 29 |
+
"What's in a name? That which we call a rose by any other word would smell as sweet.",
|
| 30 |
+
"Sweet are the uses of adversity.",
|
| 31 |
+
"Cowards die many times before their deaths; The valiant never taste of death but once."
|
| 32 |
+
]
|
| 33 |
+
|
| 34 |
+
# 输出目录,确保此目录存在
|
| 35 |
+
output_dir = 'MaZhengYang_IndexTTS2_Shakespeare_Audio'
|
| 36 |
+
os.makedirs(output_dir, exist_ok=True)
|
| 37 |
+
|
| 38 |
+
for index, quote_text in enumerate(shakespeare_quotes):
|
| 39 |
+
try:
|
| 40 |
+
print(f"Processing {index+1}/{len(shakespeare_quotes)}: {quote_text[:50]}...")
|
| 41 |
+
|
| 42 |
+
# 调用Gradio API进行语音合成
|
| 43 |
+
result = client.predict(
|
| 44 |
+
emo_control_method="Same as the voice reference",
|
| 45 |
+
prompt=handle_file(reference_audio), # 使用您提供的参考音频
|
| 46 |
+
text=quote_text, # 填入当前要合成的名言英文原文
|
| 47 |
+
emo_ref_path=None,
|
| 48 |
+
emo_weight=0.8,
|
| 49 |
+
vec1=0,
|
| 50 |
+
vec2=0,
|
| 51 |
+
vec3=0,
|
| 52 |
+
vec4=0,
|
| 53 |
+
vec5=0,
|
| 54 |
+
vec6=0,
|
| 55 |
+
vec7=0,
|
| 56 |
+
vec8=0,
|
| 57 |
+
emo_text="",
|
| 58 |
+
emo_random=False,
|
| 59 |
+
max_text_tokens_per_sentence=120,
|
| 60 |
+
param_16=True,
|
| 61 |
+
param_17=0.8,
|
| 62 |
+
param_18=30,
|
| 63 |
+
param_19=0.8,
|
| 64 |
+
param_20=0,
|
| 65 |
+
param_21=3,
|
| 66 |
+
param_22=10,
|
| 67 |
+
param_23=1500,
|
| 68 |
+
api_name="/gen_single"
|
| 69 |
+
)
|
| 70 |
+
|
| 71 |
+
# 假设返回的result是一个字典,且音频文件路径在result["value"]中
|
| 72 |
+
generated_audio_path = result["value"]
|
| 73 |
+
|
| 74 |
+
# 生成序列号,例如 000001, 000002, ...
|
| 75 |
+
sequence_number = str(index + 1).zfill(6)
|
| 76 |
+
new_audio_filename = f"{sequence_number}.wav"
|
| 77 |
+
new_audio_path = os.path.join(output_dir, new_audio_filename)
|
| 78 |
+
|
| 79 |
+
# 复制并重命名音频文件
|
| 80 |
+
copy2(generated_audio_path, new_audio_path)
|
| 81 |
+
print(f"Audio saved to: {new_audio_path}")
|
| 82 |
+
|
| 83 |
+
# 创建同名的.txt文件并写入英文名言
|
| 84 |
+
txt_filename = f"{sequence_number}.txt"
|
| 85 |
+
txt_path = os.path.join(output_dir, txt_filename)
|
| 86 |
+
with open(txt_path, 'w', encoding='utf-8') as f:
|
| 87 |
+
f.write(quote_text)
|
| 88 |
+
print(f"Text file saved to: {txt_path}")
|
| 89 |
+
|
| 90 |
+
except Exception as e:
|
| 91 |
+
print(f"Error processing quote '{quote_text}': {e}")
|
| 92 |
+
|
| 93 |
+
print("All processing completed!")
|
| 94 |
+
|
| 95 |
+
'''
|
| 96 |
+
|
| 97 |
import json
|
| 98 |
import logging
|
| 99 |
import spaces
|
|
|
|
| 422 |
|
| 423 |
if __name__ == "__main__":
|
| 424 |
demo.queue(20)
|
| 425 |
+
demo.launch(server_name="0.0.0.0", server_port=7860, share = True)
|