Skip to content

AWS Transcribe Streaming error: HTTP/2 stream is abnormally aborted in mid-communication with result code 2

0

I'm streaming from a websocket to AWS Transcribe. The very first chunk causes AWS to abort the connection. I can't find any information on why this happened.

  • verified I have permissions
  • verified the PCM audio (tried to post the small base64 chunk but it is not allowed for some reason.)
  • Chunk size is 320 bytes

I have set log: console but it hasn't yielded anything useful.


HTTP/2 stream is abnormally aborted in mid-communication with result code 2.
    at ClientHttp2Stream.<anonymous> (/Users/naten/Amplify/persephone/node_modules/@aws-sdk/client-transcribe-streaming/node_modules/@smithy/node-http-handler/dist-cjs/index.js:705:11)
    at ClientHttp2Stream.emit (node:events:517:28)
    at closeStream (node:internal/http2/core:1923:14)
    at ClientHttp2Stream._destroy (node:internal/http2/core:2334:7)
    at _destroy (node:internal/streams/destroy:109:10)
    at ClientHttp2Stream.destroy (node:internal/streams/destroy:71:5)
    at node:internal/http2/core:1153:53
    at Set.forEach (<anonymous>)
    at closeSession (node:internal/http2/core:1153:26)
    at ClientHttp2Session.destroy (node:internal/http2/core:1542:5)

My stream intiialization:

    const transcribeStream = await transcribeClient.send(
      new StartCallAnalyticsStreamTranscriptionCommand({
        LanguageCode: "en-US",
        MediaEncoding: "pcm",
        MediaSampleRateHertz: 16000,
        AudioStream: this.getAudioStream(), 
      })
    );

My generator function:

  private async *getAudioStream(): AsyncIterable<AudioStream> {
    while (true) {
      if(this.audioChunks == null) {
        console.log("stream closed, stopping audio processing")
        break;
      }
      if (this.audioChunks.length > 0) {
        const chunk = this.audioChunks.shift() ;
        yield { AudioEvent: { AudioChunk: chunk } };
      } else {
        await new Promise(resolve => setTimeout(resolve, 100)); // Wait for more chunks
      }
    }
  }

How I push onto the stream:

      const audioBuffer = Buffer.from(message.data,'base64');
      this.audioChunks.push(audioBuffer);

asked 2 years ago630 views

2 Answers
1

The error you're encountering suggests that there might be an issue with the audio stream or how it's being sent to Amazon Transcribe. Here are a few things to consider:

  1. Audio format: Ensure that your PCM audio is in the correct format. Amazon Transcribe expects 16-bit PCM audio for streaming transcription.

  2. Sample rate: You've set the MediaSampleRateHertz to 16000, which is correct for the 16 kHz audio that Amazon Transcribe supports for streaming.

  3. Chunk size: Your chunk size of 320 bytes is quite small. While Amazon Transcribe can handle various chunk sizes, you might want to try increasing it to see if it resolves the issue. A common chunk size is around 32 KB.

  4. Stream initialization: Your stream initialization looks correct, using the StartCallAnalyticsStreamTranscriptionCommand.

  5. Audio stream generator: Your getAudioStream function seems to be implemented correctly, yielding audio chunks as they become available.

  6. Error handling: Make sure you have proper error handling in place, especially for the first chunk of audio data.

  7. AWS SDK version: Ensure you're using the latest version of the AWS SDK for JavaScript, as older versions might have bugs that have been fixed in newer releases.

  8. Network issues: The error could potentially be related to network connectivity problems. Ensure you have a stable connection to AWS.

  9. Account limits: Check if you've hit any account limits for Amazon Transcribe streaming.

If the issue persists after checking these points, you may want to try the following:

  • Implement more detailed logging to capture the exact state when the error occurs.
  • Try using a different audio file to see if the problem is specific to your current audio data.
  • Consider using the AWS CLI or SDK to test the streaming transcription with a known good audio file to isolate whether the issue is with your code or the service.

If none of these suggestions resolve the issue, you may need to contact AWS Support for further assistance, as they can provide more detailed diagnostics based on your account and usage patterns.
Sources
Transcribing with HTTP or WebSockets - Amazon Transcribe
TranscriptResultStream - Amazon Transcribe
Streaming transcription overview - Amazon Transcribe

answered 2 years ago

EXPERT

reviewed 2 years ago

  • Thanks I did check all those things, and I've also tried with recorded audio dumped to a text file in base64. I've tried from my local machine and from a deployed ECS container.

    const micInstance = mic({
        rate: '16000', // 16kHz sample rate (required for AWS Transcribe)
        channels: '1', // Mono audio
        encoding: 'signed-integer', // PCM format
        bitwidth: '16', // 16-bit audio
        endian: 'little', // Little-endian encoding
        fileType: 'raw' // Raw PCM
    });
    

    Also I've already recieved this answer from a bunch of other AI tools.

    Sample chunk: FQA0ADgAQgAxACYANQA1ACQAHAATACAAEgAZABsAAwAHAAkADAADAP3/CQADAPn/9P/4/wMA///0//r/7v/v//X/8P/0//P/BgABAN//5f/4//3/8P/1/wsA+v8MAPL/8P/v/9r/0f/I/9b/5P/m/9j/s/+l/6b/mP+d/7f/wP+9/7v/hP/G/73/zf/p/9v/8//d/9j/4//J/5z/m/+D/5H/eP90/2X/Tv9F/1z/VP9D/0v/NP8n/xr/DP/9/gv/Ev8O/wz/Cf/1/u/+9P7w/uX+8P7+/gP//v71/vf+CP8Q/xP/G/8w/17/d/+C/5n/wP/V/+3//P8PAB8AKQA/AFoAcABzAIEAlACpAL4A0ADbAOoA/wASAS4BOgFPAWQBcwGNAZ0BtAHJAd0B6wH8Af8B/gEHAhQCHgIsAjUCRgI=

0

Found the reason! I was sending to us-west-1 which is unsupported.

answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.