更新 qwen3_asr_flash.py

This commit is contained in:
FAN-yeB
2025-12-10 17:57:26 +08:00
parent 48094f7e37
commit 3a74b30a0e
@@ -1,8 +1,5 @@
import os import os
import json
import asyncio
import tempfile import tempfile
import difflib
from typing import Optional, Tuple, List from typing import Optional, Tuple, List
import dashscope import dashscope
from config.logger import setup_logging from config.logger import setup_logging
@@ -130,27 +127,11 @@ class ASRProvider(ASRProviderBase):
# 处理流式响应 # 处理流式响应
full_text = "" full_text = ""
last_text = "" # 用于存储上一个文本片段
for chunk in response: for chunk in response:
try: try:
text = chunk["output"]["choices"][0]["message"].content[0]["text"] text = chunk["output"]["choices"][0]["message"].content[0]["text"]
# 标准化文本片段(去除首尾空格) # 更新为最新的完整文本
normalized_text = text.strip() full_text = text.strip()
# 只有当新文本片段与上一个不同时才处理
if normalized_text != last_text:
# 提取新增的文本部分
# 通过比较当前文本和上一个文本,找到新增的部分
if normalized_text.startswith(last_text):
# 如果当前文本以最后一个文本开头,则新增部分是两者的差集
new_part = normalized_text[len(last_text):]
else:
# 如果不以最后一个文本开头,说明识别结果发生了较大变化,直接使用当前文本
new_part = normalized_text
# 将新增部分添加到完整文本中
full_text += new_part
last_text = normalized_text
# 这里可以实时处理文本片段,例如通过回调函数
except: except:
pass pass