首页 > 解决方案 > 基于 Alexa Skill 的 WordPress 语音识别

问题描述

我想开发一个 WordPress 插件,允许用户与 WordPress 网站进行语音交互。我希望它基于 Alexa Skill。

这项任务的架构是什么?

标签: wordpresspluginsalexa

解决方案


If you think your use case is relatively standard, you can take a look at VoiceWP, which was built to allow for management of an Alexa skill mostly from within WordPress.

If you need something more custom, you can use the WordPress REST API to provide Alexa with the data you need. With this architecture, your plugin on the WordPress side would just be setting up and managing all the REST API endpoints.

From the top down the architecture looks like this:

Architecture Diagram of an Example Alexa Skill

This leaves you with 3 pieces to build:

Set up the Alexa Skill

First, you have to set up the skill with the Alexa Skills Kit. This involves setting up things like the name of your skill, the icon, and most importantly, where the skill should look to get it's functionality. In our example, we'll point the skill to an AWS Lambda function.

Set up the Lambda Skill to fulfill the Alexa input

Once the Skill knows to look to the Lambda function for it's functionality, we actually need to code the Lambda function. This can be done in Node.js (JavaScript), Python, Java (Java 8 compatible), C# (.NET Core) or Go. What the Lambda function needs to do is parse the JSON that comes from Alexa and determine which endpoint to call or which parameters to pass to this endpoint. For an example of this in Python, you can check out my example on GitHub.

Set up WordPress endpoints to provide data

Once you have the Lambda function parsing the user's intent and pushing the request to the specific endpoints, you need to write the code from within WordPress to make sure all the endpoints you need are available. This is the part that I'm able to give the least input on because the specific endpoints that you will need are based on your use case, which I don't really know at this point. But for an example of how we created a settings field and returned that value through a custom REST API endpoint, you can see this example on GitHub.

Wrapping up and Extending it Further

So once the data is returned from WordPress, formatted by the Lambda function and returned to Alexa, the user will hear the results of their query.

This can be customized and further functionality added by adding more endpoints to WordPress and more routing to the Lambda function based on new Alexa voice inputs.

Further Reading Watching

If you're interested in learning more, I've given a couple talks about this:


推荐阅读