【发布时间】:2021-11-12 09:38:18
【问题描述】:
环境详情
- 操作系统:Windows 10、11。Debian 9(拉伸)
- Node.js 版本:12.18.3、12.22.1
- npm 版本:7.19.0、7.15.0
-
@google-cloud/dialogflow-cx版本:2.13.0
问题
StreamingDetectIntent 在匹配第一个意图后不处理音频。我能够看到转录并且它能够匹配第一个意图,但是在匹配第一个意图之后,音频继续流式传输但我没有收到转录,并且on('data') 回调也没有被触发。 简而言之,匹配第一个意图后什么都没有发生
解决它的一件事是我必须结束 detectStream 然后重新初始化它。然后它按预期工作。
重现步骤
我已尝试使用 const {SessionsClient} = require("@google-cloud/dialogflow-cx"); 和
const {SessionsClient} = require("@google-cloud/dialogflow-cx").v3;
// Create a stream for the streaming request.
const detectStream = client
.streamingDetectIntent()
.on('error', console.error)
.on('end', (data)=>{
console.log(`streamingDetectIntent: -----End-----: ${JSON.stringify(data)}`);
})
.on('data', data => {
console.log(`streamingDetectIntent: Data: ----------`);
if (data.recognitionResult) {
console.log(`Intermediate Transcript: ${data.recognitionResult.transcript}`);
} else {
console.log('Detected Intent:');
if(!data.detectIntentResponse) return
const result = data.detectIntentResponse.queryResult;
console.log(`User Query: ${result.transcript}`);
for (const message of result.responseMessages) {
if (message.text) {
console.log(`Agent Response: ${message.text.text}`);
}
}
if (result.match.intent) {
console.log(`Matched Intent: ${result.match.intent.displayName}`);
}
console.log(`Current Page: ${result.currentPage.displayName}`);
}
});
const initialStreamRequest = {
session: sessionPath,
queryInput: {
audio: {
config: {
audioEncoding: encoding,
sampleRateHertz: sampleRateHertz,
singleUtterance: true,
},
},
languageCode: languageCode,
}
};
detectStream.write(initialStreamRequest);
我尝试通过文件 (.wav) 和使用麦克风流式传输音频,但结果相同。
await pump(
recordingStream, // microphone stream <OR> fs.createReadStream(audioFileName),
// Format the audio stream into the request format.
new Transform({
objectMode: true,
transform: (obj, _, next) => {
next(null, {queryInput: {audio: {audio: obj}}});
},
}),
detectStream
);
我也提到了这个implementation 和这个rpc based doc,但找不到任何理由说明为什么这不起作用。
谢谢!
【问题讨论】:
标签: node.js google-cloud-platform grpc audio-streaming dialogflow-cx