| 123456789101112131415161718192021222324252627282930313233 |
- import asyncio
- from config import *
- python_exec = sys.executable
- asr_client_py = os.path.join(WORK_DIR, "tool", "funasr_wss_client.py")
- async def run_asr_client(audio_file, output_json, asr_address=ASR_ADDRESS):
- host, port = ASR_ADDRESS.split(':')
-
- cmd = [
- python_exec,
- asr_client_py,
- "--host", host,
- "--port", port,
- "--mode", "offline",
- "--ssl", "0",
- "--audio_in", audio_file,
- "--output_json", output_json
- ]
-
- process = await asyncio.create_subprocess_exec(
- *cmd,
- stdout=asyncio.subprocess.PIPE,
- stderr=asyncio.subprocess.PIPE
- )
-
- stdout, stderr = await process.communicate()
-
- if process.returncode != 0:
- logger.error(f"语音识别执行出错: cmd: {cmd} audio_file:{audio_file} output_json:{output_json} {stderr.decode()} ")
- return False
-
- logger.info(f"语音识别输出: {stdout.decode()}")
- return True
|