给定录音 SID,如何将录音文件下载到本地驱动器(使用 Twilio 节点帮助程序库)?
Given a recording SID, how can I download the recording file to local drive (using Twilio node helper library)?
我正在使用 Twilio Node Helper Library 拨打电话并录音。
根据 API link,GET 应该 return 一个 WAV 文件,但在我的例子中,它只是 return 一个带有录音元数据的 json。
这就是我正在写的内容:
twilioClient = require('twilio')(config.twilio.acct_sid, config.twilio.auth_token)
var request = twilioClient.recordings('RE01234567890123456789012345678901')
get(function (err, recording){ // <- this "recording" is JSON
如果我在 SID 的末尾添加一个“.mp3”并不重要,我总是得到一个 JSON。
理想情况下我想写这样的东西:
var file = fs.createWriteStream('/Users/yasemin/Desktop/rec.mp3');
twilioClient.recordings('RE01234567890123456789012345678901')
.get(function (err, recording) {
if(!err){ recording.pipe(file); }});
谢谢!
TLDR:Node Helper Library 目前没有重新编码的文件下载功能。
这是来自 Twilio 支持的回复:
Looking at the documentation on our web portal, you are certainly
correct, downloading the .wav or .mp3 is possible via API call.
However, from what I can see looking at the Node example code here:
https://www.twilio.com/user/account/developer-tools/api-explorer/recording
And the documentation from the Twilio-Node developer here:
http://twilio.github.io/twilio-node/#recordings
It looks to me like the helper library doesn't actually support direct
downloading, just viewing the recording data. You can download the
application through an HTTP call, as shown in the original docs link
you noted on your Whosebug question. Let me know if you need help
with that.
In the mean time, I've reached out to the author of the library to see
if this is by design or a feature to be added to the library. It's
open source of course, so you could make a pull and add it yourself if
you like!
我遇到了这个问题,不得不开发自己的代码来处理这个问题。
下面是我想出的代码
con.on('getvmx', function(data){
comModel.find({_id: data.id}, function(err, results){
var https = require('https');
var options = {
host: 'api.twilio.com',
port: 443,
path: '/2010-04-01/Accounts/' + sid + '/Recordings/'+ results[0].sid + '.mp3',
method: 'GET',
auth: sid + ":" + auth,
agent: false
};
var req = https.request(options, function(res) {
res.setEncoding('binary');
var mp3data = '';
res.on('data', function (chunk) {
mp3data += chunk;
});
res.on('end', function(){
try{
var fileName = "/var/www/tcc/public/vm/" + results[0].sid + '.mp3';
fs.writeFile(fileName, mp3data, 'binary', function(err){
if(err){
return console.log(err);
}else{
console.log("File Saved");
con.emit('vmload', results);
}
});
}catch(err){
console.log(err.message);
}
});
});
req.end();
console.log(results);
//load all messages
//load line from reach message
});
});
我正在使用 Twilio Node Helper Library 拨打电话并录音。
根据 API link,GET 应该 return 一个 WAV 文件,但在我的例子中,它只是 return 一个带有录音元数据的 json。
这就是我正在写的内容:
twilioClient = require('twilio')(config.twilio.acct_sid, config.twilio.auth_token)
var request = twilioClient.recordings('RE01234567890123456789012345678901')
get(function (err, recording){ // <- this "recording" is JSON
如果我在 SID 的末尾添加一个“.mp3”并不重要,我总是得到一个 JSON。
理想情况下我想写这样的东西:
var file = fs.createWriteStream('/Users/yasemin/Desktop/rec.mp3');
twilioClient.recordings('RE01234567890123456789012345678901')
.get(function (err, recording) {
if(!err){ recording.pipe(file); }});
谢谢!
TLDR:Node Helper Library 目前没有重新编码的文件下载功能。
这是来自 Twilio 支持的回复:
Looking at the documentation on our web portal, you are certainly correct, downloading the .wav or .mp3 is possible via API call. However, from what I can see looking at the Node example code here:
https://www.twilio.com/user/account/developer-tools/api-explorer/recording
And the documentation from the Twilio-Node developer here:
http://twilio.github.io/twilio-node/#recordings
It looks to me like the helper library doesn't actually support direct downloading, just viewing the recording data. You can download the application through an HTTP call, as shown in the original docs link you noted on your Whosebug question. Let me know if you need help with that.
In the mean time, I've reached out to the author of the library to see if this is by design or a feature to be added to the library. It's open source of course, so you could make a pull and add it yourself if you like!
我遇到了这个问题,不得不开发自己的代码来处理这个问题。
下面是我想出的代码
con.on('getvmx', function(data){
comModel.find({_id: data.id}, function(err, results){
var https = require('https');
var options = {
host: 'api.twilio.com',
port: 443,
path: '/2010-04-01/Accounts/' + sid + '/Recordings/'+ results[0].sid + '.mp3',
method: 'GET',
auth: sid + ":" + auth,
agent: false
};
var req = https.request(options, function(res) {
res.setEncoding('binary');
var mp3data = '';
res.on('data', function (chunk) {
mp3data += chunk;
});
res.on('end', function(){
try{
var fileName = "/var/www/tcc/public/vm/" + results[0].sid + '.mp3';
fs.writeFile(fileName, mp3data, 'binary', function(err){
if(err){
return console.log(err);
}else{
console.log("File Saved");
con.emit('vmload', results);
}
});
}catch(err){
console.log(err.message);
}
});
});
req.end();
console.log(results);
//load all messages
//load line from reach message
});
});