65.9K
CodeProject 正在变化。 阅读更多。
Home

基于 Voicent Gateway 的 IVR 应用程序(Java 示例接口)

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.33/5 (2投票s)

2008年6月11日

CPOL

6分钟阅读

viewsIcon

45745

由于所有这些功能都实现为直接与Voicent Gateway通信的HTTP客户端,因此它们可以在任何与运行网关的宿主有连接的机器上运行。C#接口源代码也包含在内。

IVR简介

交互式语音应答(IVR)应用程序使呼叫者能够通过电话与任何软件进行交互,例如查询和修改数据库信息。呼叫者可以使用他们的触控拨号盘输入请求,或者直接说出他们想做的事情,例如请求账户余额信息。IVR系统通常会使用文本转语音软件来读回信息。

Voicent Gateway背景

Voicent Gateway非常适合开发交互式电话应用程序,例如Voicent AutoReminder和Voicent BroadcastByPhone。基于W3C VoiceXML标准,Voicent Gateway能够通过任何电话实现对Web和企业系统的交互式语音访问。

Voicent Gateway可以部署在任何Windows 2000/2003/XP/Vista PC上,使得大多数小型企业和组织能够负担得起成本来开发和部署基于Voicent 的解决方案。网关还支持通过在单个计算机上使用多个调制解调器来支持多条电话线。对于大规模应用程序,可以通过Web界面将不同位置的多个网关联网。

当与Skype一起使用时,Voicent Gateway无需额外硬件。电话通过互联网拨打到固定电话或手机。网关还支持使用语音调制解调器连接常规模拟电话线。您可以结合使用Skype和语音调制解调器来轻松增加系统容量。

Voicent Gateway包含一个出站呼叫调度器,可以通过其HTTP接口访问。该接口可以轻松地与几乎任何应用程序和几乎任何编程语言集成。

本网站开发者部分提供了VoiceXML教程和示例。有关设置和选项,请参阅Voicent Gateway用户指南。该产品还有一个免费版本可供下载

您还可以使用IVR Studio来开发您的IVR应用程序。此工具使您无需任何VoiceXML知识即可进行灵活的应用程序开发。您只需点击即可绘制呼叫流程图。

使用IVR API

由于所有这些功能都实现为直接与Voicent Gateway通信的HTTP客户端,因此它们可以在任何连接到运行网关的宿主机器上运行。本节末尾提供了Java接口源代码

这个Java简单接口是基于Voicent Gateway简单出站呼叫接口开发的。

callText

String callText(String phoneno, String text, boolean selfdelete)

拨打电话并播放指定的文本消息。文本消息由Voicent Gateway的文本转语音引擎转换为语音。

选项有:

phoneno 要拨打的电话号码
文本 电话呼叫的消息
selfdelete 如果设置为“1”,则要求网关在呼叫拨打后自动删除呼叫请求

返回值是呼叫请求ID <reqId>

示例

callText("123-4567", "Hello, how are you doing", 1);

拨打“123-4567”电话号码并说“你好,你怎么样”。由于设置了selfdelete位,呼叫请求记录将在呼叫后自动从网关中删除。

String reqId = callText("123-4567", "Hello, how are you", 0);

拨打“123-4567”电话号码并说“你好,你怎么样”。由于未设置selfdelete位,呼叫请求记录在呼叫后不会从网关中删除。然后您可以使用callStatus获取呼叫状态,或使用callRemove删除呼叫记录。

callAudio

String callAudio(String phoneno, String audiofile, boolean selfdelete)

拨打电话并播放指定的音频消息。

选项有:

phoneno 要拨打的电话号码。
audiofile 电话呼叫的音频消息。格式必须是PCM 16位,8KHz,单声道波形文件。音频文件必须与Voicent Gateway位于同一宿主上。
selfdelete 如果设置为“1”,则要求网关在呼叫拨打后自动删除呼叫请求。

返回值是呼叫请求ID <reqId>

示例

callAudio("123-4567", "C:\my audios\hello.wav", 1);

拨打“123-4567”电话号码并播放hello.wav文件。由于设置了selfdelete位,呼叫请求记录将在呼叫后自动从网关中删除。

String reqId = callAudio("123-4567", "C:\my audios\hello.wav", 0);

拨打“123-4567”电话号码并播放hello.wav文件。由于未设置selfdelete位,呼叫请求记录在呼叫后不会从网关中删除。然后您可以使用callStatus获取呼叫状态,或使用callRemove删除呼叫记录。

callStatus

String callStatus(String reqId)

检查具有<reqId>的呼叫的状态。如果呼叫已拨打,则返回值为“Call Made”;如果呼叫失败,则返回值为“Call Failed”;如果将重试呼叫,则返回值为“Call Will Retry”;对于任何其他状态,则返回值为“”。

请注意,如果呼叫仍在进行中,将返回一个空字符串。您需要等待然后再次轮询状态。

示例

String status = callStatus("11234035434");

callRemove

void callRemove(String reqId)

