简体   繁体   English

播放Twilio音频文件

[英]Play Twilio Audio file

$client = new Services_Twilio($sid, $token);
$calls = $client->account->calls;
foreach($calls as $call){
?>
<audio controls><source src='<?php echo "https://api.twilio.com".$call->uri; ?>' type='audio/ogg'><source src='<?php echo "https://api.twilio.com".$call->uri; ?>' type='audio/mpeg'> Your browser does not support the audio tag.</audio>
<?
}
?>

I tried appending .mp3 to the URL, it did not worked! 我尝试将.mp3附加到URL,但没有成功!

Twilio developer evangelist here. Twilio开发人员布道者在这里。

My guess here is that you are trying to list out audio elements for calls that you have recorded so that you can play them back. 我的猜测是,您正在尝试列出已录制呼叫的音频元素,以便可以播放它们。 If that is the case, then you are not using the correct URI for the recording. 如果是这种情况,则说明您没有使用正确的URI进行录制。 $call->uri will actually return the path of the API resource for the call itself. $call->uri实际上将为调用本身返回API资源的路径。

Instead, you will need to list the recordings of the call and use the URLs returned there. 相反,您将需要列出呼叫的录音并使用在那里返回的URL。 Like so: 像这样:

<?
  $client = new Services_Twilio($sid, $token);
  $calls = $client->account->calls;
  foreach($calls as $call){
    foreach($call->recordings as $recording){
?>
  <audio controls>
    <source src='<?php echo "https://api.twilio.com".$recording->uri; ?>' type='audio/wav'>
    <source src='<?php echo "https://api.twilio.com".$recording->uri.".mp3"; ?>' type='audio/mpeg'>
    Your browser does not support the audio tag.
  </audio>
<?
    }
  }
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM