javascriptv3/example_code/cross-services/transcribe-streaming-app/README.md
The cross-service example demonstrates how to build an app that records and transcribes an audio stream in real-time. It also demonstrates how to translate the transcription and send it via email to your contacts. The app uses the following AWS services:
The JavaScript SDK Transcribe Streaming client encapsulates the API into a JavaScript library that can be run on browsers, Node.js and potentially React Native. By default, the client uses HTTP/2 connection on Node.js, and uses WebSocket connection on browsers and React Native.
To build this cross-service example, you need the following:
Note: An unauthenticated role enables you to provide permissions to unauthenticated users to use the AWS Services. To create an authenticated role, see Amazon Cognito Identity Pools (Federated Identities).
For instructions on creating the minimum resources required for this tutorial, see Create the resources on this page.
You can create the AWS resources required for this cross-service example using either of the following:
To run the stack using the AWS CLI:
Install and configure the AWS CLI following the instructions in the AWS CLI User Guide.
Open the AWS Command Console from the ./transcribe-streaming-app folder.
Run the following command, replacing STACK_NAME with a unique name for the stack.
aws cloudformation create-stack --stack-name STACK_NAME --template-body file://setup.yaml --capabilities CAPABILITY_IAM
Important: The stack name must be unique within an AWS Region and AWS account. You can specify up to 128 characters, and numbers and hyphens are allowed.
For more information on the create-stack command parameters, see the AWS CLI Command Reference guide, and the AWS CloudFormation User Guide.
{
"Version": "2012-10-17",
"Statement": [
{
"Action": ["mobileanalytics:PutEvents", "cognito-sync:*"],
"Resource": "*",
"Effect": "Allow"
},
{
"Action": "ses:SendEmail",
"Resource": "*",
"Effect": "Allow"
},
{
"Action": "transcribe:StartStreamTranscriptionWebSocket",
"Resource": "*",
"Effect": "Allow"
},
{
"Action": "comprehend:DetectDominantLanguage",
"Resource": "*",
"Effect": "Allow"
},
{
"Action": "translate:TranslateText",
"Resource": "*",
"Effect": "Allow"
}
]
}
Create and verify an email address in Amazon SES. For more information, see Creating and verifying identities in Amazon SES.
Clone the AWS Code Samples repo to your local environment. See the Github documentation for instructions.
Run the following commands in sequence in the terminal to install the AWS service client modules and third-party modules listed in the package.json:
npm install
This app runs from the browser, so we create the interface using HTML and CSS. The app uses JavaScript to provide basic interactive features, and Node.js to invoke the AWS Services.
In index.html, the head section invoke the recorder.css, which applies styles to the HTML, and the index.js, which contains JavaScript and Node.js functions used in the app.
Each button on the interface invokes one of these functions when clicked.
The ./src/libs/ folders contains a file for each of the AWS Service clients required. In the awsID.js file, you must replace "REGION" with your AWS Region (e.g. us-west-2), and replace "IDENTITY_POOL_ID" with the Amazon Cognito identity pool id you created in Create the resources on this page.
./src/index.js imports all the required AWS Service and third party modules and contains the UI logic of the app.
Note: When using the app, make sure you use an email address you verified on Amazon SES in Create the resources on this page.
Important: You must bundle all the JavaScript and Node.js code required for the app into a single file (main.js) to run the app.
This is a static site consisting only of HTML, CSS, and client-side JavaScript. However, a build step is required to enable the modules to work natively in the browser.
To bundle the JavaScript and Node.js for this example in a single file named main.js, enter the following commands in sequence in the AWS CLI command line:
npm run build
This will create bundled scripts in the public folder.
npx http-server public
This will create a local web-server that hosts the content in the public folder. Open the URL displayed in the output of this command.
Select the stack you created in Create the resources on this page.
Choose Delete.