Skip to content

start_medical_stream_transcription async

start_medical_stream_transcription(
    language_code: LanguageCode,
    media_sample_rate_hertz: MediaSampleRateHertz,
    media_encoding: MediaEncoding,
    specialty: Specialty,
    type: Type,
    audio_stream: AsyncIterator[_AudioStream] | _AudioStream,
    *,
    config_overrides: Optional[AsyncTranscribeStreamingClientConfig] = None,
    vocabulary_name: Optional[VocabularyName] = None,
    show_speaker_label: Optional[Boolean] = None,
    session_id: Optional[SessionId] = None,
    enable_channel_identification: Optional[Boolean] = None,
    number_of_channels: Optional[NumberOfChannels] = None,
    content_identification_type: Optional[MedicalContentIdentificationType] = None,
) -> AsyncGenerator[StartMedicalStreamTranscriptionResponse]

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.

Parameters:

  • language_code (LanguageCode) –

    Specify the language code that represents the language spoken in your audio.

    Amazon Transcribe Medical only supports US English (en-US).

  • media_sample_rate_hertz (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.

  • media_encoding (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.

  • vocabulary_name (Optional[VocabularyName], default: None ) –

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

  • specialty (Specialty) –

    Specify the medical specialty contained in your audio.

  • type (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.

  • show_speaker_label (Optional[Boolean], default: None ) –

    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).

  • session_id (Optional[SessionId], default: None ) –

    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.

  • enable_channel_identification (Optional[Boolean], default: None ) –

    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.

  • number_of_channels (Optional[NumberOfChannels], default: None ) –

    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.

  • content_identification_type (Optional[MedicalContentIdentificationType], default: None ) –

    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.

Raises:

  • BadRequestException –

    One or more arguments to the StartStreamTranscription, StartMedicalStreamTranscription, or StartCallAnalyticsStreamTranscription operation was not valid. For example, MediaEncoding or LanguageCode used unsupported values. Check the specified parameters and try your request again.

  • ConflictException –

    A new stream started with the same session ID. The current stream has been terminated.

  • InternalFailureException –

    A problem occurred while processing the audio. Amazon Transcribe terminated processing.

  • LimitExceededException –

    Your client has exceeded one of the Amazon Transcribe limits, typically the concurrent stream service quota. This error can also occur if a stream exceeds the maximum session duration. In rare cases, this error can also occur if you increase your number of concurrent streams too quickly. Reduce your number of concurrent streams and try your request again using an exponential backoff strategy.

  • ServiceUnavailableException –

    The service is currently unavailable. Try your request later.

  • UnknownServiceError –

    The service returned an error code this client does not model.

Source code in docs_src/capo_transcribe_streaming/_services/async_transcribe_streaming.py
@asynccontextmanager
async def start_medical_stream_transcription(
    self,
    language_code: "capo_transcribe_streaming.types.language_code.LanguageCode",
    media_sample_rate_hertz: "capo_transcribe_streaming.types.media_sample_rate_hertz.MediaSampleRateHertz",
    media_encoding: "capo_transcribe_streaming.types.media_encoding.MediaEncoding",
    specialty: "capo_transcribe_streaming.types.specialty.Specialty",
    type: "capo_transcribe_streaming.types.type.Type",
    audio_stream: "AsyncIterator[capo_transcribe_streaming.types.audio_stream._AudioStream] | capo_transcribe_streaming.types.audio_stream._AudioStream",
    *,
    config_overrides: Optional[AsyncTranscribeStreamingClientConfig] = None,
    vocabulary_name: Optional[
        "capo_transcribe_streaming.types.vocabulary_name.VocabularyName"
    ] = None,
    show_speaker_label: Optional[
        "capo_transcribe_streaming.types.boolean.Boolean"
    ] = None,
    session_id: Optional[
        "capo_transcribe_streaming.types.session_id.SessionId"
    ] = None,
    enable_channel_identification: Optional[
        "capo_transcribe_streaming.types.boolean.Boolean"
    ] = None,
    number_of_channels: Optional[
        "capo_transcribe_streaming.types.number_of_channels.NumberOfChannels"
    ] = None,
    content_identification_type: Optional[
        "capo_transcribe_streaming.types.medical_content_identification_type.MedicalContentIdentificationType"
    ] = None,
) -> "AsyncGenerator[capo_transcribe_streaming.types.start_medical_stream_transcription_response.StartMedicalStreamTranscriptionResponse]":
    """<p>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.</p> <p>The following parameters are required:</p> <ul> <li> <p> <code>language-code</code> </p> </li> <li> <p> <code>media-encoding</code> </p> </li> <li> <p> <code>sample-rate</code> </p> </li> </ul> <p>For more information on streaming with Amazon Transcribe Medical, see <a href="https://docs.aws.amazon.com/transcribe/latest/dg/streaming.html">Transcribing streaming audio</a>.</p>

    Args:
        language_code: <p>Specify the language code that represents the language spoken in your audio.</p> <important> <p>Amazon Transcribe Medical only supports US English (<code>en-US</code>).</p> </important>
        media_sample_rate_hertz: <p>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.</p>
        media_encoding: <p>Specify the encoding used for the input audio. Supported formats are:</p> <ul> <li> <p>FLAC</p> </li> <li> <p>OPUS-encoded audio in an Ogg container</p> </li> <li> <p>PCM (only signed 16-bit little-endian audio formats, which does not include WAV)</p> </li> </ul> <p>For more information, see <a href="https://docs.aws.amazon.com/transcribe/latest/dg/how-input.html#how-input-audio">Media formats</a>.</p>
        vocabulary_name: <p>Specify the name of the custom vocabulary that you want to use when processing your transcription. Note that vocabulary names are case sensitive.</p>
        specialty: <p>Specify the medical specialty contained in your audio.</p>
        type: <p>Specify the type of input audio. For example, choose <code>DICTATION</code> for a provider dictating patient notes and <code>CONVERSATION</code> for a dialogue between a patient and a medical professional.</p>
        show_speaker_label: <p>Enables speaker partitioning (diarization) in your transcription output. Speaker partitioning labels the speech from individual speakers in your media file.</p> <p>For more information, see <a href="https://docs.aws.amazon.com/transcribe/latest/dg/diarization.html">Partitioning speakers (diarization)</a>.</p>
        session_id: <p>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.</p>
        enable_channel_identification: <p>Enables channel identification in multi-channel audio.</p> <p>Channel identification transcribes the audio on each channel independently, then appends the output for each channel into one transcript.</p> <p>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.</p> <p>If you include <code>EnableChannelIdentification</code> in your request, you must also include <code>NumberOfChannels</code>.</p> <p>For more information, see <a href="https://docs.aws.amazon.com/transcribe/latest/dg/channel-id.html">Transcribing multi-channel audio</a>.</p>
        number_of_channels: <p>Specify the number of channels in your audio stream. This value must be <code>2</code>, as only two channels are supported. If your audio doesn't contain multiple channels, do not include this parameter in your request.</p> <p>If you include <code>NumberOfChannels</code> in your request, you must also include <code>EnableChannelIdentification</code>.</p>
        content_identification_type: <p>Labels all personal health information (PHI) identified in your transcript.</p> <p>Content identification is performed at the segment level; PHI is flagged upon complete transcription of an audio segment.</p> <p>For more information, see <a href="https://docs.aws.amazon.com/transcribe/latest/dg/phi-id.html">Identifying personal health information (PHI) in a transcription</a>.</p>

    Raises:
        capo_transcribe_streaming.errors.bad_request_exception.BadRequestException: <p>One or more arguments to the <code>StartStreamTranscription</code>, <code>StartMedicalStreamTranscription</code>, or <code>StartCallAnalyticsStreamTranscription</code> operation was not valid. For example, <code>MediaEncoding</code> or <code>LanguageCode</code> used unsupported values. Check the specified parameters and try your request again.</p>
        capo_transcribe_streaming.errors.conflict_exception.ConflictException: <p>A new stream started with the same session ID. The current stream has been terminated.</p>
        capo_transcribe_streaming.errors.internal_failure_exception.InternalFailureException: <p>A problem occurred while processing the audio. Amazon Transcribe terminated processing.</p>
        capo_transcribe_streaming.errors.limit_exceeded_exception.LimitExceededException: <p>Your client has exceeded one of the Amazon Transcribe limits, typically the concurrent stream service quota. This error can also occur if a stream exceeds the maximum session duration. In rare cases, this error can also occur if you increase your number of concurrent streams too quickly. Reduce your number of concurrent streams and try your request again using an exponential backoff strategy.</p>
        capo_transcribe_streaming.errors.service_unavailable_exception.ServiceUnavailableException: <p>The service is currently unavailable. Try your request later.</p>
        capo_transcribe_streaming.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_transcribe_streaming.types.start_medical_stream_transcription_request.StartMedicalStreamTranscriptionRequest]",
    ) -> AsyncOperationResponse[
        "capo_transcribe_streaming.types.start_medical_stream_transcription_response.StartMedicalStreamTranscriptionResponse"
    ]:
        import capo_transcribe_streaming._operations.transcribe.start_medical_stream_transcription

        (
            output,
            http_response,
        ) = await capo_transcribe_streaming._operations.transcribe.start_medical_stream_transcription.async_start_medical_stream_transcription(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    def _redact_input(
        input_: "capo_transcribe_streaming.types.start_medical_stream_transcription_request.StartMedicalStreamTranscriptionRequest",
    ) -> dict[str, Any]:
        import capo_transcribe_streaming.types.start_medical_stream_transcription_request

        return capo_transcribe_streaming.types.start_medical_stream_transcription_request.redact_sensitive(
            input_
        )

    def _redact_output(
        output: "capo_transcribe_streaming.types.start_medical_stream_transcription_response.StartMedicalStreamTranscriptionResponse",
    ) -> dict[str, Any]:
        import capo_transcribe_streaming.types.start_medical_stream_transcription_response

        return capo_transcribe_streaming.types.start_medical_stream_transcription_response.redact_sensitive(
            output
        )

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging(
            "StartMedicalStreamTranscription",
            redact_input=_redact_input,
            redact_output=_redact_output,
        ),
    )
    input_: capo_transcribe_streaming.types.start_medical_stream_transcription_request.StartMedicalStreamTranscriptionRequest = {
        "language_code": language_code,
        "media_sample_rate_hertz": media_sample_rate_hertz,
        "media_encoding": media_encoding,
        "specialty": specialty,
        "type": type,
        "audio_stream": ensure_async_iterator(audio_stream),
    }
    if vocabulary_name is not None:
        input_["vocabulary_name"] = vocabulary_name
    if show_speaker_label is not None:
        input_["show_speaker_label"] = show_speaker_label
    if session_id is not None:
        input_["session_id"] = session_id
    if enable_channel_identification is not None:
        input_["enable_channel_identification"] = enable_channel_identification
    if number_of_channels is not None:
        input_["number_of_channels"] = number_of_channels
    if content_identification_type is not None:
        input_["content_identification_type"] = content_identification_type

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    try:
        yield response.output
    finally:
        await response.response.aclose()