How To Use Amazon Polly To Easily Convert Text To Speech In Cross Platform Apps
Sometimes it’s best to say things out loud. Other times reading some text, or the contents of a message are either difficult or might even be impossible if, for example, you or your user have visual impairments. You certainly can’t be silent if you’re narrating a movie. Whatever your purpose, if you need a way to generate speech from text, the latest Appercept AWS SDK for Delphi supports Text-to-Speech (TTS) using Amazon Polly. This great solution works smoothly both for desktop and cross platform apps.
What is Amazon Polly?
Amazon Polly is a Text-to-Speech cloud service utilising Machine Learning (ML) to provide the most natural human-like voice synthesis. Polly provides various voices for different genders, languages, and ages. Polly supports Speech Synthesis Markup Language (SSML) to give more control and enhance the synthesis.
Here is how we say something…
{$APPTYPE CONSOLE}
implementation
uses
AWS.Polly;
var
Client: IPollyClient;
Request: IPollySynthesizeSpeechRequest;
Response: IPollySynthesizeSpeechResponse;
begin
Request := TPollySynthesizeSpeechRequest.Create;
Request.OutputFormat := ‘mp3’;
Request.Text := ‘Hello, Polly!’;
Request.VoiceId := ‘Aria’;
Client := TPollyClient.Create;
Response := Client.SynthesizeSpeech(Request);
if Response.IsSuccessful then
begin
// Do something with Response.AudioStream
end;
end.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
program SaySomething;
{$APPTYPE CONSOLE}
implementation
uses AWS.Polly;
var Client: IPollyClient; Request: IPollySynthesizeSpeechRequest; Response: IPollySynthesizeSpeechResponse;
begin Request := TPollySynthesizeSpeechRequest.Create; Request.OutputFormat := ‘mp3’; Request.Text := ‘Hello, Polly!’; Request.VoiceId := ‘Aria’;
Client := TPollyClient.Create; Response := Client.SynthesizeSpeech(Request); if Response.IsSuccessful then begin // Do something with Response.AudioStream end; end. |
To use enable and use SSML, just set the request property TextType to “ssml” and make sure you wrap the value in Text with a “
Request.TextType := ‘ssml’; Request.Text := ‘ |
How can I use Amazon Polly in my cross platform apps?
Why not check out the Polly Speak demo in our AWS SDK for Delphi Samples on GitHub for a complete example.
What will you “say” with Delphi and Polly? Why not tell us @ApperceptHQ.
About Appercept AWS SDK for Delphi
Appercept AWS SDK for Delphi is available exclusively on GetIt with active Enterprise or Architect subscriptions for Embarcadero Delphi or RAD Studio. You can install the SDK through the GetIt Package Manager.