Did you like the demostration of artyom and you want to be part of it? Let's get started. There are a couple of things that you need to know before start to using artyom in your project.
Important tips
- Artyom is suggested for personal projects, your own "artificial inteligence" or other crazy project. It was not created with the intention of making money from the use of this tool based on webkitSpeechRecognition.
- Artyom only works in Google Chrome Browser (webKit).
- Artyom doesn't run in Local Files (file:// protocol) is necesary have a server o local server (wamp o xampp for example).
- Artyom needs a https:// connection if you want the continuous mode, otherwise , Google Chrome will ask for permissions every time artyom restarts itself. If you execute artyom.detectErrors() you will notice other warnings.
- See further information in why https connection for voice recognition.
If you're not satisfied with the actual version, feel free to modify artyom as you like in the official repository in Github here or don't hesitate to suggest new feature for artyom in the issues section.
How artyom works
Artyom.js consists of 2 parts: the voice commands recognition and the speech synthesis. Every module is independent, that means that you can use only the speech synthesis if you want and vice versa.
Artyom can be used directly from the browser using the artyom.window.js
file or with any bundler like Webpack, Browserify etc using the artyom.js
file.
Either in the browser or using a module bundler, you will obtain the Artyom class and you need to instantiate it to use the other methods:
// Using the /build/artyom.js file
// with ES6,TypeScript etc
import Artyom from 'artyom.js';
const Jarvis = new Artyom();
Jarvis.say("Hello World !");
Or if you are using it from the browser:
<script src="artyom.window.js"></script>
<script>
var Jarvis = new Artyom();
Jarvis.say("Hello World !");
</script>
Voice commands
The voice commands functionality, is created by matching a given text (the command) with the transcripted text from the speech recognition API. Artyom provides a wrapper to save commands using the artyom.addCommands
method (to add massive commands) or the artyom.on
function to add only a couple of commands.
var artyom = new Artyom();
artyom.addCommands([
{
indexes: ["Good morning"],
action: function(i){
console.log("Good morning Triggered");
}
},
{
indexes: ["Good night"],
action: function(i){
console.log("Good night Triggered");
}
}
]);
// Or the artisan mode to write less
artyom.on(["Good morning"]).then(function(i){
console.log("Triggered");
});
After add a couple of commands, proceed with the initialization of the command recognition using the artyom.initialize method (don't forget to set the listen property to true to start the recognition):
var artyom = new Artyom();
artyom.initialize({
lang:"en-GB",
debug:true, // Show what recognizes in the Console
listen:true, // Start listening after this
speed:0.9, // Talk a little bit slow
mode:"normal" // This parameter is not required as it will be normal by default
});
After initialize, the API will request access to the microphone and the command recognition will start. The command recognition provide 3 modes that you can check in the initialization docs.
Speech synthesis
Artyom provides an useful and compact function to synthesize text easily. The artyom.say
function receives up to 2 parameters, which only the first is required (the text to synthesize).
var artyom = new Artyom();
artyom.say("A long text here",{
onStart: function(){
console.log("Talking ...");
},
onEnd: function(){
console.log("I said all that i knew");
}
});
What makes artyom awesome, is that it will take care about the annoying words limit of the speech synthesis API. You only need to worry about how to provide the text you want to synthesize.
That's all for now, read the docs, have fun and create something awesome!