다음과 StartStreamTranscriptionAsync 함께 사용하십시오. AWS SDK또는 CLI - Amazon Transcribe

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

다음과 StartStreamTranscriptionAsync 함께 사용하십시오. AWS SDK또는 CLI

다음 코드 예시에서는 StartStreamTranscriptionAsync을 사용하는 방법을 보여 줍니다.

C++
SDKC++용
참고

더 많은 정보가 있습니다. GitHub 전체 예제를 찾아 설치 및 실행 방법을 알아보십시오. AWS 코드 예제 리포지토리.

int main() { Aws::SDKOptions options; Aws::InitAPI(options); { //TODO(User): Set to the region of your AWS account. const Aws::String region = Aws::Region::US_WEST_2; //Load a profile that has been granted AmazonTranscribeFullAccess AWS managed permission policy. Aws::Client::ClientConfiguration config; #ifdef _WIN32 // ATTENTION: On Windows with the AWS C++ SDK, this example only runs if the SDK is built // with the curl library. // For more information, see the accompanying ReadMe. // For more information, see "Building the SDK for Windows with curl". // https://docs.aws.amazon.com/sdk-for-cpp/v1/developer-guide/setup-windows.html //TODO(User): Update to the location of your .crt file. config.caFile = "C:/curl/bin/curl-ca-bundle.crt"; #endif config.region = region; TranscribeStreamingServiceClient client(config); StartStreamTranscriptionHandler handler; handler.SetOnErrorCallback( [](const Aws::Client::AWSError<TranscribeStreamingServiceErrors> &error) { std::cerr << "ERROR: " + error.GetMessage() << std::endl; }); //SetTranscriptEventCallback called for every 'chunk' of file transcripted. // Partial results are returned in real time. handler.SetTranscriptEventCallback([](const TranscriptEvent &ev) { for (auto &&r: ev.GetTranscript().GetResults()) { if (r.GetIsPartial()) { std::cout << "[partial] "; } else { std::cout << "[Final] "; } for (auto &&alt: r.GetAlternatives()) { std::cout << alt.GetTranscript() << std::endl; } } }); StartStreamTranscriptionRequest request; request.SetMediaSampleRateHertz(SAMPLE_RATE); request.SetLanguageCode(LanguageCode::en_US); request.SetMediaEncoding( MediaEncoding::pcm); // wav and aiff files are PCM formats. request.SetEventStreamHandler(handler); auto OnStreamReady = [](AudioStream &stream) { Aws::FStream file(FILE_NAME, std::ios_base::in | std::ios_base::binary); if (!file.is_open()) { std::cerr << "Failed to open " << FILE_NAME << '\n'; } std::array<char, BUFFER_SIZE> buf; int i = 0; while (file) { file.read(&buf[0], buf.size()); if (!file) std::cout << "File: only " << file.gcount() << " could be read" << std::endl; Aws::Vector<unsigned char> bits{buf.begin(), buf.end()}; AudioEvent event(std::move(bits)); if (!stream) { std::cerr << "Failed to create a stream" << std::endl; break; } //The std::basic_istream::gcount() is used to count the characters in the given string. It returns //the number of characters extracted by the last read() operation. if (file.gcount() > 0) { if (!stream.WriteAudioEvent(event)) { std::cerr << "Failed to write an audio event" << std::endl; break; } } else { break; } std::this_thread::sleep_for(std::chrono::milliseconds( 25)); // Slow down because we are streaming from a file. } if (!stream.WriteAudioEvent( AudioEvent())) { // Per the spec, we have to send an empty event (an event without a payload) at the end. std::cerr << "Failed to send an empty frame" << std::endl; } else { std::cout << "Successfully sent the empty frame" << std::endl; } stream.flush(); stream.Close(); }; Aws::Utils::Threading::Semaphore signaling(0 /*initialCount*/, 1 /*maxCount*/); auto OnResponseCallback = [&signaling]( const TranscribeStreamingServiceClient * /*unused*/, const Model::StartStreamTranscriptionRequest & /*unused*/, const Model::StartStreamTranscriptionOutcome &outcome, const std::shared_ptr<const Aws::Client::AsyncCallerContext> & /*unused*/) { if (!outcome.IsSuccess()) { std::cerr << "Transcribe streaming error " << outcome.GetError().GetMessage() << std::endl; } signaling.Release(); }; std::cout << "Starting..." << std::endl; client.StartStreamTranscriptionAsync(request, OnStreamReady, OnResponseCallback, nullptr /*context*/); signaling.WaitOne(); // Prevent the application from exiting until we're done. std::cout << "Done" << std::endl; } Aws::ShutdownAPI(options); return 0; }

전체 목록을 보려면 AWS SDK개발자 가이드 및 코드 예제는 을 참조하십시오SDK와 함께 이 서비스 사용 AWS. 이 항목에는 시작에 대한 정보와 이전 SDK 버전에 대한 세부 정보도 포함되어 있습니다.