In the previous blog post, I introduced the Smart Learning module in Myvoix.js and how to use it. (Myvoix.js source address will be released at the end of each article)
The text will expand the voice control framework under Chrome myvoix.js using the example in Chapter (ii) (please poke a link with a classmate who has not seen it), to introduce the use of the Smart Learning module in an image. In the previous example, we had the voice input to change the Hello My voix title to various colors and to increase the recognition rate of the voice instruction by the pre-save instruction. In this article, we will remove the stored instructions, and receive the pronunciation of different accents through the smart learning module.
First, we added a button to control the smart learning on and off, and a label to record the operation of the Smart learning module.
The interface code is as follows:
1 <Body>2 <H1>Hello My Voix</H1>3 <inputtype= ' button 'value= "Start" />4 <P>0</P>5 </Body>
In this example, we only test the word 'red' with smart learning to reduce the logic complexity of the UI code. After understanding how smart learning is used, the reader can create a complete UI on its own.
This page is played as follows:
1) Tap the "Start" button to turn on smart learning. At this time the user's voice input will be connected to the red Word by the smart learning. The "Start" button becomes the "Stop" button.
2) Each time the user has a voice input, the number below the button will be +1.
3) Click "Stop" button to turn off smart learning. The button below the count will clear 0, the user after the voice input, will make the title color.
Attach the JavaScript section code:
1Window.onload=function(){2 var_myvoix =NewMyvoix (undefined,undefined,true),3_title=document.getelementsbytagname (' H1 ') [0],4_btn=document.getelementsbytagname (' INPUT ') [0],5_tag = document.getElementsByTagName (' P ') [0],6_colors=[' red ', ' black ', ' blue ', ' green ', ' yellow '];7 _myvoix.start ();8 for(vari=0,l=_colors.length;i<l;i++){9(function(i) {Ten_myvoix.bind (_colors[i],function(){ One_title.style.color=_colors[i]; A }); - }) (i); - } the -_btn.onclick=function(){ - if(_btn.value=== ' Stop '){ -_tag.innerhtml= ' 0 '; +_myvoix.currentlearning =undefined; -_btn.value= ' Start '; +}Else{ A_myvoix.currentlearning = ' Red '; at_btn.value= ' Stop '; - } - }; - -_myvoix.onlearning=function(){ -_tag.innerhtml= +_tag.innerhtml+1; in }; -};
With the code, understand the function of the page, we can simply test it. We recommend that you open the console to monitor voice input .
, after clicking the Start button, we entered 5 voice commands, which were parsed by Google as ' Red ', ' ride ', ' Ride ', ' bento ', ' red '. Then we click the Stop button and enter the Voice command again, and when Google parses our input into ' ride ', ' Bento ', our headline will also turn red.
The essence of Smart learning is actually associating a set of commands to a voice command. So in practical applications, we can also use smart learning to allow users to customize voice commands.
, I linked the Hi command to the red command, saying hi to the microphone and getting the title red.
So far, the students should have been able to use Myvoix.js to develop some simple applications. In this series after the text Bo, I will explain to you myvoix.js data structure, the progress of the introduction of the essence of Myvoix.
Myvoix Source Address
forwarding Please specify the source : http://www.cnblogs.com/arthus/p/3708502.html