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

AWS Transcribe报15秒无音频超时错误排查求助

AWS Transcribe 15秒超时错误排查与修复

问题说明

使用AWS Transcribe流式转录时触发BadRequestException,错误提示:Your request timed out because no new audio was received for 15 seconds,但连接和音频数据均有效。

核心问题分析

  1. Node.js端重复监听音频事件:额外的audio_data监听会抢占async generator的音频数据获取,导致AWS Transcribe无法收到连续的音频流。
  2. 音频发送与转录启动顺序错误:客户端先发送音频数据再启动转录,导致初始音频块丢失,AWS启动后15秒内无数据触发超时。

代码修复方案

1. Node.js 代码修复

删除多余的audio_data监听(该逻辑会循环发送音频数据,完全干扰正常转录流程):

// 移除这段无效且干扰的代码
// socket.on("audio_data", (data) => {
//   console.log("Received audio data from the client");
//   if(isTrasncribing){
//     socket.emit('audio_data',data);
//   }
// });

2. 客户端(Angular)代码修复

调整启动顺序,先发送转录启动指令,再开始采集并发送音频数据,确保AWS启动后能立即收到音频:

startMSRecording(){
  navigator.mediaDevices.getUserMedia({ audio: true }).then((stream) => {
    this.audioContextMS = new AudioContext();
    this.audioInputMS = this.audioContextMS.createMediaStreamSource(stream);
    this.processorMS = this.audioContextMS.createScriptProcessor(1024, 1, 1);

    this.audioInputMS.connect(this.processorMS);
    this.processorMS.connect(this.audioContextMS.destination);

    // 先发送启动转录指令,再启动音频采集
    this.connection?.emit('startTranscription');  

    this.processorMS.onaudioprocess = (event) => {
      const float32Array = event.inputBuffer.getChannelData(0);
      const int16Array = new Int16Array(float32Array.length);
      for(let i=0;i<float32Array.length;i++){
        int16Array[i] = Math.max(-32768, Math.min(32767, float32Array[i] * 32768));
      }
      this.connection?.emit('audio_data', int16Array.buffer);
    };
  })
  .catch((error) => {
    console.error('Error accessing microphone:', error);
  });
}

3. 额外优化:静默场景处理

若用户长时间静默,可在async generator中添加超时逻辑,定期发送空音频块避免AWS超时:

audioStream = async function* () {
  while(isTrasncribing){
    const chunk = await Promise.race([
      new Promise((resolve) => {
        socket.once('audio_data', resolve);
      }),
      // 10秒无数据则发送空音频块
      new Promise(resolve => setTimeout(() => resolve(Buffer.from([])), 10000))
    ]);
    if(chunk === null){
      break;
    }
    yield {AudioEvent: {AudioChunk: chunk}};
  }
};

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.16 12:28:11