如何将 header 添加到 wav 文件?
How do you add a header to wav file?
我正在将存储为 blob 的音频数据发送到我的后端 (node/express)。当我将文件另存为 .wav 并尝试在 python 中的 SpeechRecogition 包中使用时,它会抛出一条错误消息 "file does not start with RIFF id"。那么如何在保存之前将 headers 添加到我的 blob 文件中,使其成为格式正确的 .wav 文件?如果需要我可以提供代码。
node.js 文件
var multer = require('multer');
var fs = require('fs'); //use the file system so we can save files
var uniqid = require('uniqid');
var spawn = require('child_process').spawn;
const storage = multer.memoryStorage()
var upload = multer({ storage: storage });
router.post('/api/test', upload.single('upl'), function (req, res) {
console.log(req.file);
console.log(req.file.buffer);
var id = uniqid();
fs.writeFileSync(id+".wav", Buffer.from(new Uint8Array(req.file.buffer))); //write file to server as .wav file
const scriptPath = 'handleAudio.py'
const process = spawn('python3', [__dirname+"/../"+scriptPath, "/home/bitnami/projects/sample/"+id+".wav", req.file.originalname, 'True']); //throws error about header in .wav
});
此外,我还有一个使用 php 端点的相同示例,该端点只是将 blob 保存到扩展名为 .wav 的文件中,并且 python 文件接受了它。 php 中的 move_uploaded_file
和我在上面使用节点所做的事情有什么不同?
我正在将存储为 blob 的音频数据发送到我的后端 (node/express)。当我将文件另存为 .wav 并尝试在 python 中的 SpeechRecogition 包中使用时,它会抛出一条错误消息 "file does not start with RIFF id"。那么如何在保存之前将 headers 添加到我的 blob 文件中,使其成为格式正确的 .wav 文件?如果需要我可以提供代码。
node.js 文件
var multer = require('multer');
var fs = require('fs'); //use the file system so we can save files
var uniqid = require('uniqid');
var spawn = require('child_process').spawn;
const storage = multer.memoryStorage()
var upload = multer({ storage: storage });
router.post('/api/test', upload.single('upl'), function (req, res) {
console.log(req.file);
console.log(req.file.buffer);
var id = uniqid();
fs.writeFileSync(id+".wav", Buffer.from(new Uint8Array(req.file.buffer))); //write file to server as .wav file
const scriptPath = 'handleAudio.py'
const process = spawn('python3', [__dirname+"/../"+scriptPath, "/home/bitnami/projects/sample/"+id+".wav", req.file.originalname, 'True']); //throws error about header in .wav
});
此外,我还有一个使用 php 端点的相同示例,该端点只是将 blob 保存到扩展名为 .wav 的文件中,并且 python 文件接受了它。 php 中的 move_uploaded_file
和我在上面使用节点所做的事情有什么不同?