Page updated Jan 16, 2024

Translate language

Set up the backend

If you haven't already done so, run amplify init inside your project and then amplify add auth (we recommend selecting the default configuration).

Run amplify add predictions and select Convert. Then use the following answers:

1? What would you like to convert? (Use arrow keys)
2❯ Convert text into a different language
3 Generate speech audio from text
4 Transcribe text from audio
5
6? Who should have access? Auth and Guest users

Now run amplify push which will generate your amplifyconfiguration.json and create resources in the cloud. You can now either add this to your backend or skip and add more features to your app.

Working with the API

Translate text from one source language to a destination language.

1import { Predictions } from '@aws-amplify/predictions';
2
3Predictions.convert({
4 translateText: {
5 source: {
6 text: textToTranslate,
7 // language : "es" // defaults configured on amplifyconfiguration.json
8 },
9 // targetLanguage: "en"
10 }
11})
12.then(result => console.log({ result }))
13.catch(err => console.log({ err }));

To view the complete list of supported languages refer to Supported languages and language codes.