Adrian Isles submitted the winning entry for the Application Contest for Q2. LiveWeather is a speech-enabled application that can query the user for either the name of a city and state or a zip code, then return updated internet weather information for the location given.
/*
The application may be split into following 3 components
1) Play Prompt & do recognition
2) Fetch the Weather
3) Playback the weather conditions
************************************
Play Prompt & do recognition
************************************
This is where the prompt is played and user speech-input is fed back into the engine via lumenvox speech module of asterisk.As an example of Yes-no questions & a confirmation.
*/
public boolean confirm(String confirmPromptFilename) throws AgiException {
boolean result = false;
this.exec("SpeechActivateGrammar","yes_no");
this.exec("SpeechBackground", confirmPromptFilename);
this.exec("SpeechStart");
String text = this.getFullVariable("${SPEECH_TEXT(0)}");
if (text.equals("yes"))
{
result = true;
}
this.exec("SpeechADeactivateGrammar","yes_no");
return result;
}
/************************************
Fetch the weather
*************************************
Here the program request's the weather by constructing a yahoo url and parses
the xml that is sent back as a response to this request.
*/
xmlBuffer = new StringBuffer();
yahooURL = new URL(YAHOO_URL + zipCode);
yahooC = yahooURL.openConnection();
yahooC.connect();
for(iIn = yahooC.getInputStream(); (len = iIn.read(buf)) > 0; ) {
xmlBuffer.append(new String( buf, 0, len ));
}
iIn.close();
xmlS = xmlBuffer.toString();
parseRssXml(xmlS);
/************************************
Playback the weather conditions
*************************************
Here the information fetched by the previous module is played back to the user. For example:
*/
void sayWeather( String locId, YahooWeatherFetcher y) throws AgiException {
* assumes y.getWeatherUsingZipCode() has been called */
sayAPhrase( dc.YAHOO_ACK_ULAW ); /* acknowlge Yahoo.com */
sayAPhrase( dc.CURW_ULAW ); /* The current weather at */
sayALocId( locId ); sayAPhrase( dc.IS_ULAW ); /* is */
sayYahooWeatherCode( y.currentYahooCode );
sayAPhrase( dc.WTEMP_ULAW ); /* with a temperature of */
sayANum( y.currentTemp ); sayAPhrase( dc.DF_ULAW ); /* degrees f */
sayAPhrase( dc.THE_FORCAST_ULAW ); /* The forcast for */
sayADay( y.forcastDay1 ); sayAPhrase( dc.IS_ULAW ); /* is */
sayYahooWeatherCode( y.forcastYahooCode1 );
sayAPhrase( dc.LOW_OF_ULAW ); /* with a low of */
sayANum( y.forcastLow1 );
sayAPhrase( dc.HIGH_OF_ULAW ); /* degrees f and a high of */
sayANum( y.forcastHigh1 );
sayAPhrase( dc.THE_FORCAST_ULAW ); /* The forcast for */
sayADay( y.forcastDay2 );
sayAPhrase( dc.IS_ULAW ); /* is */
sayYahooWeatherCode( y.forcastYahooCode2 );
sayAPhrase( dc.LOW_OF_ULAW ); /* with a low of */
sayANum( y.forcastLow2 );
sayAPhrase( dc.HIGH_OF_ULAW ); /* degrees f and a high of */
sayANum( y.forcastHigh2 );
sayAPhrase( dc.THATSALL_ULAW ); /* Thats all */
}
This is a quarterly contest to find sample application code, grammars, prompts and tools to post in this Asterisk Speech Application Zone. The panel of judges look for uniqueness and usability, and if your submission is chosen, you win free speech recognition software. Not only that, but you will be helping your fellow Asterisk community members speed up their application development process -- and you might find some useful code for yourself!
5 LumenVox Speech Engine Lite licenses.
(a value of $1225)
The deadline to submit your entry is Oct. 15th. The winner will be contacted via email by Oct. 30th. Please send a brief description of your application, along with the sample code, grammars, prompts or tools to News@LumenVox.com. All submissions will be considered public domain, and could potentially be posted on the internet. Please only send original code, commented code preferred. LumenVox can not endorse or be held responsible for the performance of any submission.
Good Luck, and may the best application code win!