This is a read-only archive. Find the latest Linux articles, documentation, and answers at the new Linux.com!

Linux.com

Feature: Open Source

Querying a database using open source voice control software

By Colin Beckingham on May 16, 2008 (9:00:00 AM)

Share    Print    Comments   

Though the tools for voice control and dictation in the open source world lag far behind those in the commercial arena, I decided to see how far I could get in querying a database by voice and having the computer respond verbally. Using a number of open source tools, I'm happy to report success.

I needed four basic components to perform the query:

  • The grammar and vocabulary -- a list of words that are relevant in this context, and how they are used together
  • Acoustic model -- a statistical representation of sounds that the engine can handle
  • Voice recognition engine -- does the work of deciphering what has been said
  • Dialog manager -- translates the interpreted instructions into commands for the system and generates the response

I used a number of popular and obscure open source tools:

  • Integrated Taxonomic Information System and MySQL. The ITIS database (a scientific database of current Latin Taxonomy which I will be querying) is freely downloadable, but it comes with an SQL schema for Informix rather than MySQL. I was able to massage the schema into MySQL dialect using guidance I found on one or two sites.
  • PHP and Perl for scripting
  • HMM Toolkit (HTK) from Cambridge University as the mathematical engine to generate the acoustic model. (There has been some discussion as to whether this software is truly open source. You can judge yourself from the terms of the license.)
  • Julius as the voice recognition engine
  • Audacity to record the voice samples
  • A lexicon as guide for phoneme structure, such as British English Example Pronunciations
  • Voxforge utilities to build the acoustic model using Perl and HTK
  • Festival from Edinburgh University to read back the results under the control of the dialog manager

The following discussion owes much to the Voxforge site, which I recommend as a guide to the process of building an acoustic model. It took me several hours to work through the tutorial the first time, but with experience and the ability to foresee and avoid errors, the time it takes to work through the whole process, including voice recording, falls rapidly.

The grammar

We're not building a dictation application here that listens and tries to interpret sounds into words selected from a large random vocabulary. We're dealing with a small set of specific commands we know in advance, which can be laid out and planned for.

Here are some anticipated commands:

  • COMPUTER SLEEP -- tell the computer to stop responding to commands while we do other things.
  • COMPUTER WAKE -- back to work
  • COMPUTER RESET -- restore a known configuration
  • COMPUTER QUIT -- end the program

In a quasi-meta format this could appear as:

COMPUTER ( SLEEP | WAKE | RESET | QUIT )

which simply says that the word "computer" could be followed by any one, but only one, of the words in parentheses. Expanding the grammar a bit more, we could add:

CONNECT ( LOCALHOST | SERVER1 | SERVER2 ) USE ( ITIS | OTHERDB )

... and so on. This gives you a flavor of the grammar.

Acoustic model

Once we have the grammar fully defined we can use the Voxforge tools, which in turn use Perl, HTK, and other commands, to set up the required files for generation of the acoustic model. Part of this process involves recording my voice saying the elements of the grammar. Applying the Voxforge tools to my recordings paints the statistical image or acoustic model of the grammar for the benefit of the speech recognition engine (SRE).

The Voxforge site offers two examples of how to prepare the acoustic model: a tutorial and a howto. The tutorial is a detailed explanation of the process and is a nice introduction to the field, particularly for beginners. The howto is a more automated version of the tutorial, which speeds up the whole process. I used the tutorial to begin with, then graduated to the howto to make fast modifications to my grammar and "print" them acoustically.

I used Audacity to record my prompts, but other utilities would do as well. I found it most efficient to record all of the prompts in one long .wav file, then use the label feature in Audacity to divide the audio file up with the "Export multiple" command from the menu.

Along the way we make the acquaintance of the required lexicon, which is a list of words together with the printed version of each word and its phoneme representation. Here is an example:

COMPUTER [COMPUTER] k ax m p y uw t ax r

At the end of this process the acoustic model is limited to the speaker's voice only; that is, it is speaker-dependent. This could be an advantage in terms of primitive security, or a disadvantage in terms of immediate use by others.

Speaker-independent models are a whole different kettle of fish. To find out more about this issue, see the Voxforge site, which was set up with the objective of resolving this issue in the open source domain.

Voice/speech recognition engine

We can now test the effectiveness of the acoustic model with the engine:

julius -input mic -C julian.jconf

Here, Julius, the voice recognition engine, gets input from the microphone and interprets the sounds according to the acoustic model instructions in the configuration file julian.jconf. The output will appear, together with diagnostics, in the terminal window. Here is an example as I say "COMPUTER WAKE."

