无法通过child_process在Google云功能中使用Sox命令 [英] Unable to use Sox commands in Google cloud functions via child_process
问题描述
我正忙着编写由Google Cloud Storage活动激活的Google Cloud功能.我需要在child_process中使用sox-但效果不佳.
I am busy writing a Google cloud function that gets activated by a Google Cloud Storage activity. I need to use sox in a child_process - but not having much success.
此功能提取音频文件/事件,然后需要计算文件的长度,然后显示它.
This function picks up the audio file/event and then needs to calculate the length of the file and then display that.
当我在我的index.js中运行以下代码时:
When i run the following code(in my index.js):
'use strict';
const exec = require('child_process').exec;
const fs = require('fs');
const path = require('path');
const storage = require('@google-cloud/storage')();
const vision = require('@google-cloud/vision').v1p1beta1;
const client = new vision.ImageAnnotatorClient();
exports.processAudiofile = (event) => {
const object = event.data;
if (object.resourceState === 'not_exists') {
console.log('This is a deletion event.');
return;
} else if (!object.name) {
console.log('This is a deploy event.');
return;
}
const file = storage.bucket(object.bucket).file(object.name);
const filePath = `gs://${object.bucket}/${object.name}`;
console.log(`Analyzing ${file.name}.`);
console.log(`Filepath is ${filePath}.`);
return new Promise((resolve, reject) => {
exec(`sox --i -d ${filePath}`, function(err, stdout){
if (err){
throw err;
}
console.log("Duration:" + stdout);//Prints
});
});
};
具有以下package.json:
with the following package.json:
{
"name": "audiotest",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"@google-cloud/language": "^1.2.0",
"@google-cloud/speech": "^1.5.0",
"@google-cloud/storage": "^1.6.0",
"@google-cloud/vision": "^0.19.0",
"child_process": "^1.0.2",
"fs": "0.0.1-security",
"got": "^8.3.1",
"path": "^0.12.7",
"sox": "^0.1.0"
}
}
我收到以下错误:
Error: Command failed: sox --i -d gs://rawaudiobucket/shortcall.wav
/bin/sh: 1: sox: not found at ChildProcess.exithandler
(child_process.js:199:12) at emitTwo (events.js:106:13) at
ChildProcess.emit (events.js:191:7) at maybeClose
(internal/child_process.js:920:16) at Socket.<anonymous>
(internal/child_process.js:351:11) at emitOne (events.js:96:13) at
Socket.emit (events.js:188:7) at Pipe._handle.close [as _onclose]
(net.js:509:12)
在此方面的任何帮助将不胜感激!
Any help on this would be greatly appreciated!
推荐答案
您似乎假设 sox
在运行Cloud Functions的实例中可用作命令行程序.除非当前已经记录了该特定程序(如ImageMagic convert
),否则您不应该依赖它.
It looks like you're assuming that sox
is available as a command line program in the instances that run Cloud Functions. Unless that particular program has been documented be presently (like ImageMagic convert
), you shouldn't depend on it.
请注意,sox模块的 npm页面表示:
Note that the npm page for the sox module says:
需要安装sox CLI.可以通过大多数linux发行版的软件包管理器进行安装.
Requires sox CLI to be installed. This can be installed via most linux distribution's package managers.
如果提供自己的Linux编译二进制文件,则可以直接执行它.通过节点模块来构建和运行它将是它自己的问题.
If you provide your own Linux-compiled binary, you may be able to execute it directly. Getting that to build and run via the node module is going to be its own issue.
这篇关于无法通过child_process在Google云功能中使用Sox命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!