exec_asr_client.py 1012 B

123456789101112131415161718192021222324252627282930313233
  1. import asyncio
  2. from config import *
  3. python_exec = sys.executable
  4. asr_client_py = os.path.join(WORK_DIR, "tool", "funasr_wss_client.py")
  5. async def run_asr_client(audio_file, output_json, asr_address=ASR_ADDRESS):
  6. host, port = ASR_ADDRESS.split(':')
  7. cmd = [
  8. python_exec,
  9. asr_client_py,
  10. "--host", host,
  11. "--port", port,
  12. "--mode", "offline",
  13. "--ssl", "0",
  14. "--audio_in", audio_file,
  15. "--output_json", output_json
  16. ]
  17. process = await asyncio.create_subprocess_exec(
  18. *cmd,
  19. stdout=asyncio.subprocess.PIPE,
  20. stderr=asyncio.subprocess.PIPE
  21. )
  22. stdout, stderr = await process.communicate()
  23. if process.returncode != 0:
  24. logger.error(f"语音识别执行出错: cmd: {cmd} audio_file:{audio_file} output_json:{output_json} {stderr.decode()} ")
  25. return False
  26. logger.info(f"语音识别输出: {stdout.decode()}")
  27. return True