嵌入 twilio 录音?
Embed twilio recording?
有人可以推荐将 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_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);
}
谢谢
您可以在网页中使用 <audio>
元素 (https://developer.mozilla.org/en/docs/Web/HTML/Element/audio)。
对于 src
属性,如果您想以 WAV 格式播放录音,您可以使用 link 这样的
来请求 Twilio 的 'recordings api'
https://api.twilio.com/2010-04-01/Accounts/ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/Recordings/RExxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.wav?Download=false
其中 RExxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
是记录 SID
将 .wav 更改为 .mp3,您将以 MP3 格式播放。
另外,观察 Download=false 查询字符串参数。
有人可以推荐将 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_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);
}
谢谢
您可以在网页中使用 <audio>
元素 (https://developer.mozilla.org/en/docs/Web/HTML/Element/audio)。
对于 src
属性,如果您想以 WAV 格式播放录音,您可以使用 link 这样的
https://api.twilio.com/2010-04-01/Accounts/ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/Recordings/RExxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.wav?Download=false
其中 RExxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
是记录 SID
将 .wav 更改为 .mp3,您将以 MP3 格式播放。
另外,观察 Download=false 查询字符串参数。