首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Google \ StreamingDetectIntent在匹配第一意图后不处理音频

Google \ StreamingDetectIntent在匹配第一意图后不处理音频
EN

Stack Overflow用户
提问于 2021-09-17 13:53:21
回答 1查看 422关注 0票数 0

环境细节

  • 操作系统: 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;

代码语言:javascript
复制
// 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) &使用麦克风,但结果是相同的行为。

代码语言:javascript
复制
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
    );

我也提到过这个实现和这个基于rpc的文档,但是没有找到任何理由来解释为什么这不应该起作用。

谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-09-20 12:29:50

根据文档的说法,这似乎是正确的行为。

当对话流检测到音频的声音已经停止或暂停时,它将停止语音识别,并将带有StreamingDetectIntentResponse识别结果的END_OF_SINGLE_UTTERANCE发送给客户端。接收到END_OF_SINGLE_UTTERANCE后发送到流上的任何音频都会被对话框忽略。

因此,这似乎是为什么StreamingDetectIntent不处理音频后,匹配的第一个意图。根据同一文件:

关闭流后,客户端应根据需要使用新流启动新请求。

你应该启动另一条流。您也可以在同一主题中检查其他github问题

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69224606

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档