我正在使用Google Cloud Storage和Speech API从我的node.js实现转换文件音频,而且我将FLAC编码音频文件上传到Google云端存储时遇到问题。它似乎只能正确上传大约15 - 20秒的文件,对于其他文件,API不会抛出错误并保存一个空文件(8.16KB)。
所涉及的代码部分如下:
...
var binary = new Buffer(audio, 'base64');
// write buffer to file
var Readable = require('stream').Readable
var s = new Readable
s.push(binary) // the string you want
s.push(null) // indicates end-of-file basically - the end of the stream
var convertedFLACfilePath = "" + crypto.randomBytes(32).toString('hex')+".flac";
var FfmpegCommand = require('fluent-ffmpeg');
var command = new FfmpegCommand().input(s)
.audioCodec('flac').save(convertedFLACfilePath)
.on('error', function(err) {
console.log('An error occurred: ' + err.message);
})
.on('end', function() {
console.log('Processing finished !');
const gcloudAuth = {
projectId: '-------',
keyFilename: '--------'
};
const bucketName = '--------';
const filename = convertedFLACfilePath;
const gcsUri = 'gs://' + bucketName + '/' + filename;
const encoding = 'FLAC';
const sampleRateHertz = 16000;
const languageCode = '----';
var gcloud = require('google-cloud')();
var storageClient = gcloud.storage(gcloudAuth);
var bucket = storageClient.bucket(bucketName);
bucket.upload(filename)
.then(() => {
console.log(filename + ' uploaded to ' + bucketName);
var speechClient = gcloud.speech(gcloudAuth);
const config = {
encoding: encoding,
sampleRateHertz: sampleRateHertz,
languageCode: languageCode
};
const audio = {
uri: gcsUri
//content: fs.readFileSync(filename).toString('base64'),
};
...

这种类型的操作有某种限制吗? 谢谢, 亚历克斯。