Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save willwhui/fd511cee75153bc73d51f451f3d9e0a2 to your computer and use it in GitHub Desktop.
Save willwhui/fd511cee75153bc73d51f451f3d9e0a2 to your computer and use it in GitHub Desktop.
搭建api.ai webhook(在朋友google cloud搭建的vps上使用python+flask+jinja)
搭建api.ai webhook(在朋友google cloud搭建的vps上使用python+flask+jinja)
@willwhui
Copy link
Author

willwhui commented Jul 4, 2017

让Google Home播放mp3文件

参见stackoverflow

var msg = `
  <speak>
    Tone one
    <audio src="https://examaple.com/wav/Dtmf-1.wav"></audio>
    Tone two
    <audio src="https://example.com/wav16/Dtmf-2.wav"></audio>
    Foghorn
    <audio src="https://example.com/mp3/foghorn.mp3"></audio>
    Done
  </speak>
  `;

  var reply = {
    speech: msg,
    data:{
      google:{
        "expect_user_response": true,
        "is_ssml": true
      }
    }
  };

  res.send( reply );

以上js代码的关键点在于:

  • api.ai的webhook返回字段的“speech"部分用msg来填充
  • 增加data字段
  • msg要符合google home要求的"SSML"规范
    参见google的文档:Format of response from the webhook
    根据SSML规范,speak字段中可以返回文本和mp3文件链接的混合物。

@willwhui
Copy link
Author

willwhui commented Jul 5, 2017

在flask中使用静态文件返回指向mp3的json

参见这里
只需要在template同级目录建立static目录就可以直接输入完整网址访问此目录下的所有文件

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment