ottlseo / bedrock-ai-tutor

GenAI w AWS CDK example using Anthropic Claude 3.0 Haiku & Sonnet
https://d2s3v0hqemilkh.cloudfront.net
1 stars 1 forks source link

[FE] Getting transcribe streaming responses is too slow #3

Closed ottlseo closed 7 months ago

ottlseo commented 7 months ago

After adding language score calculation, transcribe streaming became too slow

1. It depends on an audio chunk size ( & SAMPLE_RATE )

An error occurred while recording: {"Message":"1 validation error detected: 
Value '66000' at 'mediaSampleRateHertz' failed to satisfy constraint: 
Member must have value less than or equal to 48000"}

2. It seems to be relevant to languageIdentification feature

ottlseo commented 7 months ago

Error : Your stream is too big. Reduce the frame size and try your request again.

const getAudioStream = async function* () {
      yield {
        AudioEvent: {
          AudioChunk: encodePCMChunk(chunk),
        },
      };
};

Solution : Slicing chunks to keep each chunk small using a buffer

const getAudioStream = async function* () {
  let buffer = Buffer.alloc(0); // 버퍼 초기화

  for await (const chunk of microphoneStream) {
    buffer = Buffer.concat([buffer, chunk]); // 청크를 버퍼에 추가

    while (buffer.length >= CHUNK_LENGTH) {
      const audioChunk = buffer.slice(0, CHUNK_LENGTH); // 청크 길이만큼 버퍼에서 잘라내기
      buffer = buffer.slice(CHUNK_LENGTH); // 버퍼에서 청크 길이만큼 제거

      yield {
        AudioEvent: {
          AudioChunk: encodePCMChunk(audioChunk),
        },
      };
    }
  }
};