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

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

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.17/5 (4投票s)

2008年6月7日

CPOL

4分钟阅读

viewsIcon

90425

IVR 电话通知软件通过电话广播语音消息。非常适合群组活动提醒、营销、潜在客户开发、政治竞选推广、学校筹款、教会沟通、紧急通知等。

我创建了一篇包含 Java 代码的新文章。

您可以点击这里。

IVR 简介

交互式语音应答IVR)是一项电话技术,允许计算机通过电话呼叫检测语音和触摸音。基于 IVR 的系统可以通过预录制或动态生成的音频进行响应,以进一步指导呼叫者如何操作。IVR 使呼叫者能够与任何软件进行交互,例如通过普通电话或互联网电话(如 Skype)查询或修改数据库信息。因此,呼叫者可以使用他们的触摸音键盘输入请求,或者直接说出他们想要做的事情,例如请求账户余额信息。然后 IVR 将使用文本转语音软件将信息读回。

总的来说,IVR 可以让您一键拨打数百个个性化电话。

IVR 电话通知软件通过电话广播语音消息。非常适合群组活动提醒、营销、潜在客户开发、政治竞选推广、学校筹款、教会沟通、紧急通知等。

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

使用 IVR API

由于所有这些功能都作为 HTTP 客户端直接与网关通信来实现,因此它们可以在任何连接到运行网关的主机的机器上运行。

由于我的应用程序将只使用 CallText 方法,因此我将简要介绍其他方法。

概要

string CallText(string phoneno, string text, bool selfdelete)

描述

拨打电话并播放指定的文本消息。文本消息由 Voicent Gateway 的文本转语音引擎转换为语音。
选项为:
phoneno 要呼叫的电话号码
文本 电话呼叫的消息
selfdelete 如果设置为“1”,则在呼叫完成后请求网关自动删除呼叫请求

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

示例

CallText("123-4567", "你好,你怎么样", true);
呼叫电话号码“123-4567”并说“你好,你怎么样”。由于设置了 selfdelete 位,因此呼叫完成后,IVR 中的呼叫请求记录将自动删除。
string reqId = CallText("123-4567", "你好,你怎么样", 0);
呼叫电话号码“123-4567”并说“你好,你怎么样”。由于未设置 selfdelete 位,因此呼叫完成后,网关中的呼叫请求记录将不会被删除。然后您可以使用 CallStatus 获取呼叫状态,或使用 CallRemove 删除呼叫记录。

其他方法如下,详情请参阅 Voicent Gateway 简易外呼接口

概要

string CallAudio(string phoneno, string audiofile, bool selfdelete)

示例

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

概要

string CallStatus(string reqId)

示例

string status = CallStatus("11234035434");

概要

void CallRemove(string reqId)

示例

CallRemove("11234035434");

概要

void CallTillConfirm(string vcastexe, string vocfile, string wavfile, string ccode)

示例

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

源代码

此应用程序必须基于网关。在此,我们使用 Voicent Gateway 作为服务器,因为我至今尚未找到任何免费网关。您也可以访问此网站了解有关 IVR 的更多信息。

  ----------------

  File Voicent.cs:

  ----------------

  using System;
  using System.Net;
  using System.IO;
                            

namespace Voicent
{

  /// <summary>
  /// Interface class for making telephone calls using the simple
  /// API of Voicent Gateway.
  /// </summary>
  public class Voicent
  {
    /// <summary>
    /// Default constructor use https://:8155
    /// </summary>
    public Voicent()
    {
      m_host = "localhost";

      m_port = 8155;
    }


    /// <summary>
    /// Constructor with host and port
    /// </summary>
    /// <param name="host">Hostname of Voicent Gateway</param>
    /// <param name="port">port number of Voicent Gateway</param>
    public Voicent(string 
                host, int port)
    {
      m_host = host;

      m_port = port;
    }


    /// <summary>
    /// Call the specified phone number and play the text using
    /// text-to-speech engine
    /// </summary>
    /// <param name="phoneno">telephone number to call</param>
    /// <param name="text">text message to play</param>
    /// <param name="selfdelete">if set to one, automatically 
                remove call record on 
    /// gateway after the call is made</param>
    /// <returns>Call Request ID on gateway</returns>
    public string CallText(string 
                phoneno, string text, bool selfdelete)
    {

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


      // setting the http post string
      string poststr = "info=Simple Text Call " + 
                phoneno;


      poststr += "&phoneno=" + phoneno;

      poststr += "&firstocc=10";

      poststr += "&selfdelete=";

      poststr += (selfdelete ? "1" : "0");

      poststr += "&txt=" + text;


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

      return GetRequestID(rcstr);

    }


    /// <summary>
    /// Call the specified phone number and play the audio file
    /// </summary>
    /// <param name="phoneno">telephone number to call</param>
    /// <param name="filename">audio file path name</param>
    /// <param name="selfdelete">if set to one, automatically 
                remove call record on 
    /// gateway after the call is made</param>
    /// <returns>Call Request ID on gateway</returns>
    public string CallAudio(string 
                phoneno, string filename, bool selfdelete)
    {
      // call request url
      string urlstr = "/ocall/callreqHandler.jsp";


      // setting the http post string
      string poststr = "info=Simple Audio Call " + 
                      phoneno;


      poststr += "&phoneno=" + phoneno;

      poststr += "&firstocc=10";

      poststr += "&selfdelete=";

      poststr += (selfdelete ? "1" : "0");

      poststr += "&audiofile=" + filename;


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

      return GetRequestID(rcstr);
    }


