Translate a chat channel using Amazon Translate
Every day millions of users around the world communicate with each other through email, social networks, and other online communities including chat platforms and message boards. Many times, users find a community interesting and want to participate in the chat conversation, but the primary language of the online community might be different than the language that user understands.
One of those communities is Twitch, the world’s leading social video service for gamers. Each day, millions of community members gather to watch, talk, and chat about shared interests. Chat is built into every stream, so instead of passively watching the stream, you can be part of the show. You will find many streamers on Twitch who don’t necessarily speak your language, but you might still enjoy their streams and would want to participate in the chat.
To make this communication possible, AWS provides Amazon Translate, a neural machine translation service that delivers fast, high-quality, and affordable language translation. Amazon Translate can provide on-demand translation to enable cross-lingual communication between users. By adding real-time translation to chat, email, helpdesk, and ticketing applications, an English-speaking agent or employee can communicate with customers across multiple languages.
This blog post covers how you can use Amazon Translate to enable cross-lingual chat for a Twitch channel. You will also learn how to use Amazon Polly, a Text-to-Speech service, to help voice incoming real-time messages. This additional functionality provides further access and offer users the option to listen to the messages while concentrating on other tasks at hand.
Create and Configure a Twitch account
- Go to twitch.tv to sign up for a Twitch account.
- After successfully signing up for your Twitch account, go to https://twitchapps.com/tmi to create a Twitch OAuth token.
- Click on the button “Connect with Twitch” and note the OAuth token.
Create an IAM user
AWS Identity and Access Management (IAM) enables you to manage access to AWS services and resources securely. Using IAM, you can create and manage AWS users and groups, and use permissions to allow and deny their access to AWS resources. To get started, create an IAM user with the minimum required permissions to run this example.
- Go to https://console.aws.amazon.com/iam/home?region=us-east-1#/users.
- Choose Add user.
- Enter the user name, check Programmatic access, and choose Next Permissions.
- Choose Attach existing policies directly, and search for translate.
- Select the check box next to TranslateReadOnly and choose Next Review.
- Choose Create user and note the access key ID and secret access key.
Create and run the application
- Create an HTML page and copy the code from the following code block.
- Update the following code snippet with the AWS region and endpoint.
- Update the following code snippet with your Twitch username, OAuth token, AWS access key ID and AWS secret access key.
- Open the web page in a browser.
- Enter the name of a Twitch channel.
- Select source and destination language and click Go.
You should now see real-time messages along with their translation on the screen. If you compare Twitch chat with this example application, you will see messages appear in the chat simultaneously as they appear in the Twitch chat showing the performance and very low latency from Amazon Translate.
You can also view the video demonstration showing the real-time translation of Twitch chat at re:Invent 2017.
Receive and Translate Messages
The following code block shows how you receive real-time incoming messages and then use AWS SDK to call Amazon Translate to show the translated message in the UI. As you see most of the code that follows is about input and UI handling, while the code to translate the messages is only few lines.
Send translated messages
The following code block shows how you translate an outgoing message and then send it the Twitch channel.
In this post you learned how you can use Amazon Translate for real-time translation of chat messages. This blog used a Twitch channel as an example, but you can use it as a starting point for other real-time streaming text like other chat platforms, customer service interactions, message boards and more.
About the Authors
Kashif Imran is a Solutions Architect at Amazon Web Services. He works with some of the largest strategic AWS customers to provide technical guidance and design advice. His expertise spans application architecture, serverless, containers, NoSQL and machine learning.