update realtime translate demo
Browse files
ax_speech_translate_demo_qwen_api_realtime.py
CHANGED
|
@@ -42,7 +42,7 @@ TTS_MODEL_FILES = {
|
|
| 42 |
}
|
| 43 |
|
| 44 |
# Qwen大模型翻译API参数
|
| 45 |
-
QWEN_API_URL = "http://10.126.29.158:8000
|
| 46 |
|
| 47 |
# TTS辅助函数
|
| 48 |
def intersperse(lst, item):
|
|
@@ -308,7 +308,7 @@ class QwenTranslationAPI:
|
|
| 308 |
print(f"[翻译API] 轮询请求失败: {e}")
|
| 309 |
if time.time() - start_time > timeout:
|
| 310 |
break
|
| 311 |
-
time.sleep(0.
|
| 312 |
continue
|
| 313 |
|
| 314 |
if error_detected:
|
|
@@ -856,7 +856,7 @@ class SpeechTranslationPipeline:
|
|
| 856 |
all_results.append(result)
|
| 857 |
result = self.get_stream_results()
|
| 858 |
|
| 859 |
-
time.sleep(0.
|
| 860 |
|
| 861 |
# 输出结果
|
| 862 |
# print(f"\n[流式处理] 等待处理剩余音频块...")
|
|
@@ -876,7 +876,7 @@ class SpeechTranslationPipeline:
|
|
| 876 |
all_results.append(result)
|
| 877 |
wait_start = time.time() # 重置等待时间
|
| 878 |
else:
|
| 879 |
-
time.sleep(0.
|
| 880 |
|
| 881 |
# 停止流式处理
|
| 882 |
self.stop_stream_processing()
|
|
@@ -888,7 +888,7 @@ def main():
|
|
| 888 |
parser = argparse.ArgumentParser(description="实时语音翻译pipeline")
|
| 889 |
parser.add_argument("--audio_file", type=str, default="./wav/en_6mins.wav", help="输入音频文件路径")
|
| 890 |
parser.add_argument("--output_dir", type=str, default="./output", help="输出目录")
|
| 891 |
-
parser.add_argument("--api_url", type=str, default=
|
| 892 |
parser.add_argument("--target_sr", type=int, default=16000, help="ASR目标采样率 (默认: 16000)")
|
| 893 |
parser.add_argument("--chunk_duration", type=float, default=7.0, help="音频块时长(秒) (默认: 7.0)")
|
| 894 |
parser.add_argument("--overlap_duration", type=float, default=0.01, help="重叠时长(秒) (默认: 0.1)")
|
|
|
|
| 42 |
}
|
| 43 |
|
| 44 |
# Qwen大模型翻译API参数
|
| 45 |
+
QWEN_API_URL = "" # API服务地址 http://10.126.29.158:8000
|
| 46 |
|
| 47 |
# TTS辅助函数
|
| 48 |
def intersperse(lst, item):
|
|
|
|
| 308 |
print(f"[翻译API] 轮询请求失败: {e}")
|
| 309 |
if time.time() - start_time > timeout:
|
| 310 |
break
|
| 311 |
+
time.sleep(0.05)
|
| 312 |
continue
|
| 313 |
|
| 314 |
if error_detected:
|
|
|
|
| 856 |
all_results.append(result)
|
| 857 |
result = self.get_stream_results()
|
| 858 |
|
| 859 |
+
time.sleep(0.01)
|
| 860 |
|
| 861 |
# 输出结果
|
| 862 |
# print(f"\n[流式处理] 等待处理剩余音频块...")
|
|
|
|
| 876 |
all_results.append(result)
|
| 877 |
wait_start = time.time() # 重置等待时间
|
| 878 |
else:
|
| 879 |
+
time.sleep(0.02)
|
| 880 |
|
| 881 |
# 停止流式处理
|
| 882 |
self.stop_stream_processing()
|
|
|
|
| 888 |
parser = argparse.ArgumentParser(description="实时语音翻译pipeline")
|
| 889 |
parser.add_argument("--audio_file", type=str, default="./wav/en_6mins.wav", help="输入音频文件路径")
|
| 890 |
parser.add_argument("--output_dir", type=str, default="./output", help="输出目录")
|
| 891 |
+
parser.add_argument("--api_url", type=str, default="http://10.126.29.158:8000", help="Qwen API服务器URL")
|
| 892 |
parser.add_argument("--target_sr", type=int, default=16000, help="ASR目标采样率 (默认: 16000)")
|
| 893 |
parser.add_argument("--chunk_duration", type=float, default=7.0, help="音频块时长(秒) (默认: 7.0)")
|
| 894 |
parser.add_argument("--overlap_duration", type=float, default=0.01, help="重叠时长(秒) (默认: 0.1)")
|