What is @aws-amplify/predictions?
@aws-amplify/predictions is a part of the AWS Amplify library that provides machine learning capabilities to your web and mobile applications. It allows you to easily integrate features like text translation, speech generation, text recognition, and more using AWS services.
What are @aws-amplify/predictions's main functionalities?
Text Translation
This feature allows you to translate text from one language to another. In the code sample, the text 'Hello, how are you?' is translated from English to Spanish.
const { Predictions } = require('@aws-amplify/predictions');
Predictions.convert({
translateText: {
source: {
text: "Hello, how are you?",
language: "en"
},
targetLanguage: "es"
}
}).then(result => {
console.log(result.text);
}).catch(err => {
console.error(err);
});
Speech Generation
This feature converts text into speech. The code sample demonstrates converting the text 'Hello, how are you?' into an audio stream.
const { Predictions } = require('@aws-amplify/predictions');
Predictions.convert({
textToSpeech: {
source: {
text: "Hello, how are you?"
}
}
}).then(result => {
console.log(result.audioStream);
}).catch(err => {
console.error(err);
});
Text Recognition
This feature allows you to recognize text from an image. The code sample shows how to identify text from an image located at 'path/to/image.jpg'.
const { Predictions } = require('@aws-amplify/predictions');
Predictions.identify({
text: {
source: {
key: "path/to/image.jpg"
}
}
}).then(result => {
console.log(result.text);
}).catch(err => {
console.error(err);
});
Other packages similar to @aws-amplify/predictions
aws-sdk
The aws-sdk package is the official AWS SDK for JavaScript. It provides a wide range of AWS services, including those used by @aws-amplify/predictions. However, it requires more configuration and setup compared to the simplified interface provided by @aws-amplify/predictions.
tesseract.js
Tesseract.js is a pure JavaScript OCR (Optical Character Recognition) library. It provides text recognition capabilities similar to the text recognition feature in @aws-amplify/predictions but does not offer other machine learning functionalities like text translation or speech generation.