Starts a bidirectional HTTP/2 stream, where audio is streamed to Amazon Web Services HealthScribe and the transcription results are streamed to your application.
When you start a stream, you first specify the stream configuration in a MedicalScribeConfigurationEvent. This event includes channel definitions, encryption settings, medical scribe context, and post-stream analytics settings, such as the output configuration for aggregated transcript and clinical note generation. These are additional streaming session configurations beyond those provided in your initial start request headers. Whether you are starting a new session or resuming an existing session, your first event must be a MedicalScribeConfigurationEvent.
After you send a MedicalScribeConfigurationEvent, you start AudioEvents and Amazon Web Services HealthScribe responds with real-time transcription results. When you are finished, to start processing the results with the post-stream analytics, send a MedicalScribeSessionControlEvent with a Type of END_OF_SESSION and Amazon Web Services HealthScribe starts the analytics.
You can pause or resume streaming. To pause streaming, complete the input stream without sending the MedicalScribeSessionControlEvent. To resume streaming, call the StartMedicalScribeStream and specify the same SessionId you used to start the stream.
The following parameters are required:
-
language-code
-
media-encoding
-
media-sample-rate-hertz
For more information on streaming with Amazon Web Services HealthScribe, see Amazon Web Services HealthScribe.
Parameters:
-
session_id
(Optional[SessionId], default:
None
)
–
Specify an identifier for your streaming session (in UUID format). If you don't include a SessionId in your request, Amazon Web Services HealthScribe generates an ID and returns it in the response.
-
language_code
(MedicalScribeLanguageCode)
–
Specify the language code for your HealthScribe streaming session.
-
media_sample_rate_hertz
(MedicalScribeMediaSampleRateHertz)
–
Specify the sample rate of the input audio (in hertz). Amazon Web Services HealthScribe supports a range from 16,000 Hz to 48,000 Hz. The sample rate you specify must match that of your audio.
-
media_encoding
(MedicalScribeMediaEncoding)
–
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.
-
input_stream
(Iterator[_MedicalScribeInputStream] | _MedicalScribeInputStream)
–
Specify the input stream where you will send events in real time.
The first element of the input stream must be a MedicalScribeConfigurationEvent.
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/transcribe_streaming.py
| @contextmanager
def start_medical_scribe_stream(
self,
language_code: "capo_transcribe_streaming.types.medical_scribe_language_code.MedicalScribeLanguageCode",
media_sample_rate_hertz: "capo_transcribe_streaming.types.medical_scribe_media_sample_rate_hertz.MedicalScribeMediaSampleRateHertz",
media_encoding: "capo_transcribe_streaming.types.medical_scribe_media_encoding.MedicalScribeMediaEncoding",
input_stream: "Iterator[capo_transcribe_streaming.types.medical_scribe_input_stream._MedicalScribeInputStream] | capo_transcribe_streaming.types.medical_scribe_input_stream._MedicalScribeInputStream",
*,
config_overrides: Optional[TranscribeStreamingClientConfig] = None,
session_id: Optional[
"capo_transcribe_streaming.types.session_id.SessionId"
] = None,
) -> "Generator[capo_transcribe_streaming.types.start_medical_scribe_stream_response.StartMedicalScribeStreamResponse]":
"""<p>Starts a bidirectional HTTP/2 stream, where audio is streamed to Amazon Web Services HealthScribe and the transcription results are streamed to your application.</p> <p>When you start a stream, you first specify the stream configuration in a <code>MedicalScribeConfigurationEvent</code>. This event includes channel definitions, encryption settings, medical scribe context, and post-stream analytics settings, such as the output configuration for aggregated transcript and clinical note generation. These are additional streaming session configurations beyond those provided in your initial start request headers. Whether you are starting a new session or resuming an existing session, your first event must be a <code>MedicalScribeConfigurationEvent</code>. </p> <p> After you send a <code>MedicalScribeConfigurationEvent</code>, you start <code>AudioEvents</code> and Amazon Web Services HealthScribe responds with real-time transcription results. When you are finished, to start processing the results with the post-stream analytics, send a <code>MedicalScribeSessionControlEvent</code> with a <code>Type</code> of <code>END_OF_SESSION</code> and Amazon Web Services HealthScribe starts the analytics. </p> <p>You can pause or resume streaming. To pause streaming, complete the input stream without sending the <code>MedicalScribeSessionControlEvent</code>. To resume streaming, call the <code>StartMedicalScribeStream</code> and specify the same SessionId you used to start the stream. </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>media-sample-rate-hertz</code> </p> </li> </ul> <p></p> <p>For more information on streaming with Amazon Web Services HealthScribe, see <a href="https://docs.aws.amazon.com/transcribe/latest/dg/health-scribe-streaming.html">Amazon Web Services HealthScribe</a>. </p>
Args:
session_id: <p>Specify an identifier for your streaming session (in UUID format). If you don't include a SessionId in your request, Amazon Web Services HealthScribe generates an ID and returns it in the response. </p>
language_code: <p>Specify the language code for your HealthScribe streaming session.</p>
media_sample_rate_hertz: <p>Specify the sample rate of the input audio (in hertz). Amazon Web Services HealthScribe supports a range from 16,000 Hz to 48,000 Hz. The sample rate you specify must match that of your audio. </p>
media_encoding: <p>Specify the encoding used for the input audio.</p> <p>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>
input_stream: <p>Specify the input stream where you will send events in real time.</p> <p>The first element of the input stream must be a <code>MedicalScribeConfigurationEvent</code>. </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.
"""
def _handler(
req: "OperationRequest[capo_transcribe_streaming.types.start_medical_scribe_stream_request.StartMedicalScribeStreamRequest]",
) -> OperationResponse[
"capo_transcribe_streaming.types.start_medical_scribe_stream_response.StartMedicalScribeStreamResponse"
]:
import capo_transcribe_streaming._operations.transcribe.start_medical_scribe_stream
output, http_response = (
capo_transcribe_streaming._operations.transcribe.start_medical_scribe_stream.start_medical_scribe_stream(
req.options, req.input
)
)
return OperationResponse(output=output, response=http_response)
def _redact_input(
input_: "capo_transcribe_streaming.types.start_medical_scribe_stream_request.StartMedicalScribeStreamRequest",
) -> dict[str, Any]:
import capo_transcribe_streaming.types.start_medical_scribe_stream_request
return capo_transcribe_streaming.types.start_medical_scribe_stream_request.redact_sensitive(
input_
)
def _redact_output(
output: "capo_transcribe_streaming.types.start_medical_scribe_stream_response.StartMedicalScribeStreamResponse",
) -> dict[str, Any]:
import capo_transcribe_streaming.types.start_medical_scribe_stream_response
return capo_transcribe_streaming.types.start_medical_scribe_stream_response.redact_sensitive(
output
)
interceptors_, options_ = self.operation_options(
config_overrides,
OperationLogging(
"StartMedicalScribeStream",
redact_input=_redact_input,
redact_output=_redact_output,
),
)
input_: capo_transcribe_streaming.types.start_medical_scribe_stream_request.StartMedicalScribeStreamRequest = {
"language_code": language_code,
"media_sample_rate_hertz": media_sample_rate_hertz,
"media_encoding": media_encoding,
"input_stream": ensure_sync_iterator(input_stream),
}
if session_id is not None:
input_["session_id"] = session_id
response = execute_pipeline(
OperationRequest(input=input_, options=options_),
handler=_handler,
interceptors=list(interceptors_),
)
try:
yield response.output
finally:
response.response.close()
|