Skip to content

AWS Transcribe Streaming client for producing real-time transcriptions for your media content using HTTP/2.

License

Notifications You must be signed in to change notification settings

javer/aws_transcribe_streaming

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AWS Transcribe Streaming client for producing real-time transcriptions for your media content using HTTP/2.

Getting started

Add necessary dependencies to pubspec.yaml:

dependencies:
  aws_common: ^0.6.0
  aws_transcribe_streaming: ^0.1.0

Obtain a pair of Access/Secret keys for the AWS IAM user with transcribe:StartStreamTranscription permission. See details in AWS documentation: Transcribing streaming audio

It is recommended to use Temporary security credentials with session token obtained from the backend just before starting the transcribing process.

See also best practices to improve streaming transcription efficiency.

Usage

  1. Create a new transcribe streaming client:
import 'package:aws_common/aws_common.dart';
import 'package:aws_transcribe_streaming/aws_transcribe_streaming.dart';

final transcribeStreamingClient = TranscribeStreamingClient(
  region: 'eu-central-1',
  credentialsProvider: StaticCredentialsProvider(AWSCredentials(
    'ASIAIOEXAMPLEEXAMPLE',                       // accessKeyId
    'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY',   // secretAccessKey
    'AQoDYXdzEJr...',                             // sessionToken
    DateTime.now().add(const Duration(hours: 1)), // expiration
  )),
);
  1. Start a stream transcription:
final (response, audioStreamSink, transcriptEventStream) =
    await transcribeStreamingClient.startStreamTranscription(
  const StartStreamTranscriptionRequest(
    languageCode: LanguageCode.enUs,
    mediaSampleRateHertz: 48000,
    mediaEncoding: MediaEncoding.pcm,
  ),
);
  1. Subscribe to a raw TranscriptEvent stream:
final transcriptSubscription = transcriptEventStream
    .listen((TranscriptEvent event) => print(event));

or use a custom strategy to decode TranscriptEvents and build the realtime transcription:

final transcriptSubscription = transcriptEventStream
    .transform(const TranscriptEventStreamDecoder(PlainTextTranscriptionStrategy()))
    .listen((String message) => print(message));
  1. Start sending audio data to the audio stream sink:
// Raw audio data from the microphone in PCM signed 16-bit little-endian audio format
Stream<Uint8List> audioStream;

final audioStreamSubscription = audioStream.listen(
  audioStreamSink.add,
  onDone: audioStreamSink.close,
);

About

AWS Transcribe Streaming client for producing real-time transcriptions for your media content using HTTP/2.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages