Wednesday 17 October 2012

Giving Your Computer A Voice

I've found it very helpful in a few cases to add audible alarms to monitoring functions. For example, if you work in a network support environment and a server goes down, you need to know about it straight away.......preferably before your phone goes into melt-down!


By using text-to-speech, you can monitor several aspects of your working environment without having to continually check display screens.

I recommend eSpeak, which is a compact, cross-platform, open source software, speech synthesiser. Although the sound is not as natural as that produced by a system based upon human recordings, its very small size makes it a good choice for small devices, the Raspberry Pi and for applications producing announcements.

Install on Linux

You will probably find eSpeak listed in your distributions repository. So on a Debian based system (e.g. Ubuntu) you can install via Synaptic package manager, or via a terminal:-
sudo apt-get install espeak

For other Linux distros, RISC, Mac OSX, or Windows:

Check It Out!

Note for Windows users: The examples that follow using Linux also apply to Windows, except that the Windows version allows you to run a gui app or a command line version.
For the command line version, at the command prompt type:-
 cd C:\Program Files\eSpeak\command_line

Now you can probably follow the Linux examples that follow.

Once installed, you can test it on a Linux system by typing something in a terminal:-
espeak hello
...or for more than single words...
espeak "hello steve"

You can change the default voice by using the voice switch, so:-
espeak -ven+f4 "the time is 2pm"

...should give you an English female voice, where the command option (-ven+f4) means: voice English female, the 4th female voice. There are 5 voice presets (1 - 5).

So for a male voice you might use:-
espeak -ven+m2 "I need a beer"

Having different voices can be useful. For example, you could use a female voice when a server goes down, and a male voice when a new job request arrives on you Help Desk. But with the monitoring system that we use, I've created 10 voices which are simply selected at random (its less monotonous that way).

You can also "speak" text files like this...
espeak -ven+f4 myTextFile

...but espeak is probably not the best choice for a book reader.

Using eSpeak With Gambas
It should be really easy to include eSpeak in your applications using a wide range of programming languages.

Here are some examples using Gambas, which is a Basic dialect for Linux, but you could do something similar in Visual Basic on a Windows system:-

strMessage="hello steve"
EXEC ["espeak", strMessage]

...or with more control:-

strMessage="Hello, My name is Monica"
's=rate, p=pitch, v=voice, f=female, k=emphasis on capitals
EXEC ["espeak", "-s130", "-p70", "-ven+f4", "-g5", "-k5", strMessage]

This is a simple Gambas speech alarm routine:-
PUBLIC SUB Alarm(strMessage AS String,strVoice AS String)

  SELECT CASE strVoice
    CASE "monica"
    CASE "bill"
    {more voices}

  's=rate, p=pitch, v=voice, f=female, k=emphasis on capitals
  EXEC ["espeak", "-s130", "-p70", strVoice, "-g5", "-k5", strMessage]
  WAIT 2 'you may need a delay depending upon repeat period & length of text

Take a look at the manual

Don't forget that on a Linux system you can check the manual from the terminal by typing:-
man espeak
...or in Windows:-
espeak --help

espeak -ven+m2 -k20 "That is All there is to it. Have fun."


No comments:

Post a Comment