Rau*_*aul 6 javascript audio node.js
我有一个二进制存储桶(在 Firebase Storage 中),并且正在实现一个 node.js 云函数,它获取音频(audio/m4a 或 audio/caf),验证其格式和持续时间,然后将其 uri 与文档关联我的数据库(或者如果音频文件的持续时间无效则删除该音频文件)。
在数据库中创建文档之前,我需要验证音频文件。
为了从存储中下载文件,我使用此功能:
exports.downloadBinaryFileFromUrl = function (fileUrl) {
/* This function downloads a binary-encoded file from its URL and returns it */
return axios
.get(fileUrl, {
responseType: "arraybuffer",
})
.then((res) => Buffer.from(res.data, "binary"))
.catch((err) => {
if (err.response) {
/*
The request was made and the server responded with a status code
that falls out of the range of 2xx
*/
throw err.response.data;
} else if (err.request) {
// Client never received a response, or request never left
throw err.request;
} else {
// Something happened in setting up the request that triggered an Error
throw new Error(`Error: ${err.message}`);
}
});
};
Run Code Online (Sandbox Code Playgroud)
有什么想法如何使用 Node.js 获取音频文件的持续时间吗?