Text to Speech Component options

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

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,
Garden Gnome 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/
greg14369
Posts: 8
Joined: Mon Aug 10, 2020 2:46 pm
Location: USA
Contact:

Thanx Hopki,
I'm quite new to Pan2VR and have enjoyed your webinars immensely - thank you. Very concise and to the point. Since the implementation of the speech component I've tried diligently to turn off the speech when the "Info" hotspot was closed. Don't get me wrong, learning by mistakes is still the best teacher, but I don't like loose ends and prefer to "idiot proof" tours as much as possible.

I have more confidence now with this post in using this component. A little bit of coding never hurt anyone...

If we weren't in lock-down in Michigan and travel being what it is, I would buy you a couple of pints.

Cheers
Greg
User avatar
Hopki
Gnome
Posts: 12999
Joined: Thu Jan 10, 2008 3:16 pm
Location: Layer de la Haye, Essex UK
Contact:

Hi Greg,
I could not make out if you had solved the "stop talking" problem or not so please find attached a project that has an action to stop the talking on close button click or clicking the screen tint rectangle.
Regards,
Attachments
project.zip
(17.39 KiB) Downloaded 445 times
Garden Gnome 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