You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

本地运行Azure语音克隆函数遇Address already in use错误排查

问题:Azure语音克隆函数本地请求触发端口占用错误

我开发了一个语音克隆Azure函数,逻辑是接收模型名称、音频URL作为参数,执行流程为:

  • 下载音频文件
  • 调用指定模型处理音频
  • 上传处理结果并返回文件URL

本地测试时函数启动正常,但发起请求时抛出如下错误:

RuntimeError: Can't listen for client connections: [Errno 98] Address already in use
[2023-07-04T17:56:49.679Z] Language Worker Process exited. Pid=128697.
[2023-07-04T17:56:49.679Z] python3 exited with code 1 (0x1). log.reraise_exception("{0}() failed:", func.name, level="info"), raise RuntimeError(str(endpoints["error"])),RuntimeError: Can't listen for client connections: [Errno 98] Address already in use.
[2023-07-04T17:56:49.697Z] Failed to start a new language worker for runtime: python.
[2023-07-04T17:56:49.697Z] System.Private.CoreLib: A task was canceled.

经排查,错误出现在调用torchcrepe.predict函数时:

f0, pd = torchcrepe.predict(
                audio,
                self.sr,
                self.window,
                f0_min,
                f0_max,
                model,
                batch_size=batch_size,
                device=self.device,
                return_periodicity=True,
            )

进一步定位到torchcrepe库内以下代码行触发异常:

# Move model to correct device (no-op if devices are the same)
    infer.model = infer.model.to(frames.device)

    # Apply model
    return infer.model(frames, embed=embed)

解决方向
  1. 排查端口占用

    • Azure函数本地测试默认监听7071端口,先检查该端口是否被其他进程占用:
      • Windows执行:netstat -ano | findstr :7071
      • Linux/macOS执行:lsof -i :7071
    • 终止占用端口的进程,或者修改函数监听端口:在local.settings.json中添加"FUNCTIONS_CUSTOMHANDLER_PORT": "8080"(替换为未占用的端口)
  2. 调整torchcrepe使用方式

    • 显式指定使用CPU设备:将device参数改为torch.device('cpu'),避免GPU相关的端口冲突
    • 更换torchcrepe版本:尝试降级到0.0.18或升级到最新稳定版,修复版本兼容问题
    • 单例加载模型:确保模型只在函数初始化时加载一次,不要每次请求都重新加载,减少资源竞争
  3. 优化Azure函数本地配置

    • 在local.settings.json中设置WEBSITE_MAX_DYNAMIC_APPLICATION_SCALE_OUT为1,防止本地启动多个worker进程导致端口冲突
    • 增加函数的内存配额,避免资源不足引发异常

内容的提问来源于stack exchange,提问作者teewhy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.17 04:40:28