commonMain.aws.sdk.kotlin.services.transcribestreaming.serde.StartStreamTranscriptionOperationSerializer.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
The newest version!
// Code generated by smithy-kotlin-codegen. DO NOT EDIT!
package aws.sdk.kotlin.services.transcribestreaming.serde
import aws.sdk.kotlin.services.transcribestreaming.model.AudioStream
import aws.sdk.kotlin.services.transcribestreaming.model.ContentIdentificationType
import aws.sdk.kotlin.services.transcribestreaming.model.ContentRedactionType
import aws.sdk.kotlin.services.transcribestreaming.model.LanguageCode
import aws.sdk.kotlin.services.transcribestreaming.model.MediaEncoding
import aws.sdk.kotlin.services.transcribestreaming.model.PartialResultsStability
import aws.sdk.kotlin.services.transcribestreaming.model.StartStreamTranscriptionRequest
import aws.sdk.kotlin.services.transcribestreaming.model.VocabularyFilterMethod
import aws.smithy.kotlin.runtime.auth.awssigning.AwsSigningAttributes
import aws.smithy.kotlin.runtime.auth.awssigning.DefaultAwsSigner
import aws.smithy.kotlin.runtime.auth.awssigning.HashSpecification
import aws.smithy.kotlin.runtime.awsprotocol.eventstream.HeaderValue
import aws.smithy.kotlin.runtime.awsprotocol.eventstream.Message
import aws.smithy.kotlin.runtime.awsprotocol.eventstream.asEventStreamHttpBody
import aws.smithy.kotlin.runtime.awsprotocol.eventstream.buildMessage
import aws.smithy.kotlin.runtime.awsprotocol.eventstream.encode
import aws.smithy.kotlin.runtime.awsprotocol.eventstream.sign
import aws.smithy.kotlin.runtime.http.HttpBody
import aws.smithy.kotlin.runtime.http.HttpMethod
import aws.smithy.kotlin.runtime.http.operation.HttpSerializer
import aws.smithy.kotlin.runtime.http.request.HttpRequestBuilder
import aws.smithy.kotlin.runtime.http.request.headers
import aws.smithy.kotlin.runtime.http.request.url
import aws.smithy.kotlin.runtime.operation.ExecutionContext
import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.job
internal class StartStreamTranscriptionOperationSerializer: HttpSerializer.Streaming {
override suspend fun serialize(context: ExecutionContext, input: StartStreamTranscriptionRequest): HttpRequestBuilder {
val builder = HttpRequestBuilder()
builder.method = HttpMethod.POST
builder.url {
path.encoded = "/stream-transcription"
}
builder.headers {
if (input.contentIdentificationType != null) append("x-amzn-transcribe-content-identification-type", input.contentIdentificationType.value)
if (input.contentRedactionType != null) append("x-amzn-transcribe-content-redaction-type", input.contentRedactionType.value)
if (input.enableChannelIdentification != null) append("x-amzn-transcribe-enable-channel-identification", input.enableChannelIdentification.toString())
if (input.enablePartialResultsStabilization != null) append("x-amzn-transcribe-enable-partial-results-stabilization", input.enablePartialResultsStabilization.toString())
if (input.identifyLanguage != null) append("x-amzn-transcribe-identify-language", input.identifyLanguage.toString())
if (input.identifyMultipleLanguages != null) append("x-amzn-transcribe-identify-multiple-languages", input.identifyMultipleLanguages.toString())
if (input.languageCode != null) append("x-amzn-transcribe-language-code", input.languageCode.value)
if (input.languageModelName?.isNotEmpty() == true) append("x-amzn-transcribe-language-model-name", input.languageModelName)
if (input.languageOptions?.isNotEmpty() == true) append("x-amzn-transcribe-language-options", input.languageOptions)
if (input.mediaEncoding != null) append("x-amzn-transcribe-media-encoding", input.mediaEncoding.value)
if (input.mediaSampleRateHertz != null) append("x-amzn-transcribe-sample-rate", input.mediaSampleRateHertz.toString())
if (input.numberOfChannels != null) append("x-amzn-transcribe-number-of-channels", input.numberOfChannels.toString())
if (input.partialResultsStability != null) append("x-amzn-transcribe-partial-results-stability", input.partialResultsStability.value)
if (input.piiEntityTypes?.isNotEmpty() == true) append("x-amzn-transcribe-pii-entity-types", input.piiEntityTypes)
if (input.preferredLanguage != null) append("x-amzn-transcribe-preferred-language", input.preferredLanguage.value)
if (input.sessionId?.isNotEmpty() == true) append("x-amzn-transcribe-session-id", input.sessionId)
if (input.showSpeakerLabel != null) append("x-amzn-transcribe-show-speaker-label", input.showSpeakerLabel.toString())
if (input.vocabularyFilterMethod != null) append("x-amzn-transcribe-vocabulary-filter-method", input.vocabularyFilterMethod.value)
if (input.vocabularyFilterName?.isNotEmpty() == true) append("x-amzn-transcribe-vocabulary-filter-name", input.vocabularyFilterName)
if (input.vocabularyFilterNames?.isNotEmpty() == true) append("x-amzn-transcribe-vocabulary-filter-names", input.vocabularyFilterNames)
if (input.vocabularyName?.isNotEmpty() == true) append("x-amzn-transcribe-vocabulary-name", input.vocabularyName)
if (input.vocabularyNames?.isNotEmpty() == true) append("x-amzn-transcribe-vocabulary-names", input.vocabularyNames)
}
builder.body = serializeStartStreamTranscriptionOperationBody(context, input)
if (builder.body !is HttpBody.Empty) {
builder.headers.setMissing("Content-Type", "application/json")
}
return builder
}
}
internal suspend fun serializeStartStreamTranscriptionOperationBody(context: ExecutionContext, input: StartStreamTranscriptionRequest): HttpBody {
val stream = input.audioStream ?: return HttpBody.Empty
context[AwsSigningAttributes.HashSpecification] = HashSpecification.EmptyBody
context[AwsSigningAttributes.Signer] = DefaultAwsSigner
context[AwsSigningAttributes.RequestSignature] = CompletableDeferred(context.coroutineContext.job)
val messages = stream
.map(::encodeStartStreamTranscriptionAudioStreamEventMessage)
.sign(context)
.encode()
return messages.asEventStreamHttpBody(context)
}
private fun encodeStartStreamTranscriptionAudioStreamEventMessage(input: AudioStream): Message = buildMessage {
addHeader(":message-type", HeaderValue.String("event"))
when(input) {
is AudioStream.AudioEvent -> {
addHeader(":event-type", HeaderValue.String("AudioEvent"))
addHeader(":content-type", HeaderValue.String("application/octet-stream"))
payload = input.value.audioChunk
}
is AudioStream.ConfigurationEvent -> {
addHeader(":event-type", HeaderValue.String("ConfigurationEvent"))
addHeader(":content-type", HeaderValue.String("application/json"))
payload = serializeConfigurationEventPayload(input.value)
}
is AudioStream.SdkUnknown -> error("cannot serialize the unknown event type!")
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy