Speak
Speak(text[,voice)
Description
The Speak function takes the text and reads it out loud. It uses the default browser voice, unless a different voice is specified.
The sound of a voice can be modified by setting the following global variables:
NSB.speech.lang | The language code. Examples are en-US, de-DE, ar-SA. |
NSB.speech.pitch | The pitch of the voice. A value between 0 and 2. Default is 1. |
NSB.speech.rate | The speed of the voice. A value from 0 to 10. Default is 1. |
NSB.speech.volume | The loudness of the voice. A value from 0 to 1. Default is 1. |
Not all combinations of pitch, rate and volume are available for all voices.
To see the list of voices for a particular device, use the SpeedSynthesis sample.
There are differences in implementation between different browsers and operating systems. In particular, each OS has a different list of voices.
Safari/iOS
Support is excellent. Mac OS and iOS have about 83 different voices. Most languages are supported, including Arabic.
Chrome/Android
Support is good. There are about 20 voices. Note that the names of the voices are not the same as in Safari, so different voice names are needed. No Arabic support.
Windows 10 =
Not supported, but it is under consideration.
Example (BASIC)
Rem Abs Example 'Abs returns the absolute value of a number. Print "Abs(-2) = " & Abs(-2) Print "Abs(2) = " & Abs(2)
Example (JavaScript)
//Abs Example //Abs returns the absolute value of a number. NSB.Print("Abs(-2) = " + Math.abs(-2)); NSB.Print("Abs(2) = " + Math.abs(2));
Output
Abs(-2) = 2 Abs(2) = 2