startMedicalStreamTranscription method

Future<StartMedicalStreamTranscriptionResponse> startMedicalStreamTranscription({
  1. required AudioStream audioStream,
  2. required LanguageCode languageCode,
  3. required MediaEncoding mediaEncoding,
  4. required int mediaSampleRateHertz,
  5. required Specialty specialty,
  6. required Type type,
  7. MedicalContentIdentificationType? contentIdentificationType,
  8. bool? enableChannelIdentification,
  9. int? numberOfChannels,
  10. String? sessionId,
  11. bool? showSpeakerLabel,
  12. String? vocabularyName,
})

Starts a bidirectional HTTP/2 or WebSocket stream where audio is streamed to Amazon Transcribe Medical and the transcription results are streamed to your application.

The following parameters are required:

  • language-code
  • media-encoding
  • sample-rate
For more information on streaming with Amazon Transcribe Medical, see Transcribing streaming audio.

May throw BadRequestException. May throw ConflictException. May throw InternalFailureException. May throw LimitExceededException. May throw ServiceUnavailableException.

Parameter languageCode : Specify the language code that represents the language spoken in your audio.

Parameter mediaEncoding : Specify the encoding used for the input audio. Supported formats are:

  • FLAC
  • OPUS-encoded audio in an Ogg container
  • PCM (only signed 16-bit little-endian audio formats, which does not include WAV)
For more information, see Media formats.

Parameter mediaSampleRateHertz : The sample rate of the input audio (in hertz). Amazon Transcribe Medical supports a range from 16,000 Hz to 48,000 Hz. Note that the sample rate you specify must match that of your audio.

Parameter specialty : Specify the medical specialty contained in your audio.

Parameter type : Specify the type of input audio. For example, choose DICTATION for a provider dictating patient notes and CONVERSATION for a dialogue between a patient and a medical professional.

Parameter contentIdentificationType : Labels all personal health information (PHI) identified in your transcript.

Content identification is performed at the segment level; PHI is flagged upon complete transcription of an audio segment.

For more information, see Identifying personal health information (PHI) in a transcription.

Parameter enableChannelIdentification : Enables channel identification in multi-channel audio.

Channel identification transcribes the audio on each channel independently, then appends the output for each channel into one transcript.

If you have multi-channel audio and do not enable channel identification, your audio is transcribed in a continuous manner and your transcript is not separated by channel.

If you include EnableChannelIdentification in your request, you must also include NumberOfChannels.

For more information, see Transcribing multi-channel audio.

Parameter numberOfChannels : Specify the number of channels in your audio stream. This value must be 2, as only two channels are supported. If your audio doesn't contain multiple channels, do not include this parameter in your request.

If you include NumberOfChannels in your request, you must also include EnableChannelIdentification.

Parameter sessionId : Specify a name for your transcription session. If you don't include this parameter in your request, Amazon Transcribe Medical generates an ID and returns it in the response.

Parameter showSpeakerLabel : Enables speaker partitioning (diarization) in your transcription output. Speaker partitioning labels the speech from individual speakers in your media file.

For more information, see Partitioning speakers (diarization).

Parameter vocabularyName : Specify the name of the custom vocabulary that you want to use when processing your transcription. Note that vocabulary names are case sensitive.

Implementation

Future<StartMedicalStreamTranscriptionResponse>
    startMedicalStreamTranscription({
  required AudioStream audioStream,
  required LanguageCode languageCode,
  required MediaEncoding mediaEncoding,
  required int mediaSampleRateHertz,
  required Specialty specialty,
  required Type type,
  MedicalContentIdentificationType? contentIdentificationType,
  bool? enableChannelIdentification,
  int? numberOfChannels,
  String? sessionId,
  bool? showSpeakerLabel,
  String? vocabularyName,
}) async {
  _s.validateNumRange(
    'mediaSampleRateHertz',
    mediaSampleRateHertz,
    8000,
    48000,
    isRequired: true,
  );
  _s.validateNumRange(
    'numberOfChannels',
    numberOfChannels,
    2,
    1152921504606846976,
  );
  final headers = <String, String>{
    'x-amzn-transcribe-language-code': languageCode.value,
    'x-amzn-transcribe-media-encoding': mediaEncoding.value,
    'x-amzn-transcribe-sample-rate': mediaSampleRateHertz.toString(),
    'x-amzn-transcribe-specialty': specialty.value,
    'x-amzn-transcribe-type': type.value,
    if (contentIdentificationType != null)
      'x-amzn-transcribe-content-identification-type':
          contentIdentificationType.value,
    if (enableChannelIdentification != null)
      'x-amzn-transcribe-enable-channel-identification':
          enableChannelIdentification.toString(),
    if (numberOfChannels != null)
      'x-amzn-transcribe-number-of-channels': numberOfChannels.toString(),
    if (sessionId != null)
      'x-amzn-transcribe-session-id': sessionId.toString(),
    if (showSpeakerLabel != null)
      'x-amzn-transcribe-show-speaker-label': showSpeakerLabel.toString(),
    if (vocabularyName != null)
      'x-amzn-transcribe-vocabulary-name': vocabularyName.toString(),
  };
  final response = await _protocol.sendRaw(
    payload: audioStream,
    method: 'POST',
    requestUri: '/medical-stream-transcription',
    headers: headers,
    exceptionFnMap: _exceptionFns,
  );
  final $json = await _s.jsonFromResponse(response);
  return StartMedicalStreamTranscriptionResponse(
    transcriptResultStream: MedicalTranscriptResultStream.fromJson($json),
    contentIdentificationType: _s
        .extractHeaderStringValue(
            response.headers, 'x-amzn-transcribe-content-identification-type')
        ?.let(MedicalContentIdentificationType.fromString),
    enableChannelIdentification: _s.extractHeaderBoolValue(
        response.headers, 'x-amzn-transcribe-enable-channel-identification'),
    languageCode: _s
        .extractHeaderStringValue(
            response.headers, 'x-amzn-transcribe-language-code')
        ?.let(LanguageCode.fromString),
    mediaEncoding: _s
        .extractHeaderStringValue(
            response.headers, 'x-amzn-transcribe-media-encoding')
        ?.let(MediaEncoding.fromString),
    mediaSampleRateHertz: _s.extractHeaderIntValue(
        response.headers, 'x-amzn-transcribe-sample-rate'),
    numberOfChannels: _s.extractHeaderIntValue(
        response.headers, 'x-amzn-transcribe-number-of-channels'),
    requestId:
        _s.extractHeaderStringValue(response.headers, 'x-amzn-request-id'),
    sessionId: _s.extractHeaderStringValue(
        response.headers, 'x-amzn-transcribe-session-id'),
    showSpeakerLabel: _s.extractHeaderBoolValue(
        response.headers, 'x-amzn-transcribe-show-speaker-label'),
    specialty: _s
        .extractHeaderStringValue(
            response.headers, 'x-amzn-transcribe-specialty')
        ?.let(Specialty.fromString),
    type: _s
        .extractHeaderStringValue(response.headers, 'x-amzn-transcribe-type')
        ?.let(Type.fromString),
    vocabularyName: _s.extractHeaderStringValue(
        response.headers, 'x-amzn-transcribe-vocabulary-name'),
  );
}