YODAOS Developer Tools
YODAOS Developer Tools provides a range of convenient tools for manipulating YODAOS devices, such as sending text commands, sending NLP intents, launching, installing applications, etc.
The YODAOS Developer Tools can be downloaded from the YODAOS Developer Tools Releases page.
Creating a YODAOS application
With the YODAOS Developer Tools, we can quickly create a YODAOS application project:
~/workspace > yoda-cli init app awesome-demo-app
✔ Name of the package ... awesome-demo-app
✔ A short description of the package ... A demo application project
✔ Is this package private? ... no / yes
✔ Skill ids of your app ...
✔ Requested permissions of your app ... ACCESS_TTS
✔ Keywords ... demo, app
After running the above command, you can see the generated YODAOS application project in the awesome-demo-app
directory in the current directory.
More yoda-cli
commands can be viewed with yoda-cli help
.
Once the project is built, you can install the app on your YODAOS device:
~/workspace > yoda-cli pm install awesome-demo-app
Or,
~/workspace/awesome-demo-app > yoda-cli pm install .
Program entry: Main function
For YODAOS, each application is a CommonJS module. Every CommonJS module will have a reference to module.exports
, and the application of YODAOS is the same. His main entry is a function that receives a activity
as a parameter via module.exports
.
module.exports = function main (activity) {
}
The application interacts with the system through the activity
object provided by the system framework, such as receiving the system, application events, and calling the system API.
Interact with YODAOS
The activity
provided by the system framework is an object that conforms to Node.js EventEmitter API, on which we can listen to any application. Life cycle events:
module.exports = function main (activity) {
activity.on('create', () => {
/** do initialization on event `create` */
})
activity.on('request', () => {
activity.tts.speak('Hello World')
})
}
View more life cycle documentation: Life Cycle
Application Manifest
In addition to the program code, the application needs to declare its own identity, permission request and other information, so that YODAOS allocates resources to the application, distributes NLP, and so on. The package.json of the YODAOS app contains this information:
{
"name": "com.company.example.awesome-app",
"version": "1.0.0",
"main": "app.js",
"manifest": {
"skills": [
"an-pre-registered-skill-id"
],
"permission": [
"ACCESS_TTS",
"ACCESS_MULTIMEDIA"
]
}
}
Package.json is similar to the npm package, but for YODAOS applications, the most important of these is name
and manifest
: the former declares the ID of the application, the latter declares the permissions, skill IDs, etc. that need to be requested from YodaRuntime.
View more package.json Description document: Apply Manifest
Processing voice requests
After writing the NLP matching rules on the Rokid developer website, you can write the following code in the application code to process the voice request:
module.exports = function main (activity) {
activity.on('request', nlp => {
activity.tts.speak(`Hello, ${nlp.slots.value}`)
})
}
Processing URL requests
The application can evoke other applications in the form of URLs and entrust the current interaction to the application that can handle the URL.
If you want to process the URL of a domain name, you need to register the URL in the app's package.json . Here's an example of registering a foobar.app domain name:
{
"manifest": {
"skills": ["AVERYLONGSKILLID"],
"hosts": [
[ "foobar.app", { "skillId": "AVERYLONGSKILLID" } ]
]
}
}
See more apps Manifest Document: Apply Manifest
After registering such a domain name, other applications can evoke the application by calling:
activity.openURL('yoda-skill://foobar.app/example')
An application that has registered the domain name can process the URL request with the following code:
module.exports = function main (activity) {
activity.on('url', urlObject => {
activity.tts.speak(`Opened URL ${url.pathname}`)
})
}
See more documentation for URL Object: Legacy urlObject