【发布时间】:2020-08-31 17:54:24
【问题描述】:
我想在我的 Web 应用程序中集成一个 HTML5 麦克风,录制音频并将其发送到 (Node.js) 后端,使用 Dialogflow API 获取音频,并将音频结果返回给客户端以在其中播放浏览器。
(我使用 Windows 10、适用于 Linux 的 Windows 子系统、Debian 10.3 和 Google Chrome 浏览器。 )
我找到了一个 github 项目,这正是我想做的。 https://github.com/dialogflow/selfservicekiosk-audio-streaming
这是 Lee Boonstra 女士的 Medium 博客。 (https://medium.com/google-cloud/building-your-own-conversational-voice-ai-with-dialogflow-speech-to-text-in-web-apps-part-i-b92770bd8b47) 她开发了这个项目。 (非常感谢您,Boonstra 女士!)她非常准确地解释了这个项目。
该项目包含自助服务亭应用程序和 6 个简单示例。 我都试过了。 selfservicekiosk 应用程序和简单示例 1、2、4、5、6 运行良好,但 example3 没有运行。 不幸的是,example3 是我想要做的。 https://github.com/dialogflow/selfservicekiosk-audio-streaming/tree/master/examples
这些是我尝试 example3 时的结果。
我专注于这条信息。
(index):59
ArrayBuffer(0)
[[Int8Array]]: Int8Array []
[[Int16Array]]: Int16Array []
[[Int32Array]]: Int32Array []
[[Uint8Array]]: Uint8Array []
我认为浏览器可以得到音频结果,但不能播放。
首先,我检查了我电脑的麦克风设置和浏览器的网络应用活动和语音/音频(https://myaccount.google.com/activitycontrols)。
两者都已启用。
接下来,我检查 example3.html 文件并找到在我的环境中似乎不起作用的代码。但是,我不知道如何更改它。
/*
* When working with Dialogflow and Dialogflow matched an intent,
* and returned an audio buffer. Play this output.
*/
function playOutput(arrayBuffer){
let audioContext = new AudioContext();
let outputSource;
try {
if(arrayBuffer.byteLength > 0){
audioContext.decodeAudioData(arrayBuffer,
function(buffer){
audioContext.resume();
outputSource = audioContext.createBufferSource();
outputSource.connect(audioContext.destination);
outputSource.buffer = buffer;
outputSource.start(0);
},
function(){
console.log(arguments);
});
}
} catch(e) {
console.log(e);
}
}
你能给我什么建议吗?提前谢谢你。
我想检查音频结果,所以我打开了 simpleserver.js 文件并进行了更改
async function detectIntent(audio){}
https://github.com/dialogflow/selfservicekiosk-audio-streaming/blob/master/examples/simpleserver.js
async function detectIntent(audio){
request.inputAudio = audio;
console.log(request);
const responses = await sessionClient.detectIntent(request);
const audioFile = responses[0].outputAudio;
util.promisify(fs.writeFile)('test.wav', audioFile, 'binary');
console.log('completed');
}
我打开了 test.wav 文件并确保对话流给了我音频结果。
【问题讨论】:
-
请注意。过去我们不这样做。如果是面向公众的,那么嵌入在笔记本电脑中的麦克风太差了,以至于我们从来没有得到足够好的 STT 结果来给出一个像样的对话流分类
-
同意贝努瓦!我为一个贸易展创建了这个演示,我一直在使用 Yeti 麦克风来获得最佳质量,尤其是在拥挤的环境中。如果你真的要建造这个(比如说机场的自助服务亭),你会为此使用适当的硬件,甚至可能在麦克风周围使用一些防护罩。
-
@BenoitAlvarez @LeeBoonstra 感谢您的建议。我注意到麦克风非常重要。我不知道 Yeti 麦克风,它看起来很棒。感谢您的信息。
标签: javascript node.js audio google-cloud-platform dialogflow-es