有人知道如何使用 Twilio 录制和播放录音吗?
Anyone know how to record and playback a recording with Twilio?
我正在尝试实施一种简单的 'voicemail' 系统,语音信箱所有者可以在其中录制他们自己的问候语。
我想我可以做这样的事情:
response.Say("Record your message");
response.Record(recordingStatusCallback: new Uri("http://<snip>.ngrok.io/voice/playmessage"));
response.Say("Are you happy with this recording?");
return TwiML(response);
然后在playmessage方法中
[HttpPost]
public TwiMLResult PlayMessage()
{
string url = Request.Form["RecordingUrl"];
var vr = new VoiceResponse();
vr.Play(url: new Uri(url));
return TwiML(vr);
}
录音后立即挂断,然后调用PlayMessage方法
我试着添加一个 RecordingEventEnum.InProgress,像这样:
response.Record(recordingStatusCallback: new Uri("http://<snip>.ngrok.io/voice/playmessage"), recordingStatusCallbackEvent: new List<Record.RecordingEventEnum> {Record.RecordingEventEnum.InProgress });
方法似乎被调用了,但它没有播放任何内容,只是挂断了。
我还没听懂所有“如果您对录音满意,请按 1,再试一次,等等...”之类的内容。
我想我没有正确调用 'record' 方法...有人知道魔法酱吗?
谢谢,
基因
使用 action
属性代替 recordingStatusCallback
:
response.Record(action: new Uri("http://<snip>.ngrok.io/voice/playmessage"));
来自doc:
The action
attribute takes a relative or absolute URL as a value. When recording is finished, Twilio will make a GET or POST request to this URL including the parameters below.
(注意“以下参数”包括 RecordingUrl
。)
不过要小心:
There is one exception: if Twilio receives an empty recording, it will not make a request to the action
URL. The current call flow will continue with the next verb in the current TwiML document.
也就是说你的 response.Say("Are you happy with this recording?");
应该是 Play
之后的 PlayMessage()
的一部分。
另请参阅 Twilio API 文档中的示例 Record a voicemail。
我正在尝试实施一种简单的 'voicemail' 系统,语音信箱所有者可以在其中录制他们自己的问候语。
我想我可以做这样的事情:
response.Say("Record your message");
response.Record(recordingStatusCallback: new Uri("http://<snip>.ngrok.io/voice/playmessage"));
response.Say("Are you happy with this recording?");
return TwiML(response);
然后在playmessage方法中
[HttpPost]
public TwiMLResult PlayMessage()
{
string url = Request.Form["RecordingUrl"];
var vr = new VoiceResponse();
vr.Play(url: new Uri(url));
return TwiML(vr);
}
录音后立即挂断,然后调用PlayMessage方法
我试着添加一个 RecordingEventEnum.InProgress,像这样:
response.Record(recordingStatusCallback: new Uri("http://<snip>.ngrok.io/voice/playmessage"), recordingStatusCallbackEvent: new List<Record.RecordingEventEnum> {Record.RecordingEventEnum.InProgress });
方法似乎被调用了,但它没有播放任何内容,只是挂断了。
我还没听懂所有“如果您对录音满意,请按 1,再试一次,等等...”之类的内容。
我想我没有正确调用 'record' 方法...有人知道魔法酱吗?
谢谢,
基因
使用 action
属性代替 recordingStatusCallback
:
response.Record(action: new Uri("http://<snip>.ngrok.io/voice/playmessage"));
来自doc:
The
action
attribute takes a relative or absolute URL as a value. When recording is finished, Twilio will make a GET or POST request to this URL including the parameters below.
(注意“以下参数”包括 RecordingUrl
。)
不过要小心:
There is one exception: if Twilio receives an empty recording, it will not make a request to the
action
URL. The current call flow will continue with the next verb in the current TwiML document.
也就是说你的 response.Say("Are you happy with this recording?");
应该是 Play
之后的 PlayMessage()
的一部分。
另请参阅 Twilio API 文档中的示例 Record a voicemail。