我需要创建一个流程,在该事件中触发云功能时,我将音频文件上传到gcp云存储桶,然后将该文件发送到Google Speech API,以转换为json响应。
const speech = require('@google-cloud/speech');
exports.helloGCS = (event, callback) => {
console.log(`Processing file: ${event.data.name}`);
// some code to get data required for speech API
const payload = {
audio: {
uri: 'https://storage.cloud.google.com/quantum-fusion-205506.appspot.com/videos/${event.data.name}'
},
config: {
encoding: 'FLAC',
languageCode: 'en-US'
}
};
const client = new speech.SpeechClient({
projectId: 'quantum-fusion-205506'
});
client.longRunningRecognize(payload)
.then(responses => {
const operation = responses[0];
console.log('Operations : ', operation);
// current example of getting operation status by operation name with HTTP call
request(`https://speech.googleapis.com/v1/operations/${operation.latestResponse.name}?key=<XYZ>`, (error, response, body) => {
console.log('Operation status response: ', body);
console.log('Operation status response: ', error);
console.log('Operation status response: ', response);
});
});
callback();
};
返回的错误是
{ insertId: "000000-94e46263-c911-4cbb-9f96-e7a0bba6945b"
labels: {…}
logName: "projects/quantum-fusion-205506/logs/cloudfunctions.googleapis.com%2Fcloud-functions"
receiveTimestamp: "2019-03-31T19:59:43.941676738Z"
resource: {…}
severity: "ERROR"
textPayload: "Unhandled rejection"
timestamp: "2019-03-31T19:59:37.042Z"
trace: "projects/quantum-fusion-205506/traces/2ddeb72fed29d8b0387b0992a86e09d8"
}
Error: 3 INVALID_ARGUMENT: Request contains an invalid argument/
at Object.exports.createStatusError (/user_code/node_modules/@google-cloud/speech/node_modules/grpc/src/common.js:91:15)
at Object.onReceiveStatus (/user_code/node_modules/@google-cloud/speech/node_modules/grpc/src/client_interceptors.js:1204:28)
at InterceptingListener._callNext (/user_code/node_modules/@google-cloud/speech/node_modules/grpc/src/client_interceptors.js:568:42)
at InterceptingListener.onReceiveStatus (/user_code/node_modules/@google-
cloud/speech/node_modules/grpc/src/client_interceptors.js:618:8)
at callback (/user_code/node_modules/@google-cloud/speech/node_modules/grpc/src/client_interceptors.js:845:24)"