LumenVox Live Weather Demo
Weather Application

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.

Live Weather Application

Author: Adrian Isles

/*
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 */ 
}
Download Code

© 2016 LumenVox, LLC. All rights reserved.