Google Text to Speech Component — sgcAI | eSeGeCe

Text to Speech (Google)

TsgcTextToSpeechGoogle synthesises speech with Google Cloud Text-to-Speech. It signs a service account JWT, requests the audio, decodes it to a file and plays it through the audio player you assign, so a wide voice and language catalogue is a property away.

TsgcTextToSpeechGoogle

A Google Cloud speech backend. Paste the service account JSON into the options, choose the language, gender and voice, and call one method.

Component class

TsgcTextToSpeechGoogle

Purpose

Google Cloud speech synthesis

Platforms

Win32 and Win64

sgcAI is self-contained. This component ships inside sgcAI together with the sgcWebSockets Core runtime it is built on, so there is no base license to buy.

Speak with a Google Cloud voice

Provide the service account credentials, pick a voice, link an audio player.

uses
  sgcAI, sgcAI_TextToSpeech_Google, sgcAI_AudioPlayer_MCI;

var
  oTTS: TsgcTextToSpeechGoogle;
begin
  oTTS := TsgcTextToSpeechGoogle.Create(nil);
  oTTS.AudioPlayer := sgcAudioPlayerMCI1;

  // The service account JSON, pasted as-is.
  oTTS.GoogleOptions.Settings.LoadFromFile('service-account.json');
  oTTS.GoogleOptions.Language      := 'en-US';
  oTTS.GoogleOptions.VoiceId       := 'en-US-Neural2-C';
  oTTS.GoogleOptions.AudioEncoding := 'MP3';
  oTTS.GoogleOptions.FileName      := 'speech.mp3';

  oTTS.TextToSpeech('The order has been shipped.');
end;
// includes: sgcAI.hpp, sgcAI_TextToSpeech_Google.hpp

TsgcTextToSpeechGoogle *oTTS = new TsgcTextToSpeechGoogle(NULL);
oTTS->AudioPlayer = sgcAudioPlayerMCI1;

oTTS->GoogleOptions->Settings->LoadFromFile("service-account.json");
oTTS->GoogleOptions->Language = "en-US";
oTTS->GoogleOptions->VoiceId  = "en-US-Neural2-C";

oTTS->TextToSpeech("The order has been shipped.");

Key properties & methods

The members you reach for most often.

GoogleOptions

Settings holds the service account JSON, Language and VoiceId select the voice, Gender picks a default voice when no id is given, and AudioEncoding and FileName control the synthesised audio.

AudioPlayer

AudioPlayer plays the synthesised file. Assign a TsgcAudioPlayerMCI and playback starts as soon as the response arrives.

Authentication

The component builds and signs a JWT from the private key in the service account, then caches the access token until it expires, so a long-running application does not re-authenticate on every phrase.

TextToSpeech

TextToSpeech(aText) performs the whole cycle: request, decode, write, play and clean up the temporary file.

Lifecycle

OnStart and OnStop bracket the operation, which is what lets the chatbot and translator components resume recording once the reply has been spoken.

Interchangeable

The same interface as the system and Amazon speech components, so the chatbot, translator and assistant accept any of them without code changes.

Specifications & references

Authoritative sources for the services and protocols this component uses.

Keep exploring

Online HelpFull API reference and usage guide for the sgcAI components.
All sgcAI ComponentsBrowse the full feature matrix of all 15 components.
Download Free TrialSynthesise speech with your own Google Cloud project.
PricingSingle, Team and Site licenses, full source code, no base product required.
Best value: All-AccessEvery eSeGeCe product, Premium Support included, from €1,059/year.
See All-Access pricing

Ready to Get Started?

Download the free trial and give your application a Google Cloud voice.