Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Audio data from microphone stream to Transcribe service #6

Closed
tan-yaka opened this issue Mar 2, 2022 · 1 comment
Closed

Audio data from microphone stream to Transcribe service #6

tan-yaka opened this issue Mar 2, 2022 · 1 comment

Comments

@tan-yaka
Copy link

tan-yaka commented Mar 2, 2022

I'm trying to adapt the transcription example to allow an incoming microphone stream to be forwarded to the Transcribe service but can't work out how to pipe the data from the incoming socket to the AudioStream async iterator. NodeJS code:

io.on('connection', function (socket) {
  console.log(`Client connected [id=${socket.id}]`);
  socket.emit('server-ready', `AWS STT Server ready [id=${socket.id}]`);

  socket.on('stt-start', async function () {
    await startRecognitionStream();
  });

  socket.on('stt-end', function () {
    stopRecognitionStream();
  });

  socket.on('stt-data', function (data) {
    // Incoming microphone audio data
    // How to get this into the transcribe AudioStream???
  });

  const transcribeIterator = async function* () {
    for await (const chunk of ???) {
      console.log(chunk);
      yield {
        AudioEvent: {
          AudioChunk: chunk,
        },
      };
    }
  };

  async function startRecognitionStream() {
    speechClient = new TranscribeStreamingClient({
      region: process.env.AWS_DEFAULT_REGION,
      credentials: {
        accessKeyId: process.env.AWS_ACCESS_KEY_ID,
        secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
      },
    });
    
    const startStreamTranscriptionCommand = new StartStreamTranscriptionCommand({
      LanguageCode: 'en-GB',
      MediaSampleRateHertz: 16000,
      MediaEncoding: 'pcm',
      AudioStream: transcribeIterator(),
    });

    const startStreamTranscriptionCommandOutput = await speechClient.send(startStreamTranscriptionCommand);

    for await (const transcriptionEvent of startStreamTranscriptionCommandOutput.TranscriptResultStream) {
      if (transcriptionEvent.TranscriptEvent.Transcript) {
        const results = transcriptionEvent.TranscriptEvent.Transcript.Results;
        console.log(results);
      }
    }
  }

Can anyone help?

@tan-yaka
Copy link
Author

tan-yaka commented Mar 4, 2022

If anyone else was stuck with this I was able to adapt this example https://github.com/amazon-archives/amazon-transcribe-websocket-static

@tan-yaka tan-yaka closed this as completed Mar 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant