refactor(podcast_generator): 改进音频生成和合并逻辑 - 添加多线程支持加速音频生成 - 优化JSON解析逻辑增强健壮性 - 改进音频文件合并为WAV格式 - 添加执行时间统计功能 docs(config): 更新语音配置文件和添加新语音 - 为所有语音添加usedname字段 - 添加新的语音配置和角色定义 - 更新API URL参数 chore: 更新.gitignore添加日志文件排除
48 lines
1.8 KiB
Python
48 lines
1.8 KiB
Python
import json
|
||
import requests
|
||
import time
|
||
|
||
def check_tts_voices():
|
||
config_file_path = "config/edge-tts.json"
|
||
base_url = "http://192.168.1.178:7899/tts"
|
||
test_text = "你好"
|
||
rate = 5 # Assuming 'r' means rate
|
||
|
||
try:
|
||
with open(config_file_path, 'r', encoding='utf-8') as f:
|
||
config_data = json.load(f)
|
||
except FileNotFoundError:
|
||
print(f"错误: 配置文件未找到,请检查路径: {config_file_path}")
|
||
return
|
||
except json.JSONDecodeError:
|
||
print(f"错误: 无法解析 JSON 文件: {config_file_path}")
|
||
return
|
||
|
||
voices = config_data.get('voices', [])
|
||
if not voices:
|
||
print("未在配置文件中找到任何声音(voices)。")
|
||
return
|
||
|
||
print(f"开始验证 {len(voices)} 个 TTS 语音...")
|
||
for voice in voices:
|
||
voice_code = voice.get('code')
|
||
voice_name = voice.get('name', '未知')
|
||
if voice_code:
|
||
url = f"{base_url}?t={test_text}&v={voice_code}&r={rate}"
|
||
print(f"正在测试语音: {voice_name} (Code: {voice_code}) - URL: {url}")
|
||
try:
|
||
response = requests.get(url, timeout=10) # 10秒超时
|
||
if response.status_code == 200:
|
||
print(f" ✅ {voice_name} (Code: {voice_code}): 可用")
|
||
else:
|
||
print(f" ❌ {voice_name} (Code: {voice_code}): 不可用, 状态码: {response.status_code}")
|
||
except requests.exceptions.RequestException as e:
|
||
print(f" ❌ {voice_name} (Code: {voice_code}): 请求失败, 错误: {e}")
|
||
time.sleep(0.1) # 短暂延迟,避免请求过快
|
||
else:
|
||
print(f"跳过一个缺少 'code' 字段的语音条目: {voice}")
|
||
|
||
print("TTS 语音验证完成。")
|
||
|
||
if __name__ == "__main__":
|
||
check_tts_voices() |