Make your app talk!

AppStudio 5.1.1 adds a new text to speech function. It’s easy to use:

Speak("Can you hear me now?")

There are a lot of cool options (and some restrictions), so read on!

First, browser support.

  • Safari: Excellent support, both on the desktop and on iOS devices. Over 80 voices.
  • Chrome: Good support on desktop and Android devices. About 20 voices.
  • Edge: No support, but Microsoft lists it as “under consideration”

Voices

There is a variety of different voices on each platform. You can specify a voice as a second parameter in the Speak function:

  Speak("Hello","Alex")

“Alex” is a built in voice in Safari, a fairly neutral US accented voice (when the language is English). Safari has some interesting voices, including “Bad News”, “Good News”, “Bubbles”, “Bells” and “Princess”.

Chrome has a shorter list of voices. There isn’t any standardization of voices, so its list is completely different from Safari’s. Unless you’re using the default, you will need to specify different voices for each platform, like this:

  Dim voice
  If InStr(navigator.vendor,"Apple") Then voice = "Alex"
  If InStr(navigator.vendor,"Google") Then voice = "Google UK English Male"
  Speak("Hello World", voice)

To see the list of voices and test them in your browser, use the SpeechSynthesisAPI sample.

Language

Speech will normally be rendered in the browser’s default language. However, you can change the language to something else. To change to German, do the following:

NSB.speech.lang = "de-DE"

Not all languages are supported by all browsers. For example, Safari can speak Arabic (“ar-SA”), while Chrome cannot (as of this blog post).

Volume

The volume can be set to a value between 0 and 1. The default is 1:

NSB.speech.volume = .2

Some voices do not let you set the volume.

Pitch

The Pitch can be set to a value between 0 and 2. The default is 1:

NSB.speech.pitch = 1.5

Some voices do not let you set the pitch.

Rate

The Rate can be set to a value between 0 and 1. The default is 1:

NSB.speech.rate = .5

Some voices do not let you set the rate.