250 likes | 502 Views
VXML: return and submit. Speaker: Yan-Shiang Wang Date:2006.5.18. <return> element. The return element is used to terminate a subdialog and return control to the main dialog. The event and namelist attributes are mutually exclusive.
E N D
VXML: return and submit Speaker: Yan-Shiang Wang Date:2006.5.18
<return> element • The return element is used to terminate a subdialog and return control to the main dialog. • The event and namelist attributes are mutually exclusive. • The message and messageexpr attributes are mutually exclusive. • Parents • block, catch, error, filled, foreach, help, if, noinput, nomatch, prompt • Children • none
Demo1 - return (return.vxml) <?xml version="1.0" encoding="UTF-8"?> <vxml version = "2.1"> <form id="Demo1"> <subdialog name="SubD_1" src="MySubD.vxml"> <param name="confirm_prompt" expr="'Do you think Brokeback Mountain is a good movie?'"/> <filled> <if cond="SubD_1.response=='yes'"> <prompt>You are probably right.</prompt> <elseif cond="SubD_1.response=='no'"/> <prompt>You are probably wrong.</prompt> </if> </filled> </subdialog> </form> </vxml> Note:SubDialogName.FieldName
MySubD.vxml(1/2) <?xml version="1.0" encoding="UTF-8"?> <vxml version = "2.1"> <form id="Demo1"> <var name="confirm_prompt"/> <var name="response"/> <field name="field_confirm" type="boolean"> <prompt> <value expr="confirm_prompt"/> </prompt>
MySubD.vxml(2/2) <filled> <if cond="field_confirm == true"> <assign name="response" expr="'yes'"/> <else/> <assign name="response" expr="'no'"/> </if> <prompt>You say <value expr="response"/>.</prompt> <return namelist="response"/> </filled> </field> </form> </vxml>
<return> syntax & attributes <return event = "string" eventexpr = "ECMAScript_Expression" message = "string" messageexpr = "ECMAScript_Expression" namelist = "var-1 var-2 ... var-n" /> • event - event to throw to the subdialog • namelist - variables to return • eventexpr - event to throw (ECMAScript) • message - additional information about the event being thrown • messageexpr - additional information (ECMAScript)
Demo2 - return event (return1.vxml) <?xml version="1.0" encoding="UTF-8"?> <vxml version = "2.1"> <catch event="MyEvent"> <prompt>Of course. This is a demo for return event.</prompt> </catch> <form id="Demo2"> <subdialog name="SubD_1" src="MySubD_1.vxml"> <param name="confirm_prompt" expr="'This is a demo for return event, right?'"/> <filled> <prompt>I thought so.</prompt> </filled> </subdialog> </form> </vxml>
MySubD_1.vxml(1/2) <?xml version="1.0" encoding="UTF-8"?> <vxml version = "2.1"> <form id="Demo2"> <var name="confirm_prompt"/> <var name="response"/> <field name="field_confirm" type="boolean"> <prompt> <value expr="confirm_prompt"/> </prompt>
MySubD_1.vxml(2/2) <filled> <if cond="field_confirm == true"> <assign name="response" expr="'yes'"/> <else/> <assign name="response" expr="'no'"/> </if> <prompt>You say <value expr="response"/>.</prompt> <return event="MyEvent"/> </filled> </field> </form> </vxml>
Demo3 - return namelist (return2.vxml) <?xml version="1.0" encoding="UTF-8"?> <vxml version = "2.1"> <form id="Demo3"> <subdialog name="SubD_1" src="MySubD_2.vxml"> <param name="confirm_prompt" expr="'Do you think Brokeback Mountain is a good movie?'"/> <filled> <prompt>Your opinion about Brokeback Mountain is</prompt> <if cond="SubD_1.response1=='yes'"> <value expr="SubD_1.response2"/> <elseif cond="SubD_1.response1=='no'"/> <value expr="SubD_1.response2"/> </if> </filled> </subdialog> </form> </vxml>
MySubD_2.vxml(1/2) <?xml version="1.0" encoding="UTF-8"?> <vxml version = "2.1"> <form id="Demo3"> <var name="confirm_prompt"/> <var name="response1"/> <var name="response2"/> <field name="field_confirm" type="boolean"> <prompt> <value expr="confirm_prompt"/> </prompt>
MySubD_2.vxml(2/2) <filled> <if cond="field_confirm == true"> <assign name="response1" expr="'yes'"/> <assign name="response2" expr="'probably right.'"/> <else/> <assign name="response1" expr="'no'"/> <assign name="response2" expr="'probably wrong.'"/> </if> <prompt>You say <value expr="response1"/>.</prompt> <return namelist="response1 response2"/> </filled> </field> </form> </vxml> Note:namelist="var1 var2 var3 …"
<submit> element • The use of the submit tag will transition control to a new document, either via the GET or POST methods. • Dissimilar to the goto element, submit allows the developer to submit a space-delimited list of variables to the destination document. • Parents • block, catch, error, filled, foreach, help, if, noinput, nomatch, prompt • Children • none
<submit> syntax <submit enctype = "encoding_type" expr = "ECMAScript_Expression" fetchaudio = "URI" fetchaudioexpr = "ECMAScript_Expression" fetchhint = "string" fetchtimeout = "string" maxage = "seconds" maxstale = "seconds" method = "string" namelist = "string" next = "URI" />
<submit> attributes • namelist - variables to submit • next - target to submit (URI) • enctype - MIME encoding type of the submitted data • application/x-www-form-urlencoded (default) • multipart/form-data (binary data) • expr - target to submit (ECMAScript) • fetchaudio - audio to play while fetching resource (URI) • fetchaudioexpr - audio to play (ECMAScript)
<submit> attributes (cont.) • fetchhint - resource be fetched during application execution • prefetch - begin the resource fetch upon initial document execution • safe - resource may only be fetched when needed (default) • fetchtimeout - timeout seconds or milliseconds (default is 15s) • method - GET (default) or POST • strongly advised not to rely on this attributebest controlled by the hosting server's response headers • maxage - maximum acceptable age in sec (Cache-Control) • maxstale - maximum acceptable staleness in sec (Cache-Control)
Demo4 - submit_city (submit_city.vxml) <?xml version="1.0"?> <vxml version="2.1"> <form> <field name="city"> <prompt>What city do you want to visit, just choice it. Taipei press 1 Taichung press 2 Nantou press 3 Kaohsiung press 4 <option value="Taipei" dtmf="1">Taipei</option> <option value="Taichung" dtmf="2">Taichung</option> <option value="Nantou" dtmf="3">Nantou</option> <option value="Kaohsiung" dtmf="4">Kaohsiung</option> <filled> <submit next="city_intro.php" namelist="city"/> </filled> </field> </form> </vxml>
city_intro.php(1/2) <?php $user_get=$_REQUEST['city']; if ($user_get=="Taipei") $city_status="This is modern city."; else if ($user_get=="Taichung") $city_status="This is my hometown."; else if ($user_get=="Nantou") $city_status="I study here, now."; else $city_status="I have been there for 4 years."; $h = date("H"); $m = date(“i"); $s = date(“s"); echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; ?> Note:$_REQUEST['VaribleName']
city_intro.php(2/2) <vxml version="2.1"> <form> <block> <prompt> <prosody rate="-20%"> You choice <?=$user_get?>. <?=$city_status?> </prosody> <prosody rate="-40%"> Now is <?=$h?>clock <?=$m?> and <?=$s?>second. </prosody> </prompt> </block> </form> </vxml>
Demo5 - submit_record(1/2) (submit_record.vxml) <?xml version="1.0"?> <vxml version="2.1"> <form id="record_greeting"> <record name="personal_greeting" dtmfterm="true" beep="true"> <prompt> At the tone, please record your personal greeting. When you're done, press pound. </prompt> </record>
Demo5 - submit_record(2/2) <field name="conf"> <prompt> Here's what callers will hear. <break size="small"/> <audio expr="personal_greeting"/> </prompt> </field> <block> <submit next="mail_record.php" namelist="personal_greeting" method="post"/> </block> </form> </vxml>
mail_record.php(1/2) <?php $tmpFile=$HTTP_POST_FILES['personal_greeting']['tmp_name']; if (is_uploaded_file($tmpFile)) { $file_name = date("mdHi"); $wavfile="wav/" . $file_name . ".wav"; copy($tmpFile, sprintf("%s",$wavfile)); $msg = "audio saved"; include("basic_att_mail.php"); } else { $msg = "unable to save audio"; } ?> Note:mail the wav file via PHP script
mail_record.php(2/2) <vxml version="2.1"> <form> <var name="msg" expr="'<?=$msg?>'"/> <var name="file" expr="'<?=$file_name?>'"/> <block> <break size="medium"/> <value expr="msg"/> <break size="medium"/> <audio expr="'wav/' + file + '.wav'">your greeting</audio> </block> </form> </vxml>
Review • what we learn today • return • submit • dependence • subdialog • param • catch • record • audio
Reference • TellMe • https://studio.tellme.com/ • VoiceXML Development Guide • http://www.vxml.org/ • 究極PHP • 學貫出版 • Source Code • http://stu.csie.ncnu.edu.tw/~94321517/vxml_sourcecode.rar