<?xml version="1.0" encoding="utf-8"?> <MMWEATHER> <REPORT type="frc3"> <TOWN index="10381" sname="%C1%E5%F0%EB%E8%ED" latitude="52" longitude="13"> <FORECAST day="02" month="08" year="2011" hour="20" tod="3" predict="0" weekday="3"> <PHENOMENA cloudiness="0" precipitation="10" rpower="0" spower="0"/> <PRESSURE max="760" min="758"/> <TEMPERATURE max="21" min="19"/> <WIND min="2" max="4" direction="1"/> <RELWET max="74" min="72"/> <HEAT min="19" max="21"/> </FORECAST> <FORECAST day="03" month="08" year="2011" hour="02" tod="0" predict="0" weekday="4"> <PHENOMENA cloudiness="0" precipitation="10" rpower="0" spower="0"/> <PRESSURE max="761" min="759"/> <TEMPERATURE max="15" min="13"/> <WIND min="1" max="3" direction="1"/> <RELWET max="83" min="81"/> <HEAT min="13" max="15"/> </FORECAST> <FORECAST day="03" month="08" year="2011" hour="08" tod="1" predict="0" weekday="4"> <PHENOMENA cloudiness="0" precipitation="10" rpower="0" spower="0"/> <PRESSURE max="761" min="759"/> <TEMPERATURE max="18" min="16"/> <WIND min="2" max="4" direction="2"/> <RELWET max="80" min="78"/> <HEAT min="16" max="18"/> </FORECAST> <FORECAST day="03" month="08" year="2011" hour="14" tod="2" predict="0" weekday="4"> <PHENOMENA cloudiness="1" precipitation="10" rpower="0" spower="0"/> <PRESSURE max="760" min="758"/> <TEMPERATURE max="26" min="24"/> <WIND min="2" max="4" direction="2"/> <RELWET max="56" min="54"/> <HEAT min="22" max="24"/> </FORECAST> </TOWN> </REPORT> </MMWEATHER>
#!/bin/bash DIR=/var/www/html/gismeteo/xml /usr/bin/wget 'http://informer.gismeteo.ru/xml/27612_1.xml' -O $DIR/27612_1.xml # /usr/bin/wget 'http://informer.gismeteo.ru/xml/26063_1.xml' -O $DIR/26063_1.xml #- /usr/bin/wget 'http://informer.gismeteo.ru/xml/22892_1.xml' -O $DIR/22892_1.xml # /usr/bin/wget 'http://informer.gismeteo.ru/xml/29634_1.xml' -O $DIR/29634_1.xml # /usr/bin/wget 'http://informer.gismeteo.ru/xml/31960_1.xml' -O $DIR/31960_1.xml # /usr/bin/wget 'http://informer.gismeteo.ru/xml/26850_1.xml' -O $DIR/26850_1.xml # /usr/bin/wget 'http://informer.gismeteo.ru/xml/33345_1.xml' -O $DIR/33345_1.xml # /usr/bin/wget 'http://informer.gismeteo.ru/xml/36870_1.xml' -O $DIR/36870_1.xml # /usr/bin/wget 'http://informer.gismeteo.ru/xml/76680_1.xml' -O $DIR/76680_1.xml # /usr/bin/wget 'http://informer.gismeteo.ru/xml/2974_1.xml' -O $DIR/2974_1.xml # /usr/bin/wget 'http://informer.gismeteo.ru/xml/10381_1.xml' -O $DIR/10381_1.xml # /usr/bin/wget 'http://informer.gismeteo.ru/xml/48454_1.xml' -O $DIR/48454_1.xml #
<?xml version="1.0" encoding="utf-8"?> <grammar xml:lang="ru-RU" root="speak" mode="voice" version="1.0" xmlns="http://www.w3.org/2001/06/grammar" tag-format="semantics/1.0-literals"> <rule id="speak" scope="public"> <one-of> <item>!SYLLABLES</item> <item>!SYLLABLES <ruleref uri="#town"/> !SYLLABLES</item> </one-of> </rule> <rule id="town"> <one-of> <item><tag>27612_1.xml</tag></item> <item><tag>27612_1.xml</tag></item> <item>-<tag>26063_1.xml</tag></item> <item><tag>26063_1.xml</tag></item> <item><tag>26063_1.xml</tag></item> <item><tag>22892_1.xml</tag></item> <item><tag>29634_1.xml</tag></item> <item><tag>31960_1.xml</tag></item> <item><tag>26850_1.xml</tag></item> <item><tag>33345_1.xml</tag></item> <item><tag>36870_1.xml</tag></item> <item>-<tag>36870_1.xml</tag></item> <item><tag>36870_1.xml</tag></item> <item><tag>76680_1.xml</tag></item> <item><tag>2974_1.xml</tag></item> <item><tag>10381_1.xml</tag></item> <item><tag>48454_1.xml</tag></item> </one-of> </rule> </grammar>
<?xml version="1.0" encoding="utf-8"?> <grammar xml:lang="ru-RU" root="speak" mode="voice" version="1.0" xmlns="http://www.w3.org/2001/06/grammar" tag-format="semantics/1.0-literals"> <rule id="speak" scope="public"> <one-of> <item>!SYLLABLES</item> <item>!SYLLABLES <ruleref uri="#time"/> !SYLLABLES</item> </one-of> </rule> <rule id="time"> <one-of> <item> <tag>00</tag></item> <item> <tag>01</tag></item> <item> <tag>02</tag></item> <item> <tag>03</tag></item> <item> <tag>10</tag></item> <item> <tag>11</tag></item> <item> <tag>12</tag></item> <item> <tag>13</tag></item> </one-of> </rule> </grammar>
<?xml version="1.0" encoding="utf-8"?> <grammar xml:lang="ru-RU" root="speak" mode="voice" version="1.0" xmlns="http://www.w3.org/2001/06/grammar" tag-format="semantics/1.0-literals"> <rule id="speak" scope="public"> <one-of> <item>!SYLLABLES</item> <item>!SYLLABLES <ruleref uri="#check"/> !SYLLABLES</item> </one-of> </rule> <rule id="check"> <one-of> <item> <tag>city_choice</tag></item> <item> <tag>time_choice</tag></item> <item><tag>bye</tag></item> </one-of> </rule> </grammar>
city_choice.wav | Say the name of the city, the weather in which you are interested. |
no_input.wav | Speak, please, louder. |
error_city.wav | Sorry, incomprehensible. Repeat the name of the city. |
error.wav | I did not understand you. Please repeat. |
time_choice.wav | Say the weather for how long you are interested. For example, tomorrow afternoon. |
end_next.wav | To find out the weather in another city, say "choose a city." To find out the weather at another time of day, say “another time”. To end the call, say “finish”. |
bye.wav | Thank you for your call. Goodbye! |
not_found_time.wav | There is no weather data for the selected time. Choose a different time. |
#!/usr/bin/perl use XML::Simple; use Asterisk::AGI; use Time::localtime; use strict; $|=1; my $AGI = new Asterisk::AGI; my %var = $AGI->ReadParse(); # my $xml_file=$AGI->get_variable("xml_file"); my $xml_source="/var/www/html/gismeteo/xml/$xml_file"; if ($ARGV[0] eq "city"){ # = city, # xml- open (LIST, "/var/www/html/gismeteo/agi-bin/get_xml.sh") || die " get_xml.sh"; my $city=""; while (<LIST>) { if(m/$xml_file/) { ($city)=/#(.*)/; last; } } close(LIST); $AGI->set_variable('city' => $city); exit; } elsif ($ARGV[0] eq "time") { # # my @cl_time=$AGI->get_variable("RECOG_INT0")=~/(.)/g; # my $present_time=localtime(time()); my $present_weekday=$present_time->wday; # my @day=('',''); my @tod=('','','',''); my @cloudiness=('','','',''); my %precipitation=('4'=>'', '5'=>'', '6'=>'', '7'=>'', '8'=>'', '9'=>'', '10'=>' '); # XML- my $xmlWeather = new XML::Simple(keeproot => 1,searchpath => ".", forcearray => 1, suppressempty => ''); my $xmlTown = $xmlWeather->XMLin($xml_source); my $xmlData = $xmlTown->{MMWEATHER}[ 0]->{REPORT}[ 0]->{TOWN}[ 0]->{FORECAST}; my $i=0; # , for ($i=0; $i<4; $i++) { print "$xmlData->[$i]->{weekday}, $present_weekday%7+1+$cl_time[0], $xmlData->[$i]->{tod}\n"; if ($xmlData->[$i]->{weekday}==($present_weekday%7+1+$cl_time[0]) && $xmlData->[$i]->{tod}==$cl_time[1]) { $AGI->set_variable('speech_text' => "$day[$cl_time[0]] $tod[$xmlData->[$i]->{tod}] $xmlData->[$i]->{TEMPERATURE}[ 0]->{min} $xmlData->[$i]->{TEMPERATURE}[ 0]->{max} . $cloudiness[$xmlData->[$i]->{PHENOMENA}[ 0]->{cloudiness}]. $precipitation{$xmlData->[$i]->{PHENOMENA}[ 0]->{precipitation}}."); $AGI->set_priority('found'); exit; } } # , $AGI->set_priority('not_found'); }
[macro-recog-gismeteo] ;ARG1 - , ARG2 - , ARG3 - , ARG4 - exten => s,1,MRCPRecog(${GRAMMARS_PATH}/${ARG1},ct=0.20&b=1&f=${SND_PATH}/${ARG2}) exten => s,n(recog),SET(RECOG_HYP_NUM=0) exten => s,n,SET(RECOG_UTR0=) ; NLSML- exten => s,n,AGI(NLSML.agi,${QUOTE(${RECOG_RESULT})}) ; no-input exten => s,n,GotoIf(${REGEX("Completion-Cause: 002" ${RECOG_RESULT})}?$[${PRIORITY}+1]:check_error) exten => s,n,MRCPRecog(${GRAMMARS_PATH}/${ARG1},ct=0.20&b=1&f=${SND_PATH}/no_input) exten => s,n,Goto(recog) ; exten => s,n(check_error),GotoIf($["${RECOG_UTR0}" = ""]?$[${PRIORITY}+1]:ok) exten => s,n,MRCPRecog(${GRAMMARS_PATH}/${ARG1},ct=0.20&b=1&f=${SND_PATH}/${ARG3}) exten => s,n,Goto(recog) ; exten => s,n(ok),Goto(${MACRO_CONTEXT},${MACRO_EXTEN},${ARG4})
[gismeteo] exten => 6853,1,Goto(gismeteo,1) ; , exten => gismeteo,1,Answer() ; exten => gismeteo,n,Set(SND_PATH=/var/www/html/gismeteo/sounds) exten => gismeteo,n,Set(GRAMMARS_PATH=http://192.168.2.103/gismeteo/grammars) exten => gismeteo,n,Set(AGI_PATH=/var/www/html/gismeteo/agi-bin) ; exten => gismeteo,n(city_choice),Macro(recog-gismeteo,towns.xml,city_choice,error_city,$[${PRIORITY}+1]) exten => gismeteo,n,SET(xml_file=${RECOG_INT0}) ; AGI- exten => gismeteo,n,AGI(${AGI_PATH}/gismeteo.agi,city) exten => gismeteo,n,MRCPSynth(<?xml version=\"1.0\"?><speak version=\"1.0\" xml:lang=\"ru-ru\" xmlns=\"http://www.w3.org/2001/10/synthesis\"><voice name=\"8000\"> ${city}.</voice></speak>) ; exten => gismeteo,n(time_choice),Macro(recog-gismeteo,time.xml,time_choice,error,agi_check) ; AGI- exten => gismeteo,n(agi_check),AGI(${AGI_PATH}/gismeteo.agi,time) ; exten => gismeteo,n(not_found),Macro(recog-gismeteo,time.xml,not_found_time,error,agi_check) ; exten => gismeteo,n(found),MRCPSynth(<?xml version=\"1.0\"?><speak version=\"1.0\" xml:lang=\"ru-ru\" xmlns=\"http://www.w3.org/2001/10/synthesis\"><voice name=\"8000\">${speech_text}</voice></speak>) ; exten => gismeteo,n,Macro(recog-gismeteo,end_next.xml,end_next,error,$[${PRIORITY}+1]) exten => gismeteo,n,Goto(${RECOG_INT0}) exten => gismeteo,n(bye),Playback(${SND_PATH}/bye) exten => gismeteo,n,Hangup()
Source: https://habr.com/ru/post/125512/
All Articles