A Tutorial Introduction to SALT4. Simple Speech Recognition4.1 Recognition from a fixed set of phrasesOur next example is a program that recognises the names of countries that make up the European Union. This is, of course, a very easy recognition task and the recogniser should not really make any mistakes.
<html xmlns:salt="http://www.saltforum.org/2002/SALT">
<object id="speech-add-in" CLASSID="clsid:33cbfc53-a7de-491a-90f3-0e782a7e347a">
</object>
<?import namespace="salt" implementation="#speech-add-in"/>
<!-- SALT: Recognise European Union country -->
<salt:listen id="RecogEU">
<salt:grammar>
<grammar version="1.0" xml:lang="en-US"
xmlns="http://www.w3.org/2001/06/grammar" root="EUCountry">
<rule id="EUCountry" scope="public">
<one-of>
<item>Austria</item><item>Belgium</item><item>Cyprus</item>
<item>Czech Republic</item><item>Denmark</item>
Try this out on your computer: Normal version, Debug version. Let's look at the element tags in this example in more detail
Here is the application running: ![]() Note the little volume meter window. This provides feedback to the user that the system is waiting for speech, the volume of the sounds being recorded, and the amount of time available before recognition time out occurs. We will see how to adjust the time-out duration in a later example. 4.2 Simple variationIn the simple variation below, we recognise the country name and report the name of the capital of the country. We also refine the grammar so that the user can say "What is the capital of ..." if they want.
<html xmlns:salt="http://www.saltforum.org/2002/SALT">
<object id="speech-add-in" CLASSID="clsid:33cbfc53-a7de-491a-90f3-0e782a7e347a">
</object>
<?import namespace="salt" implementation="#speech-add-in"/>
<!-- SALT: Recognise European Union country -->
<salt:listen id="RecogEU" onreco="FindCapital()" babbletimeout="4">
<salt:grammar>
<grammar version="1.0" xml:lang="en-US"
xmlns="http://www.w3.org/2001/06/grammar" root="EUCountry">
<rule id="EUCountry" scope="public">
<item repeat="0-1">What is the capital of</item>
<one-of>
<item>Austria</item><item>Belgium</item><item>Cyprus</item>
<item>Czech Republic</item><item>Denmark</item><item>Estonia</item>
<item>Finland</item><item>France</item><item>Germany</item>
<item>Greece</item><item>Hungary</item><item>Ireland</item>
<item>Italy</item><item>Latvia</item><item>Lithuania</item>
<item>Luxembourg</item><item>Malta</item><item>Poland</item>
<item>Portugal</item><item>Slovakia</item><item>Slovenia</item>
<item>Spain</item><item>Sweden</item><item>The Netherlands</item>
<item>United Kingdom</item>
</one-of>
</rule>
</grammar>
</salt:grammar>
</salt:listen>
<body>
<h1>SALT: Find Capital of EU Country</h1>
<p>The Capital of
<input name="txtCountry" type="text" onclick="RecogEU.Start()" />
is
<input name="txtCapital" type="text" onclick="RecogEU.Start()" />.
<p>Click in text field, wait for level meter, speak country name.
</body>
<script>
function FindCapital()
{
var pRecog=document.getElementById("RecogEU");
var pCountry=document.getElementById("txtCountry");
var country = new String(pRecog.text);
country = country.replace("What is the capital of ","");
pCountry.value=country;
var pCapital=document.getElementById("txtCapital");
pCapital.value=LookupCapital(country);
}
function LookupCapital(country)
{
if (country=="Austria") return("Vienna");
else if (country=="Belgium") return("Brussels");
else if (country=="Cyprus") return("Nicosia");
else if (country=="Czech Republic") return("Prague");
else if (country=="Denmark") return("Copenhagen");
else if (country=="Estonia") return("Tallinn");
else if (country=="Finland") return("Helsinki");
else if (country=="France") return("Paris");
else if (country=="Germany") return("Berlin");
else if (country=="Greece") return("Athens");
else if (country=="Hungary") return("Budapest");
else if (country=="Ireland") return("Dublin");
else if (country=="Italy") return("Rome");
else if (country=="Latvia") return("Riga");
else if (country=="Lithuania") return("Vilnius");
else if (country=="Luxembourg") return("Luxembourg");
else if (country=="Malta") return("Valletta");
else if (country=="Poland") return("Warsaw");
else if (country=="Portugal") return("Lisbon");
else if (country=="Slovakia") return("Bratislava");
else if (country=="Slovenia") return("Ljubljana");
else if (country=="Spain") return("Madrid");
else if (country=="Sweden") return("Stockholm");
else if (country=="The Netherlands") return("Amsterdam");
else if (country=="United Kingdom") return("London");
else return("Unknown");
}
</script>
</html>
Try this out on your computer: Normal version, Debug version. The particular changes of note are:
This is how it looks: ![]() An exercise for youAdapt the European Capitals script so that it speaks the answer! Next: the <PROMPT> element in detail.
|
|
University College London - Gower Street - London - WC1E 6BT - |