2015-11-28 6 views
8

私はvoiceXMLで新しく、投稿後にサーバーが値を返す方法を知りたいと思います。私は、voiceXMLにサーバの応答を読み込ませます。 According to voiceXML documentation、私は結果がXMLでなければならないことを理解します。ここでサーバーから返された結果を読み込むためにvoiceXMLを作成します。

は結果を受け、私のNode.js/express.jsコードです:

enter image description here

:ここ

app.post("/getData", function (req, res) { 
    console.log(JSON.stringify(req.body)); 
    res.header('Content-Type','text/xml').send('<?xml version="1.0" ?> <vxml version="2.0"> <block> <prompt> The time in Milwaukee is 10 </prompt> </block> </vxml>'); 
}); 

は、私が正常に投稿内容を受け付けておりますことを示すスクリーンショットであります以下は、XML結果を正常に送信していることを示すスクリーンショットです: enter image description here

ここに私のVoiceXMLファイルです:

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE vxml PUBLIC "-//BeVocal Inc//VoiceXML 2.0//EN" "http://cafe.bevocal.com/libraries/dtd/vxml2-0-bevocal.dtd"> 
<vxml xmlns="http://www.w3.org/2001/vxml" xmlns:bevocal="http://www.bevocal.com/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0"> 
    <form scope="dialog"> 
     <field name="name" modal="false"> 
      <grammar src="grammars.grammar#Names"/> 
      <prompt>Whats your name?</prompt> 
      <filled> 
       <prompt>Hello <value expr="name"/> 
       </prompt> 
      </filled> 
     </field> 

     <field name="city" modal="false"> 
      <grammar src="grammars.grammar#Cities"/> 
      <prompt>What city are you from?</prompt> 
      <filled> 
       <prompt>You are from <value expr="city"/> 
       </prompt> 
      </filled> 
     </field> 

     <field name="country" modal="false"> 
      <grammar src="grammars.grammar#Countries"/> 
      <prompt>What country are you from?</prompt> 
      <filled> 
       <prompt>You are from <value expr="country"/> 
       </prompt> 
      </filled> 
     </field> 

     <field name="cityTime"> 
      <prompt> 
       What city would you like the time for? 
      </prompt> 
      <grammar type="application/x-nuance-gsl"> 
       [denver (san francisco) ] 
      </grammar> 
     </field> 
     <field name="formatTime"> 
      <prompt> 
       Twelve hour or twenty four hour clock? 
      </prompt> 
      <grammar type="application/x-nuance-gsl"> 
       [[twelve (twenty four)] ?hour] 
      </grammar> 
     </field> 
     <block> 
      <submit next="http://65.29.170.122/getData" method="post" namelist="name city country cityTime formatTime" /> 
     </block> 
    </form> 
</vxml> 

答えて

7

2つのアプローチが用意されています まず、あなたの入力フォームを送信し、応答があなたのデータを果たし、新たなVoiceXMLドキュメントである必要があり収集した後。

第2に、ブラウザでサポートされている場合(ほとんどの場合)、Dataエレメントを使用してVoiceXMLフォームからリクエストを行うことができます。応答はXMLである必要があります。 VoiceXMLは結果として得られるDOMを歩き回ってデータを取得する方法を提供します。

データを読み上げる場合、ほとんどのブラウザは、プロンプト内でsay-as要素のSSMLをサポートしています。ほとんどのプロ用アプリケーションでは、典型的なアプローチは、時間を再生するために一連の録画を組み立てて再生するためのjavascriptライブラリを構築することです。

0

ファイルにPHPコードを追加し、xmlスクリプトを追加し、必要に応じてサーバーレスポンスをエコーし​​ます。この方法では、音声サーバが実際に取得する最終的なXMLにもPHPコードがありますが、phpを無視するので、結果をエコーし​​たXMLタグだけを取ります。たとえば:

<?php 
$appointmentTime = $_REQUEST['appointment_time']; 
?> 
<Response> 
    <Play> <?php echo $appointmentTime ?> </Play> 
</Response> 
関連する問題