删除具有reqId的呼叫的呼叫记录。如果呼叫尚未拨打,它也将被删除。

示例

allRemove("11234035434");

callTillConfirm

void callTillConfirm(String vcastexe, String vocfile, String wavfile, String ccode)

持续呼叫列表中的人员,直到有人输入确认码。消息是指定的音频文件。这非常适合用于电话通知升级流程。

要使用此功能,必须安装Voicent BroadcastByPhone专业版。此功能类似于命令行界面BroadcastByPhone。但是,由于无法通过远程机器调用命令,因此此Perl函数使用网关调度一个事件,该事件反过来在网关主机上调用该命令。

选项有:

vcastexe BroadcastByPhone程序。它通常位于网关主机上的“C:\Program Files\Voicent\BroadcastByPhone\bin\vcast.exe”。
vocfile 要使用的BroadcastByPhone呼叫列表。
ccode 用于广播的确认码
wavfile 用于广播的音频文件

示例

CallTillConfirm(
"C:\Program Files\Voicent\BroadcastByPhone\bin\vcast.exe",
"C:\My calllist\escalation.voc",
"C:\My calllist\escalation.wav","911911");

这将调用网关主机上的BroadcastByPhone程序,并开始呼叫“C:\My calllist\escalation.voc”中定义的呼叫列表中的所有人。播放的音频消息是“C:\My calllist\escalation.wav”。一旦列表中的任何人输入确认码“911911”,呼叫将自动停止。

源代码

------------------
File Voicent.java:
------------------

import java.net.URL;
import java.net.URLEncoder;
import java.net.HttpURLConnection;
import java.io.PrintWriter;
import java.io.InputStream;

public class Voicent
{
    /**
    * Constructor with default localhost:8155
    */

    public Voicent()
    {
        host_ = "localhost";
        port_ = 8155;
    }

    /**
    * Constructor with Voicent gateway hostname and port.
    * @param host Voicent gateway host machine
    * @param port Voicent gateway port number
    */
    
    public Voicent(String host, int port)
    {
        host_ = host;
        port_ = port;
    }    

    /**
    * Make a call to the number specified and play the text message
    * using text-to-speech engine.
    *
    * @param phoneno Phone number to call, exactly as it should be dialed
    * @param text Text to play over the phone using text-to-speech
    * @param selfdelete After the call,
    *        delete the call request automatically if set to 1
    * @return Call request ID
    */


    public String callText(String phoneno, String text, boolean selfdelete)
    {

        // call request url
        String urlstr = "/ocall/callreqHandler.jsp";

        // setting the http post string
        String poststr = "info=";
        poststr += URLEncoder.encode("Simple Text Call " + phoneno);
        poststr += "&phoneno=";
        poststr += phoneno;
        poststr += "&firstocc=10";
        poststr += "&selfdelete=";
        poststr += (selfdelete ? "1" : "0");
        poststr += "&txt=";
        poststr += URLEncoder.encode(text);

        // Send Call Request
        String rcstr = postToGateway(urlstr, poststr);
               
        return getReqId(rcstr);
    }

    /**
    * Make a call to the number specified and play the audio file. The
    * audio file should be of PCM 8KHz, 16bit, mono.
    *
    * @param phoneno Phone number to call, exactly as it should be dialed
    * @param audiofile Audio file path name
    * @param selfdelete After the call, 
    *        delete the call request automatically if set to 1
    * @return Call request ID
    */

    public String callAudio(String phoneno, String audiofile, boolean selfdelete)
    {
        // call request url
        String urlstr = "/ocall/callreqHandler.jsp";

        // setting the http post string
        String poststr = "info=";
        poststr += URLEncoder.encode("Simple Audio Call " + phoneno);

        poststr += "&phoneno=";
        poststr += phoneno;
        poststr += "&firstocc=10";
        poststr += "&selfdelete=";
        poststr += (selfdelete ? "1" : "0");
        poststr += "&audiofile=";
        poststr += URLEncoder.encode(audiofile);
             
        // Send Call Request
        String rcstr = postToGateway(urlstr, poststr);

        return getReqId(rcstr);
    }
    
    /**
    * Get call status of the call with the reqID.
    *
    * @param reqID Call request ID on the gateway
    * @return call status
    */

    public String callStatus(String reqID)
    {
        // call status url
        String urlstr = "/ocall/callstatusHandler.jsp";

        // setting the http post string
        String poststr = "reqid=";
        poststr += URLEncoder.encode(reqID);

        // Send Call Request
        String rcstr = postToGateway(urlstr, poststr);

        return getCallStatus(rcstr);
    }

    /**
    * Remove all request from the gateway
    *
    * @param reqID Call request ID on the gateway
    * @return call status
    */

    public void callRemove(String reqID)
    {
        // call status url
        String urlstr = "/ocall/callremoveHandler.jsp";
               
        // setting the http post string
        String poststr = "reqid=";
        poststr += URLEncoder.encode(reqID);
               
        // Send Call remove post
        postToGateway(urlstr, poststr);
    }

