对于使用Meteor框架的跨平台应用程序项目,我想记录麦克风输入并提取语音,这要归功于Google Speech API
根据Google文档,我更具体地尝试构建音频流以馈送Google Speech客户端。
在客户端,一个录制按钮触发以下startCapture功能(基于cordova audioinput plugin):
export var startCapture = function () {
try {
if (window.audioinput && !audioinput.isCapturing()) {
setTimeout(stopCapture, 20000);
var captureCfg = {
sampleRate: 16000,
bufferSize: 2048,
}
audioinput.start(captureCfg);
}
}
catch (e) {
}
}
Run Code Online (Sandbox Code Playgroud)
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 …Run Code Online (Sandbox Code Playgroud) javascript cordova meteor google-speech-api google-cloud-speech