다음 코드 예제에서는 고객 의견 카드를 분석하고, 원어에서 번역하고, 감정을 파악하고, 번역된 텍스트에서 오디오 파일을 생성하는 애플리케이션을 생성하는 방법을 보여줍니다.
- .NET
-
- SDK for .NET
-
이 예제 애플리케이션은 고객 피드백 카드를 분석하고 저장합니다. 특히 뉴욕시에 있는 가상 호텔의 필요를 충족합니다. 호텔은 다양한 언어의 고객들로부터 물리적인 의견 카드의 형태로 피드백을 받습니다. 피드백은 웹 클라이언트를 통해 앱에 업로드됩니다. 의견 카드의 이미지가 업로드된 후 다음 단계가 수행됩니다.
-
Amazon Textract를 사용하여 이미지에서 텍스트가 추출됩니다.
-
Amazon Comprehend가 추출된 텍스트와 해당 언어의 감정을 파악합니다.
-
추출된 텍스트는 Amazon Translate를 사용하여 영어로 번역됩니다.
-
Amazon Polly가 추출된 텍스트에서 오디오 파일을 합성합니다.
전체 앱은 AWS CDK를 사용하여 배포할 수 있습니다. 소스 코드와 배포 지침은 GitHub
의 프로젝트를 참조하십시오. 이 예시에서 사용되는 서비스
Amazon Comprehend
Lambda
Amazon Polly
Amazon Textract
Amazon Translate
-
- Java
-
- SDK for Java 2.x
-
이 예제 애플리케이션은 고객 피드백 카드를 분석하고 저장합니다. 특히 뉴욕시에 있는 가상 호텔의 필요를 충족합니다. 호텔은 다양한 언어의 고객들로부터 물리적인 의견 카드의 형태로 피드백을 받습니다. 피드백은 웹 클라이언트를 통해 앱에 업로드됩니다. 의견 카드의 이미지가 업로드된 후 다음 단계가 수행됩니다.
-
Amazon Textract를 사용하여 이미지에서 텍스트가 추출됩니다.
-
Amazon Comprehend가 추출된 텍스트와 해당 언어의 감정을 파악합니다.
-
추출된 텍스트는 Amazon Translate를 사용하여 영어로 번역됩니다.
-
Amazon Polly가 추출된 텍스트에서 오디오 파일을 합성합니다.
전체 앱은 AWS CDK를 사용하여 배포할 수 있습니다. 소스 코드와 배포 지침은 GitHub
의 프로젝트를 참조하십시오. 이 예시에서 사용되는 서비스
Amazon Comprehend
Lambda
Amazon Polly
Amazon Textract
Amazon Translate
-
- JavaScript
-
- SDK for JavaScript (v3)
-
이 예제 애플리케이션은 고객 피드백 카드를 분석하고 저장합니다. 특히 뉴욕시에 있는 가상 호텔의 필요를 충족합니다. 호텔은 다양한 언어의 고객들로부터 물리적인 의견 카드의 형태로 피드백을 받습니다. 피드백은 웹 클라이언트를 통해 앱에 업로드됩니다. 의견 카드의 이미지가 업로드된 후 다음 단계가 수행됩니다.
-
Amazon Textract를 사용하여 이미지에서 텍스트가 추출됩니다.
-
Amazon Comprehend가 추출된 텍스트와 해당 언어의 감정을 파악합니다.
-
추출된 텍스트는 Amazon Translate를 사용하여 영어로 번역됩니다.
-
Amazon Polly가 추출된 텍스트에서 오디오 파일을 합성합니다.
전체 앱은 AWS CDK를 사용하여 배포할 수 있습니다. 소스 코드와 배포 지침은 GitHub
의 프로젝트를 참조하십시오. 다음 발췌문은 Lambda 함수 내에서 AWS SDK for JavaScript가 사용되는 방식을 보여줍니다. import { ComprehendClient, DetectDominantLanguageCommand, DetectSentimentCommand, } from "@aws-sdk/client-comprehend"; /** * Determine the language and sentiment of the extracted text. * * @param {{ source_text: string}} extractTextOutput */ export const handler = async (extractTextOutput) => { const comprehendClient = new ComprehendClient({}); const detectDominantLanguageCommand = new DetectDominantLanguageCommand({ Text: extractTextOutput.source_text, }); // The source language is required for sentiment analysis and // translation in the next step. const { Languages } = await comprehendClient.send( detectDominantLanguageCommand, ); const languageCode = Languages[0].LanguageCode; const detectSentimentCommand = new DetectSentimentCommand({ Text: extractTextOutput.source_text, LanguageCode: languageCode, }); const { Sentiment } = await comprehendClient.send(detectSentimentCommand); return { sentiment: Sentiment, language_code: languageCode, }; };
import { DetectDocumentTextCommand, TextractClient, } from "@aws-sdk/client-textract"; /** * Fetch the S3 object from the event and analyze it using Amazon Textract. * * @param {import("@types/aws-lambda").EventBridgeEvent<"Object Created">} eventBridgeS3Event */ export const handler = async (eventBridgeS3Event) => { const textractClient = new TextractClient(); const detectDocumentTextCommand = new DetectDocumentTextCommand({ Document: { S3Object: { Bucket: eventBridgeS3Event.bucket, Name: eventBridgeS3Event.object, }, }, }); // Textract returns a list of blocks. A block can be a line, a page, word, etc. // Each block also contains geometry of the detected text. // For more information on the Block type, see https://docs.aws.amazon.com/textract/latest/dg/API_Block.html. const { Blocks } = await textractClient.send(detectDocumentTextCommand); // For the purpose of this example, we are only interested in words. const extractedWords = Blocks.filter((b) => b.BlockType === "WORD").map( (b) => b.Text, ); return extractedWords.join(" "); };
import { PollyClient, SynthesizeSpeechCommand } from "@aws-sdk/client-polly"; import { S3Client } from "@aws-sdk/client-s3"; import { Upload } from "@aws-sdk/lib-storage"; /** * Synthesize an audio file from text. * * @param {{ bucket: string, translated_text: string, object: string}} sourceDestinationConfig */ export const handler = async (sourceDestinationConfig) => { const pollyClient = new PollyClient({}); const synthesizeSpeechCommand = new SynthesizeSpeechCommand({ Engine: "neural", Text: sourceDestinationConfig.translated_text, VoiceId: "Ruth", OutputFormat: "mp3", }); const { AudioStream } = await pollyClient.send(synthesizeSpeechCommand); const audioKey = `${sourceDestinationConfig.object}.mp3`; // Store the audio file in S3. const s3Client = new S3Client(); const upload = new Upload({ client: s3Client, params: { Bucket: sourceDestinationConfig.bucket, Key: audioKey, Body: AudioStream, ContentType: "audio/mp3", }, }); await upload.done(); return audioKey; };
import { TranslateClient, TranslateTextCommand, } from "@aws-sdk/client-translate"; /** * Translate the extracted text to English. * * @param {{ extracted_text: string, source_language_code: string}} textAndSourceLanguage */ export const handler = async (textAndSourceLanguage) => { const translateClient = new TranslateClient({}); const translateCommand = new TranslateTextCommand({ SourceLanguageCode: textAndSourceLanguage.source_language_code, TargetLanguageCode: "en", Text: textAndSourceLanguage.extracted_text, }); const { TranslatedText } = await translateClient.send(translateCommand); return { translated_text: TranslatedText }; };
이 예시에서 사용되는 서비스
Amazon Comprehend
Lambda
Amazon Polly
Amazon Textract
Amazon Translate
-
- Ruby
-
- SDK for Ruby
-
이 예제 애플리케이션은 고객 피드백 카드를 분석하고 저장합니다. 특히 뉴욕시에 있는 가상 호텔의 필요를 충족합니다. 호텔은 다양한 언어의 고객들로부터 물리적인 의견 카드의 형태로 피드백을 받습니다. 피드백은 웹 클라이언트를 통해 앱에 업로드됩니다. 의견 카드의 이미지가 업로드된 후 다음 단계가 수행됩니다.
-
Amazon Textract를 사용하여 이미지에서 텍스트가 추출됩니다.
-
Amazon Comprehend가 추출된 텍스트와 해당 언어의 감정을 파악합니다.
-
추출된 텍스트는 Amazon Translate를 사용하여 영어로 번역됩니다.
-
Amazon Polly가 추출된 텍스트에서 오디오 파일을 합성합니다.
전체 앱은 AWS CDK를 사용하여 배포할 수 있습니다. 소스 코드와 배포 지침은 GitHub
의 프로젝트를 참조하십시오. 이 예시에서 사용되는 서비스
Amazon Comprehend
Lambda
Amazon Polly
Amazon Textract
Amazon Translate
-
- SDK for .NET
-
이 예제 애플리케이션은 고객 피드백 카드를 분석하고 저장합니다. 특히 뉴욕시에 있는 가상 호텔의 필요를 충족합니다. 호텔은 다양한 언어의 고객들로부터 물리적인 의견 카드의 형태로 피드백을 받습니다. 피드백은 웹 클라이언트를 통해 앱에 업로드됩니다. 의견 카드의 이미지가 업로드된 후 다음 단계가 수행됩니다.
-
Amazon Textract를 사용하여 이미지에서 텍스트가 추출됩니다.
-
Amazon Comprehend가 추출된 텍스트와 해당 언어의 감정을 파악합니다.
-
추출된 텍스트는 Amazon Translate를 사용하여 영어로 번역됩니다.
-
Amazon Polly가 추출된 텍스트에서 오디오 파일을 합성합니다.
전체 앱은 AWS CDK를 사용하여 배포할 수 있습니다. 소스 코드와 배포 지침은 GitHub
의 프로젝트를 참조하십시오. 이 예시에서 사용되는 서비스
Amazon Comprehend
Lambda
Amazon Polly
Amazon Textract
Amazon Translate
-
AWS SDK 개발자 가이드 및 코드 예시의 전체 목록은 AWS SDK에서 Lambda 사용섹션을 참조하세요. 이 주제에는 시작하기에 대한 정보와 이전 SDK 버전에 대한 세부 정보도 포함되어 있습니다.