【问题标题】:speech services of a bot are not working in "Test in Web chat" option in Azure机器人的语音服务在 Azure 中的“Web 聊天测试”选项中不起作用
【发布时间】:2019-06-18 10:55:10
【问题描述】:

我在 Azure 门户上部署了一个 Web 机器人应用程序。该机器人使用语音服务来获取用户输入,但在将其部署到 azure 后,语音服务无法正常工作并且它不接受语音信息。

即使我在 Azure 中单击网络聊天窗口上的音频图标,它也没有

此机器人已在 Bot 模拟器上进行了本地测试并按要求工作。但在 Azure 中,它没有。不知道怎么回事。

有什么意见吗?

【问题讨论】:

  • bot 应用程序窗口中的网络聊天窗口是否没有使用网络聊天频道?
  • 机器人是否响应文本输入?

标签: botframework azureportal direct-line-botframework


【解决方案1】:

请仔细检查您是否已将所有适当的凭据插入到配置中。网络聊天中的测试应该开箱即用,没有问题。

话虽如此,网络聊天中的测试功能使用较旧的 v3 BotFramework-WebChat(即 BotChat)实现。虽然计划更新(此时没有 ETA),但底层代码可能对您来说是个问题。

如果您想测试网络聊天,我建议您在本地设置一个 v4 网络聊天环境。这实际上很容易做到。以下是方法,如果感兴趣的话:

首先,在 Azure 机器人设置中启用 Direct Line 通道...

...复制秘密并暂时保存在某个地方。

将此代码添加到您的机器人的 index.js 文件中(可以完整地附加到末尾)。从 .env 文件存储和访问您复制的直接线路密码。这将保存为directLineSecret,并作为Bearer {token} 传递到授权中。另请注意,使用的端口是 3500,但您可以将其设置为您选择的任何内容。此令牌端点将在您运行机器人时运行。

/**
 * Creates token server
 */
const bodyParser = require('body-parser');
const request = require('request');
const corsMiddleware = require('restify-cors-middleware');

const cors = corsMiddleware({
  origins: ['*']
});

// Create server.
let tokenServer = restify.createServer();
tokenServer.pre(cors.preflight);
tokenServer.use(cors.actual);
tokenServer.use(bodyParser.json({
  extended: false
}));
tokenServer.dl_name = 'DirectLine';
tokenServer.listen(process.env.port || process.env.PORT || 3500, function() {
  console.log(`\n${ tokenServer.dl_name } listening to ${ tokenServer.url }.`);
});

// Listen for incoming requests.
tokenServer.post('/directline/token', (req, res) => {
  // userId must start with `dl_`
  const userId = (req.body && req.body.id) ? req.body.id : `dl_${ Date.now() + Math.random().toString(36) }`;
  const options = {
    method: 'POST',
    uri: 'https://directline.botframework.com/v3/directline/tokens/generate',
    headers: {
      'Authorization': `Bearer ${ process.env.directLineSecret}`
    },
    json: {
      User: {
        Id: userId
      }
    }
  };
  request.post(options, (error, response, body) => {
    if (!error && response.statusCode < 300) {
      res.send({
        token: body.token
      });
    } else {
      res.status(500);
      res.send('Call to retrieve token from DirectLine failed');
    }
  });
});

接下来,创建这个简单的 index.html 页面,该页面从您的令牌端点请求令牌并实例化网络聊天。这将需要认知服务语音服务订阅密钥来启用可以在 Azure 中创建的语音。如果您更改了令牌端点中的端口,请在 await fetch 的 html 文件中进行匹配。

<!DOCTYPE html>
<html>

  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>WebChat</title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style>
      html,
      body {
        height: 100%
      }

      body {
        margin: 0
      }

      #webchat,
      #webchat>* {
        height: 100%;
        width: 100%;
      }
    </style>
  </head>

  <body>
    <div id="webchat" role="main"></div>
    <script type="text/javascript"
      src="https://unpkg.com/markdown-it/dist/markdown-it.min.js"></script>
    <script
      src="https://cdn.botframework.com/botframework-webchat/master/webchat.js"></script>
    <script>
    ( async function () {
      const res = await fetch( 'http://localhost:3500/directline/token', { method: 'POST' } );
      const { token } = await res.json();

      const webSpeechPonyfillFactory = await window.WebChat.createCognitiveServicesSpeechServicesPonyfillFactory( {
        region: '',  // 'westus', for example
        subscriptionKey: ""
      } );

      window.WebChat.renderWebChat( {
        directLine: window.WebChat.createDirectLine( { token } ),
        webSpeechPonyfillFactory
      }, document.getElementById( 'webchat' ) );
      document.querySelector( '#webchat > *' ).focus();
    } )().catch( err => console.error( err ) );
  </script>
  </body>
</html>

最后,将运行 html 页面的本地 Web 服务器添加到 Azure 机器人设置的 Direct Line 通道中的受信任 URL 列表中,并与机器人一起在本地运行 html 页面。您现在拥有一个可以进行测试的本地 v4 网络聊天环境。

希望有帮助!

【讨论】:

    【解决方案2】:

    您可以在网络聊天控件中启用语音界面。用户可以通过Web Chat控件中的麦克风与语音界面进行交互。请参考以下链接https://docs.microsoft.com/en-us/azure/bot-service/bot-service-channel-connect-webchat-speech?view=azure-bot-service-3.0

    【讨论】:

      猜你喜欢
      • 2019-11-23
      • 2020-03-31
      • 1970-01-01
      • 2017-08-25
      • 1970-01-01
      • 1970-01-01
      • 2021-05-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多