简介
阅读有关 artyom 的简介
重要!
Artyom 只建议用于个人项目,你自己的 “人工智能” 或者什么疯狂项目。Artyom的初衷不是利用 webkitSpeechRecognition赚钱。
Artyom 只能运行于 Google Chrome Browser(webKit)。
Artyom 无法运行于本地文件(file://protocol),你需要一个服务器或者本地服务去运行之。
如果你希望以持续模式(continuous mode)使用 Artyom,那么你需要提供https://链接。否则,Google> Chrome 将会在 Artyom 每次重启其自身时请求许可。如果你执行 artyom.detectErrors() 函数,你会看到其他的警告信息。
Artyom 如何使用
Artyom.js 包含两个部分: the voice commands recognition 和 speech synthesis。每个模块是完全独立的,这意味着你可以只使用 speech synthesis 模块或者只使用 the voice commands recognition 模块。
Artyom 可以在浏览器中直接使用(通过 artyom.window.js
),或者通过打包工具(webpack,browserify)使用 artyom.js
。
无论通过哪一种方式,你都会用到 Artyom Clas 并且需要将其实例化以使用 artyom 的其他方法:
// Using the /build/artyom.js file
// with ES6,TypeScript etc
import Artyom from 'artyom.js';
const Jarvis = new Artyom();
Jarvis.say("Hello World !");
如果你在通过浏览器使用 artyom:
<script src="artyom.window.js"></script>
<script>
var Jarvis = new Artyom();
Jarvis.say("Hello World !");
</script>
Voice commands
Voice commands 功能适用于通过speech recognition API 获得的翻译文本匹配既定的文本(命令)。Artyom 提供了封装方法以保存命令,对于大量的命令可以使用 artyom.addCommands
方法,而对于少数的几条命令可以使用 artyom.on
方法。
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");
});
在添加一系列命令后,使用artyom.initialize
方法继续进行命令识别的初始化(不要忘记将listen属性设置为true以开始识别):
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
});
初始化之后,该API将会请求客户端的麦克风,之后命令识别开始运行。命令识别提供了三个模式(于初始化文档了解相关信息)。
Speech synthesis
Artyom提供了好用的功能来轻松合成文本。artyom.say
函数接受至多两个参数,其中第一个参数是必须的(用于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");
}
});
而让artyom 最棒的地方是提供了处理语音合成API文字长度的限制的方法。你只需要考虑哪些你想要合成的文本。
这就是简介的全部内容了,祝你好运。
Last updated
Was this helpful?