### read waveform input pass1_best: <s> COMPUTER WAKE pass1_best_wordseq: 0 9 5 pass1_best_phonemeseq: sil | k ax m p y uw t ax r | w ey k pass1_best_score: -12243.838867 ### Recognition: 2nd pass (RL heuristic best-first) STAT: 00 _default: 26 generated, 26 pushed, 5 nodes popped in 444 sentence1: <s> COMPUTER WAKE </s> wseq1: 0 9 5 1 phseq1: sil | k ax m p y uw t ax r | w ey k | sil cmscore1: 1.000 1.000 1.000 1.000 score1: -12466.839844

In this case the SRE has hit the right command first time. Note that in both passes (the engine always does two passes) the SRE detected the correct sentence. The output includes score information which could be used to filter out words not recognized or otherwise doubtful. Absolute score values may differ in another model or situation.

The final command line will look something like this when typed into the Linux box:

julius -input mic -C julian.jconf | mydialogmanager.php

When we pipe the output to the dialog manager for interpretation and action, all of the information is passed up in the pipe, but only some of it is acted upon.

Dialog manager

The kernel of information we need here is in the line that begins with "sentence1:". We can throw away all other sentences unless we are in debugging mode or need to test scores. It is the job of the dialog manager to find that sentence, strip off the junk at the beginning and end, and leave us with "COMPUTER WAKE," which is a string that it can handle. Here is the introduction to a simple PHP dialog manager:

#!/usr/local/bin/php -q <?php $awake = false; $myloop = true; $in = defined('STDIN') ? STDIN : fopen('php://stdin' , 'r'); while ($myloop) { // infinite loop $line = fgets($in,1024); if (substr($line,0,8) == 'sentence') { $sent = substr($line,15,-5); $ok = more_stuff($sent); } } ?>

The code sets up a couple of status variables, makes sure that the input channel is defined to receive the output of Julius, and then goes into an infinite loop, constantly checking for more to do. The program waits until it sees an incoming string, then extracts the sentence.

What can the function more_stuff() do? One possibility is a switch statement:

switch ($sent) { case 'COMPUTER WAKE': $awake = true; break; case 'COMPUTER SLEEP': $awake = false; break; case 'COMPUTER RESET': // statements depending on other parts of the DM break; case 'COMPUTER QUIT': $myloop = false; break; default: if ($awake) { // go on and do interesting things with other statements } else { // do nothing } break; }

During the processing of commands we want to get Festival to read out results. We can accomplish this by sending a string to the following function, which I show as printing to the monitor for debugging as well as enunciating the result:

function saytext($phrase) { echo $phrase."\n"; exec('festival -b \'(SayText "'.$phrase.'")\''); }

Conclusion

Julius interprets my voice commands correctly pretty much 100% of the time, except for the first utterance of the session. In the first utterance the system has no previous utterance to use in its analysis and will sometimes make an error. It is easy to program around this and discard the first instruction.

Those more knowledgeable in speech recognition processes will have noted that I have made no mention of building in a "silence" part of the model to help filter out spurious and irrelevant commands. More information on this subject is available at the Voxforge site.

The grammar format we defined permits variable variables, in the sense that you can declare a grammar sentence like:

DIAL < ONE | TWO | THREE | FOUR >

The angle brackets indicate to the HTK toolkit that combinations such as DIAL TWO THREE, DIAL ONE, and DIAL FOUR ONE TWO TWO are all valid, but in this format my recognition accuracy fell off rapidly.

While the grammar format is necessarily a long way from natural language processing, a simple dialog manager is able to provide me with a readback from the database via Festival with few problems and with surprising accuracy.

Colin Beckingham is a freelance programmer and writer in Eastern Ontario. He is currently working on a project that logs and charts the operation of a biomass burner using open source resources.

Share    Print    Comments   

Comments

on Querying a database using open source voice control software

Note: Comments are owned by the poster. We are not responsible for their content.

Querying a database using open source voice control software

Posted by: Anonymous [ip: 85.24.88.228] on May 16, 2008 01:03 PM
Ok, this sounds obvious, but if it can be done this way, when do we see this in ubuntu...as an easy install, I believe that the elderly and the disabled community, plus the sci-fi freaks out there would be really well served by this type of technology....One more thing, how is this different from the sphinx project.

#

Querying a database using open source voice control software

Posted by: Mark Slade on May 16, 2008 03:02 PM
That is so Star Trek. It needs to be coded to include some beeps and blips, or maybe to confirm commands that don't otherwise garner a response with "Acknowledged". :D

#

Querying a database using open source voice control software

Posted by: Anonymous [ip: 91.45.154.16] on May 16, 2008 06:51 PM
Nice article and cool stuff. Thank you.

#1 - Don't think we'll see it easily included in mainstream distros. Like the article points out building and assembling such a system requires much hand-crafting and even a little programming.

Dennis

#

Querying a database using open source voice control software

Posted by: Anonymous [ip: 208.57.233.24] on May 21, 2008 07:50 PM
Any chance we can get a video or sound file of this in action?

#

This story has been archived. Comments can no longer be posted.



 
Tableless layout Validate XHTML 1.0 Strict Validate CSS Powered by Xaraya