如何使用 Twilio 进行实时语音 phone 通话,而不是在接听电话时只播放 MP3?

How to make live voice phone call using Twilio instead of just playing an MP3 when call is answered?

为了通过 Twilio 从笔记本中调用 phone 号码,我创建了 ASP.NET-MVC 5.2 应用程序。

我可以拨打一个号码并接听 phone 但我不知道如何实现现场语音(能够通话)连接而不只是播放音乐。

我在里面创建了一个动作方法HomeController:

  public ActionResult Call(string to) {
            client = new TwilioRestClient(Settings.AccountSid, Settings.AuthToken); 

            var result = client.InitiateOutboundCall(Settings.TwilioNumber, to, "http://twimlets.com/message?Message%5B0%5D=http://demo.kevinwhinnery.com/audio/zelda.mp3"); //it causes to play zelda theme when call is answered by callee

            if (result.RestException != null) {
                return new System.Web.Mvc.HttpStatusCodeResult(500, result.RestException.Message);
            }

            return Content("Call enroute!");
        }

 public ActionResult Index() {
            return View();
        }

此操作方法由 Ajax 调用调用。

当我从 Views\Home\Index.csthml 按下按钮时:

    <form>
        <p>Enter your mobile phone number:</p>
        <input id="to" type="text"
               placeholder="ex: +16518675309" />
        <button>Send me a message</button>
    </form>

调用下面的脚本将 <input id="to"> 中的 phone 数字传递给 HomeController 中的操作方法 public ActionResult Call(string to):

$('form button').on('click', function(e) {
    e.preventDefault();

    // expect just a string of text back from the server 
    var url = '/call'; 
    $.ajax(url, { //invokes call action method
        method:'POST',
        dataType:'text',
        data:{
            to:$('#to').val()//passes the number argument to the action method
        },
        success: function(data) {
            showFlash(data);
        },
        error: function(jqxhr) {
            alert('There was an error sending a request to the server');
        }
    })
});

这将开始 phone 呼叫指定号码,即 48123456789,其中 48 是国家/地区代码。当被叫方接听电话时,将播放塞尔达主题曲。( http://twimlets.com/message?Message%5B0%5D=http://demo.kevinwhinnery.com/audio/zelda.mp3 )

相反,我想通过笔记本(它有内部微phone)与我打电话的人交谈,让这个人回话。简而言之,我想有现场的声音。

问题:如何在ASP.NET-MVC中使用Twilio实现真人语音phone通话5.x?

Settings.AccountSidSettings.AuthToken 是我的凭据:

 public static class Settings
    {
        public static string AccountSid { get { return "A###############0"; } }
        public static string AuthToken { get { return "e###############0"; } }
        public static string TwilioNumber { get { return "4########1"; } }
    }

执行此操作的方法是使用 Dial Twiml https://www.twilio.com/docs/api/twiml/dial Dial can take one of several options; either a phone number, a SIP URL or a Twilio Client identifier. An example of dial is the CallMe twimlet available at https://www.twilio.com/labs/twimlets/callme 并且看起来类似于以下

<Response>
    <Dial>
        <Number>+44.........</Number>
    </Dial>
</Response>

如果您的笔记本电脑上已经安装了软件phone,那么您可以拨号。例如,如果你有 Skype,你可以使用你的 Skype phone 号码。

如果您没有安装软件phone,您可以随时使用 Twilio 客户端 https://www.twilio.com/client 并在您的网络浏览器中安装 运行。

这里是 Twilio 布道者。

如果您想从浏览器发出 phone 调用,您需要考虑使用 Twilio Client for JavaScript:

https://www.twilio.com/docs/quickstart/csharp/client

这样您就可以从浏览器向 Twilio 发起 VoIP 呼叫。一旦呼叫到达 Twilio,您就可以将该呼叫桥接到另一个 Twilio 客户端、SIP 端点或 PSTN phone:

https://www.twilio.com/docs/quickstart/csharp/client/outgoing-calls

希望对您有所帮助。