Javascript 从cordova插件audioinput到Google语音API的音频流
对于一个使用Meteor框架的跨平台应用程序项目,我想录制麦克风输入并提取语音,感谢 在Google文档之后,我更具体地尝试构建一个音频流来为Google语音客户端提供信息 在客户端,录制按钮触发以下Javascript 从cordova插件audioinput到Google语音API的音频流,javascript,cordova,meteor,google-speech-api,google-cloud-speech,Javascript,Cordova,Meteor,Google Speech Api,Google Cloud Speech,对于一个使用Meteor框架的跨平台应用程序项目,我想录制麦克风输入并提取语音,感谢 在Google文档之后,我更具体地尝试构建一个音频流来为Google语音客户端提供信息 在客户端,录制按钮触发以下startCapture功能(基于): audioinput事件允许我在录制音频数据时获取音频数据块: window.addEventListener('audioinput', onAudioInputCapture, false); var audioDataQueue = []; funct
startCapture
功能(基于):
audioinput
事件允许我在录制音频数据时获取音频数据块:
window.addEventListener('audioinput', onAudioInputCapture, false);
var audioDataQueue = [];
function onAudioInputCapture(evt) {
try {
if (evt && evt.data) {
// Push the data to the audio queue (array)
audioDataQueue.push(evt.data);
// Here should probably be a call to a Meteor server method?
}
}
catch (e) {
}
}
我正在努力将录制的音频数据转换成一些可读的流,通过管道传输到服务器端的GoogleSpeechAPI客户端
const speech = require('@google-cloud/speech');
const client = new speech.SpeechClient();
const request = {
config: {
encoding: "LINEAR16",
sampleRateHertz: 16000,
languageCode: 'en-US',
},
interimResults: true,
};
export const recognizeStream = client
.streamingRecognize(request)
.on('error', console.error)
.on('data', data =>
console.log(data.results)
);
我尝试了以下方法,但感觉不是正确的方法:
const Stream = require('stream')
var serverAudioDataQueue = [];
const readable = new Stream.Readable({
objectMode: true,
});
readable._read = function(n){
this.push(audioDataQueue.splice(0, audioDataQueue.length))
}
readable.pipe(recognizeStream);
Meteor.methods({
'feedGoogleSpeech': function(data){
data.forEach(item=>serverAudioDataQueue.push(item));
},
...
});
对此有什么见解吗?凯文,你是如何处理这件事的?你找到解决办法了吗?
const Stream = require('stream')
var serverAudioDataQueue = [];
const readable = new Stream.Readable({
objectMode: true,
});
readable._read = function(n){
this.push(audioDataQueue.splice(0, audioDataQueue.length))
}
readable.pipe(recognizeStream);
Meteor.methods({
'feedGoogleSpeech': function(data){
data.forEach(item=>serverAudioDataQueue.push(item));
},
...
});