如何使用Twilio,而不是只播放MP3时,呼叫接通,使真人语音电话? [英] How to make live voice phone call using Twilio instead of just playing an MP3 when call is answered?

查看:240
本文介绍了如何使用Twilio,而不是只播放MP3时,呼叫接通,使真人语音电话?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要通过Twilio呼叫从笔记本电脑的电话号码,我创建的ASP.NET MVC 5.2应用程序。

我可以拨打一个号码,接电话,但我不知道该如何实现真人语音(要能讲)连接,而不仅仅是播放音乐。

我创建了内部的操作方法的HomeController

 公众的ActionResult调用(字符串){
            客户端=新TwilioRestClient(Settings.AccountSid,Settings.AuthToken);            VAR的结果= client.InitiateOutboundCall(Settings.TwilioNumber,以http://twimlets.com/message?Message%5B0%5D=http://demo.kevinwhinnery.com/audio/zelda.mp3); //它会导致玩塞尔达主题时调用是由被叫方回答            如果(result.RestException!= NULL){
                返回新System.Web.Mvc.HttpStatus codeResult(500,result.RestException.Message);
            }            返回的内容(叫途中!);
        } 公众的ActionResult指数(){
            返回查看();
        }

此操作的方法是通过调用Ajax调用。

当我打从视图\\首页\\ Index.csthml 按钮:

 <形式为GT;
        < P>输入您的手机号码:其中; / P>
        <输入ID =到类型=文本
               占位=恩:16518675309/>
        <按钮和GT;给我一个消息< /按钮>
    < /表及GT;

下面的脚本调用从&LT传递的电话号码;输入ID =到> 来操作方法公众的ActionResult呼叫(串)的HomeController

  $('形式的按钮')。在('点击',功能(E){
    亦即preventDefault();    //想到刚文本字符串从服务器返回
    VAR URL ='/呼叫';
    $就(URL,{//调用调用操作方法
        方法:POST,
        数据类型:'文字',
        数据:{
            于:$('#为)VAL()//经过数参数的操作方法
        },
        成功:功能(数据){
            showFlash(数据);
        },
        错误:功能(jqxhr){
            警报('发生错误发送到服务器的请求');
        }
    })
});

这开始打电话给指定的号码,即 48123456789 ,其中 48 是该国code。当呼叫由被叫方回答,塞尔达主题播放。(的http://twimlets.com/message?Message%5B0%5D=http://demo.kevinwhinnery.com/audio/zelda.mp3

相反的,我想通过笔记本谈论(它有内置麦克风),以我打过电话的人,让这个人顶嘴。在几句话我想有真人语音。

问:如何实现ASP.NET MVC的5.x的使用Twilio真人语音电话

Settings.AccountSid Settings.AuthToken 是我的凭据:

 公共静态类设置
    {
        公共静态字符串AccountSid {{返回A ############### 0; }}
        公共静态字符串的authToken {{返回E ############### 0; }}
        公共静态字符串TwilioNumber {{返回4 ######## 1; }}
    }


解决方案

Twilio传道这里。

如果要放置在浏览器中一个电话你需要看看使用Twilio客户端JavaScript的:

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

这将让您可以从浏览器到Twilio VoIP呼叫。一旦呼叫Twilio可以再桥梁与另一个Twilio客户端,SIP终端或PSTN电话拨打:

https://www.twilio.com/docs/quickstart/ CSHARP /客户/呼出通话

希望有所帮助。

To call phone number from notebook through Twilio I created ASP.NET-MVC 5.2 application.

I can call a number and answer the phone but I don't know how to achieve live voice(to be able to talk) connection instead of just playing music.

I created an action method inside 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();
        }

This action method is invoked by Ajax call.

When I hit the button from 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>

The script below is invoked which passes the phone number from <input id="to"> to the action method public ActionResult Call(string to) in the HomeController:

$('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');
        }
    })
});

This starts phone call to the specified number i.e. 48123456789 where 48 is the country code. When the call is answered by the callee, the zelda theme is played.( http://twimlets.com/message?Message%5B0%5D=http://demo.kevinwhinnery.com/audio/zelda.mp3 )

Instead of that I would like to talk through notebook(it has internal microphone) to the person I've called and let this person talk back. In few words I would like to have live voice.

Question: How to achieve live voice phone call using Twilio in ASP.NET-MVC 5.x?

Settings.AccountSid and Settings.AuthToken are my credentials:

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

解决方案

Twilio evangelist here.

If you want to place a phone call from your browser you'll need to look at using Twilio Client for JavaScript:

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

That will let you place a VoIP call from the browser into Twilio. Once the call reaches Twilio you can then bridge that call with another Twilio Client, SIP endpoint or PSTN phone:

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

Hope that helps.

这篇关于如何使用Twilio,而不是只播放MP3时,呼叫接通,使真人语音电话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