Twilio 你要录音吗?
有人能推荐将Twilio录音嵌入网站的最佳方式吗 我说的是Twilio服务器上的Twilio录制 现在我只是使用下面我编写的PHP函数来下载文件,然后在我这方面找到嵌入的方法,但是可能有更简单的方法吗Twilio 你要录音吗?,twilio,twilio-php,twilio-api,Twilio,Twilio Php,Twilio Api,有人能推荐将Twilio录音嵌入网站的最佳方式吗 我说的是Twilio服务器上的Twilio录制 现在我只是使用下面我编写的PHP函数来下载文件,然后在我这方面找到嵌入的方法,但是可能有更简单的方法吗 function download_recording_from_twilio($url) { // the file_name is everything after the twilio.com/ with an added .mp3 at the end $word_after_w
function download_recording_from_twilio($url) {
// the file_name is everything after the twilio.com/ with an added .mp3 at the end
$word_after_which_we_extract = "twilio.com/";
// what is the beginning position of this word?
$begPos = strpos($url, $word_after_which_we_extract);
// beginning position is the beginning of the word plus the word length
$begPos += strlen($word_after_which_we_extract);
// everything after twilio.com/
$everything_after = substr($url, $begPos, strlen($url));
// position of the last / in $everything_after
$last_slash = strrpos($url, "/");
// everything after the last slash
$everything_after_last_slash = substr($url, $last_slash, strlen($url));
// full filepath
$full_path = $everything_after.".mp3";
// create final filename
$file_name = $everything_after_last_slash.".mp3";
$source = "https://api.twilio.com/".$full_path;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $source);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0');
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_SSL_CIPHER_LIST, 'ecdhe_rsa_aes_128_gcm_sha_256');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_VERBOSE,true);
$data = curl_exec ($ch);
$error = curl_error($ch);
curl_close ($ch);
$destination = ".".$file_name;
$file = fopen($destination, "w+");
fputs($file, $data);
fclose($file);
}
谢谢您可以使用)
对于src
属性,如果您想以WAV格式播放录音,可以通过如下链接请求Twilio的“录音api”
https://api.twilio.com/2010-04-01/Accounts/ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/Recordings/RExxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.wav?Download=false
其中,rexxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
是记录SID
将.wav更改为.mp3,您将以mp3格式播放
另外,请注意Download=false查询字符串参数。太好了,谢谢!你知道他们会保留这些录音多久吗?我不确定,但我想Twilio不会删除你的录音。您可以通过API调用删除它们。从它看来,在开始的10000分钟内,每个月都有一个免费的存储空间。我已经询问了他们的支持,我会在知道后更新答案。谢谢你的回答录音是永久保存的事实上,他们刚刚确认