Text to Speech Component options

Post Reply
User avatar
Hopki
Gnome
Posts: 10831
Joined: Thu Jan 10, 2008 3:16 pm
Location: Layer de la Haye, Essex UK
Contact:

Fri Nov 06, 2020 5:58 pm

Pano2VR ships with a Text to Speech component to add audio voice-overs for any text box or image element with Alt Text.
By default when you add the component to a skin you just need to add it as a child element to any text box to speak its contents.
For a video on how to use it please see this link: Text to Speech

The first mod you may want to do is to stop it talking, as an example when you change nodes it will continue to talk.
To do this automatically you can add a second action to the component.

Source: Before Node Change
Action: Go to URL
The the URL will be:

Code: Select all

javascript:
if (window.speechSynthesis) {
  window.speechSynthesis.cancel();
}
Leave the Target blank.

You can even add this to a Stop button using, Mouse Click, Go to URL and use the code above.
Ther are also the options to add Pause and Resume buttons.
Using a Mouse Click, Go top URL action use the following code.

Pause button URL code:

Code: Select all

javascript:
if (window.speechSynthesis) {
  window.speechSynthesis.pause();
}
Resume button code:

Code: Select all

javascript:
if (window.speechSynthesis) {
  window.speechSynthesis.resume();
}

Extending the functions
The default code ends with this code:

Code: Select all

    utter.text = text;
    synt.speak(utter);
    window.ggLastTTSElement=this;
You can add more attrobutes to the component
As an example I have added four new attobutes to the code, please see below:

Code: Select all

    utter.text = text; 
    utter.lang = 'en';
    utter.rate = 1;
    utter.pitch = 1;
    utter.volume = 1;
    synt.speak(utter);
    window.ggLastTTSElement=this;
The first option is utter.lang = 'en'; can be used to change the accent of the voice, note this is not a translation.
You can also force regional accents of the same language as well as different languages.
For example:
utter.lang = 'en';
utter.lang = 'en-UK'; English British accent
utter.lang = 'en-US'; English Ameriacan accent
So all "en" but three different accents.
Please note, this works well for Chrome and Firefox, but Safari on the Mac is part of the OS and not a separate application. This means it will use the OS voice settings.
If you go to Preferences => Accessibility => Speech you can add more languages and regional accents to macOS.
Please see ISO Language Code Table

The next attribute is utter.rate = 1;
This is the speed of the speech, 1 is the default, so 0.8 will be slower and 1.2 will be faster.

Then there is utter.pitch = 1;
Setting the number higher will increase the pitch of the voice, as an example 0.5 will be lower and 1.5 will be much higher.

Finally utter.volume = 1;
The default is 1 which seems to be the systems volume level, however, you can set lower volumes, so 0.5 is half as loud as your system volume.

Regards,
Hopki
Garden Gnome Software Support
If you send an e-mail to support please send a link to the forum post for reference.
support@ggnome.com
https://ggnome.com/wiki/documentation/
Post Reply