commonMain.aws.sdk.kotlin.services.transcribestreaming.transform.StartCallAnalyticsStreamTranscriptionOperationDeserializer.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of transcribestreaming-jvm Show documentation
Show all versions of transcribestreaming-jvm Show documentation
The AWS SDK for Kotlin client for Transcribe Streaming
// Code generated by smithy-kotlin-codegen. DO NOT EDIT!
package aws.sdk.kotlin.services.transcribestreaming.transform
import aws.sdk.kotlin.runtime.ClientException
import aws.sdk.kotlin.services.transcribestreaming.model.CallAnalyticsLanguageCode
import aws.sdk.kotlin.services.transcribestreaming.model.CallAnalyticsTranscriptResultStream
import aws.sdk.kotlin.services.transcribestreaming.model.ContentIdentificationType
import aws.sdk.kotlin.services.transcribestreaming.model.ContentRedactionType
import aws.sdk.kotlin.services.transcribestreaming.model.MediaEncoding
import aws.sdk.kotlin.services.transcribestreaming.model.PartialResultsStability
import aws.sdk.kotlin.services.transcribestreaming.model.StartCallAnalyticsStreamTranscriptionResponse
import aws.sdk.kotlin.services.transcribestreaming.model.TranscribeStreamingException
import aws.sdk.kotlin.services.transcribestreaming.model.VocabularyFilterMethod
import aws.smithy.kotlin.runtime.awsprotocol.eventstream.MessageType
import aws.smithy.kotlin.runtime.awsprotocol.eventstream.decodeFrames
import aws.smithy.kotlin.runtime.awsprotocol.eventstream.type
import aws.smithy.kotlin.runtime.awsprotocol.json.RestJsonErrorDeserializer
import aws.smithy.kotlin.runtime.awsprotocol.setAseErrorMetadata
import aws.smithy.kotlin.runtime.awsprotocol.withPayload
import aws.smithy.kotlin.runtime.http.HttpBody
import aws.smithy.kotlin.runtime.http.isSuccess
import aws.smithy.kotlin.runtime.http.operation.HttpDeserialize
import aws.smithy.kotlin.runtime.http.readAll
import aws.smithy.kotlin.runtime.http.response.HttpResponse
import aws.smithy.kotlin.runtime.http.toSdkByteReadChannel
import aws.smithy.kotlin.runtime.operation.ExecutionContext
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
internal class StartCallAnalyticsStreamTranscriptionOperationDeserializer: HttpDeserialize {
override suspend fun deserialize(context: ExecutionContext, response: HttpResponse): StartCallAnalyticsStreamTranscriptionResponse {
if (!response.status.isSuccess()) {
throwStartCallAnalyticsStreamTranscriptionError(context, response)
}
val builder = StartCallAnalyticsStreamTranscriptionResponse.Builder()
builder.contentIdentificationType = response.headers["x-amzn-transcribe-content-identification-type"]?.let { ContentIdentificationType.fromValue(it) }
builder.contentRedactionType = response.headers["x-amzn-transcribe-content-redaction-type"]?.let { ContentRedactionType.fromValue(it) }
builder.enablePartialResultsStabilization = response.headers["x-amzn-transcribe-enable-partial-results-stabilization"]?.toBoolean() ?: false
builder.languageCode = response.headers["x-amzn-transcribe-language-code"]?.let { CallAnalyticsLanguageCode.fromValue(it) }
builder.languageModelName = response.headers["x-amzn-transcribe-language-model-name"]
builder.mediaEncoding = response.headers["x-amzn-transcribe-media-encoding"]?.let { MediaEncoding.fromValue(it) }
builder.mediaSampleRateHertz = response.headers["x-amzn-transcribe-sample-rate"]?.toInt()
builder.partialResultsStability = response.headers["x-amzn-transcribe-partial-results-stability"]?.let { PartialResultsStability.fromValue(it) }
builder.piiEntityTypes = response.headers["x-amzn-transcribe-pii-entity-types"]
builder.requestId = response.headers["x-amzn-request-id"]
builder.sessionId = response.headers["x-amzn-transcribe-session-id"]
builder.vocabularyFilterMethod = response.headers["x-amzn-transcribe-vocabulary-filter-method"]?.let { VocabularyFilterMethod.fromValue(it) }
builder.vocabularyFilterName = response.headers["x-amzn-transcribe-vocabulary-filter-name"]
builder.vocabularyName = response.headers["x-amzn-transcribe-vocabulary-name"]
deserializeStartCallAnalyticsStreamTranscriptionOperationBody(builder, response.body)
return builder.build()
}
}
private suspend fun throwStartCallAnalyticsStreamTranscriptionError(context: ExecutionContext, response: HttpResponse): kotlin.Nothing {
val payload = response.body.readAll()
val wrappedResponse = response.withPayload(payload)
val errorDetails = try {
RestJsonErrorDeserializer.deserialize(response.headers, payload)
} catch (ex: Exception) {
throw TranscribeStreamingException("Failed to parse response as 'restJson1' error", ex).also {
setAseErrorMetadata(it, wrappedResponse, null)
}
}
val ex = when(errorDetails.code) {
"BadRequestException" -> BadRequestExceptionDeserializer().deserialize(context, wrappedResponse)
"ConflictException" -> ConflictExceptionDeserializer().deserialize(context, wrappedResponse)
"InternalFailureException" -> InternalFailureExceptionDeserializer().deserialize(context, wrappedResponse)
"LimitExceededException" -> LimitExceededExceptionDeserializer().deserialize(context, wrappedResponse)
"ServiceUnavailableException" -> ServiceUnavailableExceptionDeserializer().deserialize(context, wrappedResponse)
else -> TranscribeStreamingException(errorDetails.message)
}
setAseErrorMetadata(ex, wrappedResponse, errorDetails)
throw ex
}
internal suspend fun deserializeStartCallAnalyticsStreamTranscriptionOperationBody(builder: StartCallAnalyticsStreamTranscriptionResponse.Builder, body: HttpBody) {
val chan = body.toSdkByteReadChannel() ?: return
val events = decodeFrames(chan)
.map { message ->
when(val mt = message.type()) {
is MessageType.Event -> when(mt.shapeType) {
"UtteranceEvent" -> {
val e = deserializeUtteranceEventPayload(message.payload)
CallAnalyticsTranscriptResultStream.UtteranceEvent(e)
}
"CategoryEvent" -> {
val e = deserializeCategoryEventPayload(message.payload)
CallAnalyticsTranscriptResultStream.CategoryEvent(e)
}
else -> CallAnalyticsTranscriptResultStream.SdkUnknown
}
is MessageType.Exception -> when(mt.shapeType){
"BadRequestException" -> {
val err = deserializeBadRequestExceptionPayload(message.payload)
throw err
}
"LimitExceededException" -> {
val err = deserializeLimitExceededExceptionPayload(message.payload)
throw err
}
"InternalFailureException" -> {
val err = deserializeInternalFailureExceptionPayload(message.payload)
throw err
}
"ConflictException" -> {
val err = deserializeConflictExceptionPayload(message.payload)
throw err
}
"ServiceUnavailableException" -> {
val err = deserializeServiceUnavailableExceptionPayload(message.payload)
throw err
}
else -> throw TranscribeStreamingException("error processing event stream, unrecognized errorType: ${mt.shapeType}")
}
is MessageType.Error -> throw TranscribeStreamingException("error processing event stream: errorCode=${mt.errorCode}; message=${mt.message}")
is MessageType.SdkUnknown -> throw ClientException("unrecognized event stream message `:message-type`: ${mt.messageType}")
}
}
builder.callAnalyticsTranscriptResultStream = events
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy