/** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace Aws; using namespace Aws::Auth; using namespace Aws::Client; using namespace Aws::TranscribeStreamingService; using namespace Aws::TranscribeStreamingService::Model; using namespace Aws::Http; using namespace Aws::Utils::Json; using namespace smithy::components::tracing; using ResolveEndpointOutcome = Aws::Endpoint::ResolveEndpointOutcome; const char* TranscribeStreamingServiceClient::SERVICE_NAME = "transcribe"; const char* TranscribeStreamingServiceClient::ALLOCATION_TAG = "TranscribeStreamingServiceClient"; TranscribeStreamingServiceClient::TranscribeStreamingServiceClient(const TranscribeStreamingService::TranscribeStreamingServiceClientConfiguration& clientConfiguration, std::shared_ptr endpointProvider) : BASECLASS(clientConfiguration, Aws::MakeShared(ALLOCATION_TAG, Aws::MakeShared(ALLOCATION_TAG), SERVICE_NAME, Aws::Region::ComputeSignerRegion(clientConfiguration.region)), Aws::MakeShared(ALLOCATION_TAG)), m_clientConfiguration(clientConfiguration), m_executor(clientConfiguration.executor), m_endpointProvider(std::move(endpointProvider)) { init(m_clientConfiguration); } TranscribeStreamingServiceClient::TranscribeStreamingServiceClient(const AWSCredentials& credentials, std::shared_ptr endpointProvider, const TranscribeStreamingService::TranscribeStreamingServiceClientConfiguration& clientConfiguration) : BASECLASS(clientConfiguration, Aws::MakeShared(ALLOCATION_TAG, Aws::MakeShared(ALLOCATION_TAG, credentials), SERVICE_NAME, Aws::Region::ComputeSignerRegion(clientConfiguration.region)), Aws::MakeShared(ALLOCATION_TAG)), m_clientConfiguration(clientConfiguration), m_executor(clientConfiguration.executor), m_endpointProvider(std::move(endpointProvider)) { init(m_clientConfiguration); } TranscribeStreamingServiceClient::TranscribeStreamingServiceClient(const std::shared_ptr& credentialsProvider, std::shared_ptr endpointProvider, const TranscribeStreamingService::TranscribeStreamingServiceClientConfiguration& clientConfiguration) : BASECLASS(clientConfiguration, Aws::MakeShared(ALLOCATION_TAG, credentialsProvider, SERVICE_NAME, Aws::Region::ComputeSignerRegion(clientConfiguration.region)), Aws::MakeShared(ALLOCATION_TAG)), m_clientConfiguration(clientConfiguration), m_executor(clientConfiguration.executor), m_endpointProvider(std::move(endpointProvider)) { init(m_clientConfiguration); } /* Legacy constructors due deprecation */ TranscribeStreamingServiceClient::TranscribeStreamingServiceClient(const Client::ClientConfiguration& clientConfiguration) : BASECLASS(clientConfiguration, Aws::MakeShared(ALLOCATION_TAG, Aws::MakeShared(ALLOCATION_TAG), SERVICE_NAME, Aws::Region::ComputeSignerRegion(clientConfiguration.region)), Aws::MakeShared(ALLOCATION_TAG)), m_clientConfiguration(clientConfiguration), m_executor(clientConfiguration.executor), m_endpointProvider(Aws::MakeShared(ALLOCATION_TAG)) { init(m_clientConfiguration); } TranscribeStreamingServiceClient::TranscribeStreamingServiceClient(const AWSCredentials& credentials, const Client::ClientConfiguration& clientConfiguration) : BASECLASS(clientConfiguration, Aws::MakeShared(ALLOCATION_TAG, Aws::MakeShared(ALLOCATION_TAG, credentials), SERVICE_NAME, Aws::Region::ComputeSignerRegion(clientConfiguration.region)), Aws::MakeShared(ALLOCATION_TAG)), m_clientConfiguration(clientConfiguration), m_executor(clientConfiguration.executor), m_endpointProvider(Aws::MakeShared(ALLOCATION_TAG)) { init(m_clientConfiguration); } TranscribeStreamingServiceClient::TranscribeStreamingServiceClient(const std::shared_ptr& credentialsProvider, const Client::ClientConfiguration& clientConfiguration) : BASECLASS(clientConfiguration, Aws::MakeShared(ALLOCATION_TAG, credentialsProvider, SERVICE_NAME, Aws::Region::ComputeSignerRegion(clientConfiguration.region)), Aws::MakeShared(ALLOCATION_TAG)), m_clientConfiguration(clientConfiguration), m_executor(clientConfiguration.executor), m_endpointProvider(Aws::MakeShared(ALLOCATION_TAG)) { init(m_clientConfiguration); } /* End of legacy constructors due deprecation */ TranscribeStreamingServiceClient::~TranscribeStreamingServiceClient() { ShutdownSdkClient(this, -1); } std::shared_ptr& TranscribeStreamingServiceClient::accessEndpointProvider() { return m_endpointProvider; } void TranscribeStreamingServiceClient::init(const TranscribeStreamingService::TranscribeStreamingServiceClientConfiguration& config) { AWSClient::SetServiceClientName("Transcribe Streaming"); AWS_CHECK_PTR(SERVICE_NAME, m_endpointProvider); m_endpointProvider->InitBuiltInParameters(config); } void TranscribeStreamingServiceClient::OverrideEndpoint(const Aws::String& endpoint) { AWS_CHECK_PTR(SERVICE_NAME, m_endpointProvider); m_endpointProvider->OverrideEndpoint(endpoint); } void TranscribeStreamingServiceClient::StartCallAnalyticsStreamTranscriptionAsync(Model::StartCallAnalyticsStreamTranscriptionRequest& request, const StartCallAnalyticsStreamTranscriptionStreamReadyHandler& streamReadyHandler, const StartCallAnalyticsStreamTranscriptionResponseReceivedHandler& handler, const std::shared_ptr& handlerContext) const { if (!m_endpointProvider) { handler(this, request, StartCallAnalyticsStreamTranscriptionOutcome(Aws::Client::AWSError(TranscribeStreamingServiceErrors::INTERNAL_FAILURE, "INTERNAL_FAILURE", "Endpoint provider is not initialized", false)), handlerContext); return; } if (!request.LanguageCodeHasBeenSet()) { AWS_LOGSTREAM_ERROR("StartCallAnalyticsStreamTranscription", "Required field: LanguageCode, is not set"); handler(this, request, StartCallAnalyticsStreamTranscriptionOutcome(Aws::Client::AWSError(TranscribeStreamingServiceErrors::MISSING_PARAMETER, "MISSING_PARAMETER", "Missing required field [LanguageCode]", false)), handlerContext); return; } if (!request.MediaSampleRateHertzHasBeenSet()) { AWS_LOGSTREAM_ERROR("StartCallAnalyticsStreamTranscription", "Required field: MediaSampleRateHertz, is not set"); handler(this, request, StartCallAnalyticsStreamTranscriptionOutcome(Aws::Client::AWSError(TranscribeStreamingServiceErrors::MISSING_PARAMETER, "MISSING_PARAMETER", "Missing required field [MediaSampleRateHertz]", false)), handlerContext); return; } if (!request.MediaEncodingHasBeenSet()) { AWS_LOGSTREAM_ERROR("StartCallAnalyticsStreamTranscription", "Required field: MediaEncoding, is not set"); handler(this, request, StartCallAnalyticsStreamTranscriptionOutcome(Aws::Client::AWSError(TranscribeStreamingServiceErrors::MISSING_PARAMETER, "MISSING_PARAMETER", "Missing required field [MediaEncoding]", false)), handlerContext); return; } auto meter = m_telemetryProvider->getMeter(this->GetServiceClientName(), {}); auto endpointResolutionOutcome = TracingUtils::MakeCallWithTiming( [&]() -> ResolveEndpointOutcome { return m_endpointProvider->ResolveEndpoint(request.GetEndpointContextParams()); }, TracingUtils::SMITHY_CLIENT_ENDPOINT_RESOLUTION_METRIC, *meter, {{TracingUtils::SMITHY_METHOD_DIMENSION, request.GetServiceRequestName()}, {TracingUtils::SMITHY_SERVICE_DIMENSION, this->GetServiceClientName()}}); if (!endpointResolutionOutcome.IsSuccess()) { handler(this, request, StartCallAnalyticsStreamTranscriptionOutcome(Aws::Client::AWSError( CoreErrors::ENDPOINT_RESOLUTION_FAILURE, "ENDPOINT_RESOLUTION_FAILURE", endpointResolutionOutcome.GetError().GetMessage(), false)), handlerContext); return; } endpointResolutionOutcome.GetResult().AddPathSegments("/call-analytics-stream-transcription"); request.SetResponseStreamFactory( [&] { request.GetEventStreamDecoder().Reset(); return Aws::New(ALLOCATION_TAG, request.GetEventStreamDecoder()); } ); auto eventEncoderStream = Aws::MakeShared(ALLOCATION_TAG); eventEncoderStream->SetSigner(GetSignerByName(Aws::Auth::EVENTSTREAM_SIGV4_SIGNER)); request.SetAudioStream(eventEncoderStream); // this becomes the body of the request auto sem = Aws::MakeShared(ALLOCATION_TAG, 0, 1); request.SetRequestSignedHandler([eventEncoderStream, sem](const Aws::Http::HttpRequest& httpRequest) { eventEncoderStream->SetSignatureSeed(Aws::Client::GetAuthorizationHeader(httpRequest)); sem->ReleaseAll(); }); m_executor->Submit([this, endpointResolutionOutcome, &request, handler, handlerContext] () mutable { JsonOutcome outcome = MakeRequest(request, endpointResolutionOutcome.GetResult(), Aws::Http::HttpMethod::HTTP_POST, Aws::Auth::EVENTSTREAM_SIGV4_SIGNER); if(outcome.IsSuccess()) { handler(this, request, StartCallAnalyticsStreamTranscriptionOutcome(NoResult()), handlerContext); } else { request.GetAudioStream()->Close(); handler(this, request, StartCallAnalyticsStreamTranscriptionOutcome(outcome.GetError()), handlerContext); } return StartCallAnalyticsStreamTranscriptionOutcome(NoResult()); }); sem->WaitOne(); streamReadyHandler(*request.GetAudioStream()); } void TranscribeStreamingServiceClient::StartMedicalStreamTranscriptionAsync(Model::StartMedicalStreamTranscriptionRequest& request, const StartMedicalStreamTranscriptionStreamReadyHandler& streamReadyHandler, const StartMedicalStreamTranscriptionResponseReceivedHandler& handler, const std::shared_ptr& handlerContext) const { if (!m_endpointProvider) { handler(this, request, StartMedicalStreamTranscriptionOutcome(Aws::Client::AWSError(TranscribeStreamingServiceErrors::INTERNAL_FAILURE, "INTERNAL_FAILURE", "Endpoint provider is not initialized", false)), handlerContext); return; } if (!request.LanguageCodeHasBeenSet()) { AWS_LOGSTREAM_ERROR("StartMedicalStreamTranscription", "Required field: LanguageCode, is not set"); handler(this, request, StartMedicalStreamTranscriptionOutcome(Aws::Client::AWSError(TranscribeStreamingServiceErrors::MISSING_PARAMETER, "MISSING_PARAMETER", "Missing required field [LanguageCode]", false)), handlerContext); return; } if (!request.MediaSampleRateHertzHasBeenSet()) { AWS_LOGSTREAM_ERROR("StartMedicalStreamTranscription", "Required field: MediaSampleRateHertz, is not set"); handler(this, request, StartMedicalStreamTranscriptionOutcome(Aws::Client::AWSError(TranscribeStreamingServiceErrors::MISSING_PARAMETER, "MISSING_PARAMETER", "Missing required field [MediaSampleRateHertz]", false)), handlerContext); return; } if (!request.MediaEncodingHasBeenSet()) { AWS_LOGSTREAM_ERROR("StartMedicalStreamTranscription", "Required field: MediaEncoding, is not set"); handler(this, request, StartMedicalStreamTranscriptionOutcome(Aws::Client::AWSError(TranscribeStreamingServiceErrors::MISSING_PARAMETER, "MISSING_PARAMETER", "Missing required field [MediaEncoding]", false)), handlerContext); return; } if (!request.SpecialtyHasBeenSet()) { AWS_LOGSTREAM_ERROR("StartMedicalStreamTranscription", "Required field: Specialty, is not set"); handler(this, request, StartMedicalStreamTranscriptionOutcome(Aws::Client::AWSError(TranscribeStreamingServiceErrors::MISSING_PARAMETER, "MISSING_PARAMETER", "Missing required field [Specialty]", false)), handlerContext); return; } if (!request.TypeHasBeenSet()) { AWS_LOGSTREAM_ERROR("StartMedicalStreamTranscription", "Required field: Type, is not set"); handler(this, request, StartMedicalStreamTranscriptionOutcome(Aws::Client::AWSError(TranscribeStreamingServiceErrors::MISSING_PARAMETER, "MISSING_PARAMETER", "Missing required field [Type]", false)), handlerContext); return; } auto meter = m_telemetryProvider->getMeter(this->GetServiceClientName(), {}); auto endpointResolutionOutcome = TracingUtils::MakeCallWithTiming( [&]() -> ResolveEndpointOutcome { return m_endpointProvider->ResolveEndpoint(request.GetEndpointContextParams()); }, TracingUtils::SMITHY_CLIENT_ENDPOINT_RESOLUTION_METRIC, *meter, {{TracingUtils::SMITHY_METHOD_DIMENSION, request.GetServiceRequestName()}, {TracingUtils::SMITHY_SERVICE_DIMENSION, this->GetServiceClientName()}}); if (!endpointResolutionOutcome.IsSuccess()) { handler(this, request, StartMedicalStreamTranscriptionOutcome(Aws::Client::AWSError( CoreErrors::ENDPOINT_RESOLUTION_FAILURE, "ENDPOINT_RESOLUTION_FAILURE", endpointResolutionOutcome.GetError().GetMessage(), false)), handlerContext); return; } endpointResolutionOutcome.GetResult().AddPathSegments("/medical-stream-transcription"); request.SetResponseStreamFactory( [&] { request.GetEventStreamDecoder().Reset(); return Aws::New(ALLOCATION_TAG, request.GetEventStreamDecoder()); } ); auto eventEncoderStream = Aws::MakeShared(ALLOCATION_TAG); eventEncoderStream->SetSigner(GetSignerByName(Aws::Auth::EVENTSTREAM_SIGV4_SIGNER)); request.SetAudioStream(eventEncoderStream); // this becomes the body of the request auto sem = Aws::MakeShared(ALLOCATION_TAG, 0, 1); request.SetRequestSignedHandler([eventEncoderStream, sem](const Aws::Http::HttpRequest& httpRequest) { eventEncoderStream->SetSignatureSeed(Aws::Client::GetAuthorizationHeader(httpRequest)); sem->ReleaseAll(); }); m_executor->Submit([this, endpointResolutionOutcome, &request, handler, handlerContext] () mutable { JsonOutcome outcome = MakeRequest(request, endpointResolutionOutcome.GetResult(), Aws::Http::HttpMethod::HTTP_POST, Aws::Auth::EVENTSTREAM_SIGV4_SIGNER); if(outcome.IsSuccess()) { handler(this, request, StartMedicalStreamTranscriptionOutcome(NoResult()), handlerContext); } else { request.GetAudioStream()->Close(); handler(this, request, StartMedicalStreamTranscriptionOutcome(outcome.GetError()), handlerContext); } return StartMedicalStreamTranscriptionOutcome(NoResult()); }); sem->WaitOne(); streamReadyHandler(*request.GetAudioStream()); } void TranscribeStreamingServiceClient::StartStreamTranscriptionAsync(Model::StartStreamTranscriptionRequest& request, const StartStreamTranscriptionStreamReadyHandler& streamReadyHandler, const StartStreamTranscriptionResponseReceivedHandler& handler, const std::shared_ptr& handlerContext) const { if (!m_endpointProvider) { handler(this, request, StartStreamTranscriptionOutcome(Aws::Client::AWSError(TranscribeStreamingServiceErrors::INTERNAL_FAILURE, "INTERNAL_FAILURE", "Endpoint provider is not initialized", false)), handlerContext); return; } if (!request.MediaSampleRateHertzHasBeenSet()) { AWS_LOGSTREAM_ERROR("StartStreamTranscription", "Required field: MediaSampleRateHertz, is not set"); handler(this, request, StartStreamTranscriptionOutcome(Aws::Client::AWSError(TranscribeStreamingServiceErrors::MISSING_PARAMETER, "MISSING_PARAMETER", "Missing required field [MediaSampleRateHertz]", false)), handlerContext); return; } if (!request.MediaEncodingHasBeenSet()) { AWS_LOGSTREAM_ERROR("StartStreamTranscription", "Required field: MediaEncoding, is not set"); handler(this, request, StartStreamTranscriptionOutcome(Aws::Client::AWSError(TranscribeStreamingServiceErrors::MISSING_PARAMETER, "MISSING_PARAMETER", "Missing required field [MediaEncoding]", false)), handlerContext); return; } auto meter = m_telemetryProvider->getMeter(this->GetServiceClientName(), {}); auto endpointResolutionOutcome = TracingUtils::MakeCallWithTiming( [&]() -> ResolveEndpointOutcome { return m_endpointProvider->ResolveEndpoint(request.GetEndpointContextParams()); }, TracingUtils::SMITHY_CLIENT_ENDPOINT_RESOLUTION_METRIC, *meter, {{TracingUtils::SMITHY_METHOD_DIMENSION, request.GetServiceRequestName()}, {TracingUtils::SMITHY_SERVICE_DIMENSION, this->GetServiceClientName()}}); if (!endpointResolutionOutcome.IsSuccess()) { handler(this, request, StartStreamTranscriptionOutcome(Aws::Client::AWSError( CoreErrors::ENDPOINT_RESOLUTION_FAILURE, "ENDPOINT_RESOLUTION_FAILURE", endpointResolutionOutcome.GetError().GetMessage(), false)), handlerContext); return; } endpointResolutionOutcome.GetResult().AddPathSegments("/stream-transcription"); request.SetResponseStreamFactory( [&] { request.GetEventStreamDecoder().Reset(); return Aws::New(ALLOCATION_TAG, request.GetEventStreamDecoder()); } ); auto eventEncoderStream = Aws::MakeShared(ALLOCATION_TAG); eventEncoderStream->SetSigner(GetSignerByName(Aws::Auth::EVENTSTREAM_SIGV4_SIGNER)); request.SetAudioStream(eventEncoderStream); // this becomes the body of the request auto sem = Aws::MakeShared(ALLOCATION_TAG, 0, 1); request.SetRequestSignedHandler([eventEncoderStream, sem](const Aws::Http::HttpRequest& httpRequest) { eventEncoderStream->SetSignatureSeed(Aws::Client::GetAuthorizationHeader(httpRequest)); sem->ReleaseAll(); }); m_executor->Submit([this, endpointResolutionOutcome, &request, handler, handlerContext] () mutable { JsonOutcome outcome = MakeRequest(request, endpointResolutionOutcome.GetResult(), Aws::Http::HttpMethod::HTTP_POST, Aws::Auth::EVENTSTREAM_SIGV4_SIGNER); if(outcome.IsSuccess()) { handler(this, request, StartStreamTranscriptionOutcome(NoResult()), handlerContext); } else { request.GetAudioStream()->Close(); handler(this, request, StartStreamTranscriptionOutcome(outcome.GetError()), handlerContext); } return StartStreamTranscriptionOutcome(NoResult()); }); sem->WaitOne(); streamReadyHandler(*request.GetAudioStream()); }