'commit'
This commit is contained in:
@@ -34,9 +34,9 @@ class ASRClient:
|
||||
logger.error(f"初始化ASR客户端失败: {str(e)}", exc_info=True)
|
||||
raise
|
||||
|
||||
async def transcribe_file(self, file_path):
|
||||
def transcribe_file_sync(self, file_path):
|
||||
"""
|
||||
转写本地音频文件
|
||||
转写本地音频文件 (同步版本)
|
||||
|
||||
Args:
|
||||
file_path: 本地音频文件路径
|
||||
@@ -44,7 +44,7 @@ class ASRClient:
|
||||
Returns:
|
||||
str: 转写后的文本,如果失败返回None
|
||||
"""
|
||||
logger.info(f"开始转写文件: {file_path}")
|
||||
logger.info(f"开始转写文件(Sync): {file_path}")
|
||||
|
||||
try:
|
||||
recognition = Recognition(
|
||||
@@ -54,9 +54,7 @@ class ASRClient:
|
||||
callback=None
|
||||
)
|
||||
|
||||
# Run blocking call in executor
|
||||
loop = asyncio.get_running_loop()
|
||||
result = await loop.run_in_executor(None, lambda: recognition.call(file_path))
|
||||
result = recognition.call(file_path)
|
||||
|
||||
if result.status_code == HTTPStatus.OK:
|
||||
sentences = []
|
||||
@@ -73,3 +71,16 @@ class ASRClient:
|
||||
except Exception as e:
|
||||
logger.error(f"转写过程出错: {str(e)}", exc_info=True)
|
||||
return None
|
||||
|
||||
async def transcribe_file(self, file_path):
|
||||
"""
|
||||
转写本地音频文件
|
||||
|
||||
Args:
|
||||
file_path: 本地音频文件路径
|
||||
|
||||
Returns:
|
||||
str: 转写后的文本,如果失败返回None
|
||||
"""
|
||||
loop = asyncio.get_running_loop()
|
||||
return await loop.run_in_executor(None, self.transcribe_file_sync, file_path)
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user