    /// <summary>
    /// Get call request status
    /// </summary>
    /// <param name="reqID">Call request ID</param>
    /// <returns>status code</returns>
    public string CallStatus(string 
                reqID)
    {
      // call status url
      string urlstr = "/ocall/callstatusHandler.jsp";

      string poststr = "reqid=" + reqID;


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


      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 "";
    }


    /// <summary>
    /// Remove the call request on the gateway
    /// </summary>
    /// <param name="reqID">Call Request ID</param>
    public void CallRemove(string 
                reqID)
    {
      // call status url
      string urlstr = "/ocall/callremoveHandler.jsp";

      string poststr = "reqid=" + reqID;


      // Send Call Request
      PostToGateway(urlstr, poststr);
    }


    /// <summary>
    /// Invoke Voicent BroadcastByPhone and start the 
                call-till-confirm escalation process
    /// </summary>
    /// <param name="vcastexe">BroadcastByPhone executable file 
                path</param>
    /// <param name="vocfile">BroadcastByPhone call list file 
                path</param>
    /// <param name="wavfile">Audio file, must be PCM 8KHz, 
                16bit, mono wave file format</param>
    /// <param name="ccode">Confirmation code, numbers only</param>
    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=Simple Call till Confirm";

      poststr += "&phoneno=1111111"; // any number

      poststr += "&firstocc=10";

      poststr += "&selfdelete=0";

      poststr += "&startexec=" + vcastexe;


      string cmdline = "\"" + vocfile + "\" -startnow";

      cmdline += " -confirmcode " + ccode;

      cmdline += " -wavfile " + "\"" + wavfile + "\"";


      // add -cleanstatus if necessary
      poststr += "&cmdline=" + cmdline;


      PostToGateway(urlstr, poststr);
    }


    protected string PostToGateway(string urlstr, string poststr)
    {
      Uri url = new Uri("http://" + m_host + ":" + 
                m_port.ToString() + urlstr);

      HttpWebRequest HttpWRequest = (HttpWebRequest) 
                WebRequest.Create(url);

                

      HttpWRequest.Headers.Set("Pragma", "no-cache");

      HttpWRequest.Timeout = 60000;

      HttpWRequest.Method = "POST";

      HttpWRequest.ContentType = 
                "application/x-www-form-urlencoded";

                

      byte[] PostData = 
                System.Text.Encoding.ASCII.GetBytes(poststr);

      HttpWRequest.ContentLength = PostData.Length;

      Stream tempStream = HttpWRequest.GetRequestStream();

      tempStream.Write(PostData,0,PostData.Length);

      tempStream.Close();

                

      HttpWebResponse HttpWResponse = (HttpWebResponse) 
                HttpWRequest.GetResponse();

      Stream receiveStream = 
                HttpWResponse.GetResponseStream(); 

      StreamReader readStream = new 
                StreamReader(receiveStream);

                

      string rcstr = "";

      Char[] read = new Char[256]; 

      int count = 0;

      while ((count = readStream.Read(read, 0, 256)) > 
                0) {

        rcstr += new String(read, 0, count);

      }

      HttpWResponse.Close();

      readStream.Close();


      return rcstr;
    }


    protected string GetRequestID(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 - index1);
    }


    private string m_host;

    private int m_port;

  }

}










                
  --------------------

  File TextVoicent.cs:

  --------------------

  using System;
  using System.Threading;
  using Voicent;

                

namespace csapi
{
  /// <summary>
  /// Simple class to test Voicent C# Simple Interface
  /// </summary>
  class TestVoicent
  {
    /// <summary>
    /// The main entry point for the application.
    /// </summary>

    [STAThread]

    static void Main(string[] args)
    {
      string phoneno = "8147838"; // Replace it with 
                      your number


      Voicent.Voicent voicent = new Voicent.Voicent();


      // Test CallText
      string reqId = voicent.CallText(phoneno, "Hello, 
                how are you", true);

      Console.WriteLine("Call request ID = " + reqId);


      // Test CallAudio
      reqId = voicent.CallAudio(phoneno, "C:/Program 
                      Files/Voicent/MyRecordings/sample_message.wav", false);

      Console.WriteLine("Call request ID = " + reqId);


      // try to get status
      while (true) {

        Thread.Sleep(20000); // wair for 20 
                seconds

        string status = 
                voicent.CallStatus(reqId);

        Console.WriteLine("Call Status: " + 
                status);

        if (status.Length != 0)

          break;

      }


      // remove the call request on the gateway
      voicent.CallRemove(reqId);


      // Test call-till-confirm
      voicent.CallTillConfirm("C:/Program 
                      Files/Voicent/BroadcastByPhone/bin/vcast.exe",

                "C:/temp/testctf.voc",

                "C:/Program 
                      Files/Voicent/MyRecordings/sample_message.wav",

                "12345");

    }

  }

}

IVR 的亮点

理想的呼入与呼出 IVR 解决方案

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

呼入与呼出 IVR 解决方案主要特点

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

IVR 历史

无。

© . All rights reserved.