    /**
    * Invoke BroadcastByPhone and start the call-till-confirm process
    *
    * @param vcastexe Executable file vcast.exe, BroadcastByPhone path name
    * @param vocfile BroadcastByPhone call list file
    * @param wavfile Audio file used for the broadcast
    * @param ccode Confirmation code
    */

    public void callTillConfirm(String vcastexe, String vocfile, 
                String wavfile, String ccode)

    {
        // call request url
        String urlstr = "/ocall/callreqHandler.jsp";

        // setting the http post string
        String poststr = "info=";
        poststr += URLEncoder.encode("Simple Call till Confirm");
        poststr += "&phoneno=1111111"; // any number
        poststr += "&firstocc=10";
        poststr += "&selfdelete=0";
        poststr += "&startexec=";
        poststr += URLEncoder.encode(vcastexe);

        String cmdline = "\"";
        cmdline += vocfile;
        cmdline += "\"";
        cmdline += " -startnow";
        cmdline += " -confirmcode ";
        cmdline += ccode;
        cmdline += " -wavfile ";
        cmdline += "\"";
        cmdline += wavfile;
        cmdline += "\"";

        // add -cleanstatus if necessary
        poststr += "&cmdline=";
        poststr += URLEncoder.encode(cmdline);

        // Send like a Call Request
        postToGateway(urlstr, poststr);
    }

    private String postToGateway(String urlstr, String poststr)
    {
        try {

            URL url = new URL("http", host_, port_, urlstr);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();

            conn.setDoInput(true);
            conn.setDoOutput(true);
            conn.setRequestMethod("POST");

            PrintWriter out = new PrintWriter(conn.getOutputStream());
            out.print(poststr);
            out.close();

            InputStream in = conn.getInputStream();
            StringBuffer rcstr = new StringBuffer();
            byte[] b = new byte[4096];
            int len;

            while ((len = in.read(b)) != -1)
                rcstr.append(new String(b, 0, len));

            return rcstr.toString();
        }
        catch (Exception e) {
            e.printStackTrace();
            return "";
        }
    }
    
    private String getReqId(String rcstr)
    {
        int index1 = rcstr.indexOf("[ReqId=");
        if (index1 == -1)
            return "";
        index1 += 7;
              
        int index2 = rcstr.indexOf("]", index1);
        if (index2 == -1)
            return "";
        return rcstr.substring(index1, index2);
    }

    private String getCallStatus(String rcstr)
    {
        if (rcstr.indexOf("^made^") != -1)
            return "Call Made";
    
        if (rcstr.indexOf("^failed^") != -1)
            return "Call Failed";
                   
        if (rcstr.indexOf("^retry^") != -1)
            return "Call Will Retry";
    
        return "";
    }

    /* test usage */
    public static void main(String args[])
        throws InterruptedException
    {

        String mynumber = "1112222"; // replace with your own

        Voicent voicent = new Voicent();
        String reqId = voicent.callText(mynumber,
                    "hello, how are you", true);
        System.out.println("callText: " + reqId);
              

        reqId = voicent.callAudio(mynumber,
                    "C:/Program    Files/Voicent/MyRecordings/sample_message.wav",
                    false);
        System.out.println("callAudio: " + reqId);

        while (true) {
            Thread.currentThread().sleep(30000);
            String status = voicent.callStatus(reqId);
            if (status.length() > 0) {
                System.out.println(status);
                voicent.callRemove(reqId);
                break;
            }
        }

        voicent.callTillConfirm("C:/Program Files/Voicent/BroadcastByPhone/bin/vcast.exe",
                            "C:/temp/testctf.voc",
                            "C:/Program Files/Voicent/MyRecordings/sample_message.wav",
                            "1234");
    }

    private String host_;
    private int port_;

}

IVR的兴趣点

理想的入站和出站IVR解决方案

  • 自助服务:使呼叫者能够简单轻松地在几秒钟内获得标准查询的答案,而无需座席。
  • 转接给合适的座席:自动捕获呼叫者的相关信息,并将他们转接给合适的座席来处理他们的电话。
  • 24/7客户服务:让您的客户在需要时获取他们所需的信息。您的IVR应用程序即使在您不在时也在工作,或者它可以将来电转接至您的手机。
  • 自动化出站IVR:与BroadcastByPhone Autodialer完全集成。全自动化的交互式出站呼叫应用程序,用于生成销售线索并与您的客户保持联系。

入站和出站IVR解决方案主要功能

  • 拖放式呼叫流程设计
  • 部署在任何运行Windows 2000/2003/XP/Vista的PC上
  • 将呼叫转接至任何电话,例如您的手机
  • 交互式触摸音响应
  • 语音命令响应
  • 自动文本转语音
  • 轻松集成到您的网站
  • (开发者功能)通过Java集成到任何程序
  • 支持Skype或语音调制解调器进行呼叫
  • 支持单线或多线电话
  • 自然的文本转语音引擎,用于通过电话播放任何文本

IVR历史

无。

© . All rights reserved.