This repository has been archived by the owner on Jul 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
speak and listen blocks 3.xml
16 lines (16 loc) · 8.19 KB
/
speak and listen blocks 3.xml
1
<blocks app="Snap! 4.0, http://snap.berkeley.edu" version="1"><block-definition s="listen for a number %'what to do with the number' %'what to do if not a number'" type="command" category="sensing"><header></header><code></code><inputs><input type="%cmdRing"></input><input type="%cmdRing"></input></inputs><script><custom-block s="Listen then %cmdRing but if error %cmdRing"><block s="reifyScript"><script><block s="doIfElse"><block s="reportIsA"><block var="spoken"/><l><option>number</option></l></block><script><block s="doRun"><block var="what to do with the number"/><list><block var="spoken"/></list></block></script><script><block s="doRun"><block var="what to do if not a number"/><list><block var="spoken"/></list></block></script></block></script><list><l>spoken</l></list></block><block var="what to do if not a number"/></custom-block></script></block-definition><block-definition s="set language to %'language'" type="command" category="other"><header></header><code></code><inputs><input type="%s"></input></inputs><script><block s="doRun"><block s="reportJSFunction"><list><l>lang</l></list><l>if (window.speech_recognition) {
 window.speech_recognition.lang = lang;
}</l></block><list><block var="language"/></list></block></script></block-definition><block-definition s="run eCraft2Learn command %'command name' with %'inputs'" type="command" category="other"><header></header><code></code><inputs><input type="%txt"></input><input type="%mult%s"></input></inputs><script><block s="doRun"><block s="reportJSFunction"><list><l>function_name</l><l>parameters</l></list><l>if (typeof ecraft2learn === 'object') {






 ecraft2learn.run(function_name, parameters);






} else {






 var script = document.createElement("script");






 script.type = "text/javascript";






 script.src = "https://toontalk.github.io/ai-cloud/ecraft2learn.js";






 script.addEventListener('load', function () {






 ecraft2learn.run(function_name, parameters);






 });






 document.head.appendChild(script);






}</l></block><list><block var="command name"/><block var="inputs"/></list></block></script></block-definition><block-definition s="call eCraft2Learn reporter %'reporter name' with %'inputs'" type="reporter" category="other"><header></header><code></code><inputs><input type="%txt"></input><input type="%mult%s"></input></inputs><script><block s="doReport"><block s="evaluate"><block s="reportJSFunction"><list><l>function_name</l><l>parameters</l></list><l>if (typeof ecraft2learn === 'object') {






 return ecraft2learn.run(function_name, parameters);






} else {






 alert("Any eCraft2Learn command must be run before the " + function_name + " reporter.");






 return 0;






}</l></block><list><block var="reporter name"/><block var="inputs"/></list></block></block></script></block-definition><block-definition s="speak %'message' then %'what to do when finished' with pitch %'pitch' with rate %'rate' with voice %'voice' with volume %'volume' in language %'language code'" type="command" category="sound"><header></header><code></code><inputs><input type="%s"></input><input type="%cmdRing"></input><input type="%n"></input><input type="%n"></input><input type="%n"></input><input type="%n"></input><input type="%txt"></input></inputs><script><custom-block s="run eCraft2Learn command %txt with %mult%s"><l>speak</l><list><block var="message"/><block var="pitch"/><block var="rate"/><block var="voice"/><block var="volume"/><block var="language code"/><block var="what to do when finished"/></list></custom-block></script></block-definition><block-definition s="Get voice names" type="reporter" category="sound"><header></header><code></code><inputs></inputs><script><block s="doReport"><custom-block s="call eCraft2Learn reporter %txt with %mult%s"><l>get_voice_names</l><list></list></custom-block></block></script></block-definition><block-definition s="voice name of %'voice number'" type="reporter" category="sound"><header></header><code></code><inputs><input type="%n"></input></inputs><script><block s="doReport"><custom-block s="call eCraft2Learn reporter %txt with %mult%s"><l>get_voice_name</l><list><block var="voice number"/></list></custom-block></block></script></block-definition><block-definition s="Speak %'message' then %'to do when finished speaking'" type="command" category="sound"><header></header><code></code><inputs><input type="%txt"></input><input type="%cmdRing"></input></inputs><script><custom-block s="run eCraft2Learn command %txt with %mult%s"><l>speak</l><list><block var="message"/><l></l><l></l><l></l><l></l><l></l><block var="to do when finished speaking"/></list></custom-block></script></block-definition><block-definition s="Stop speech recognition" type="command" category="sensing"><header></header><code></code><inputs></inputs><script><custom-block s="run eCraft2Learn command %txt with %mult%s"><l>stop_speech_recognition</l><list></list></custom-block></script></block-definition><block-definition s="Speak %'message'" type="command" category="sound"><header></header><code></code><inputs><input type="%txt"></input></inputs><script><custom-block s="run eCraft2Learn command %txt with %mult%s"><l>speak</l><list><block var="message"/><l></l><l></l><l></l><l></l><l></l><l></l></list></custom-block></script></block-definition><block-definition s="listen" type="command" category="sensing"><comment x="0" y="0" w="90" collapsed="false">When something is spoken this broadcasts 'heard something' and sets 'last thing spoken' to the text that was spoken.</comment><header></header><code></code><inputs></inputs><script><custom-block s="Listen then %cmdRing but if error %cmdRing"><block s="reifyScript"><script><block s="doSetVar"><l>last thing spoken</l><block var="spoken"/></block><block s="doBroadcast"><l>heard something</l></block><custom-block s="listen"></custom-block></script><list><l>spoken</l></list></block><block s="reifyScript"><script><block s="doSetVar"><l>speech recognition error</l><block var="error"/></block><block s="doBroadcast"><l>speech recognition error</l></block><block s="doIfElse"><block s="reportEquals"><block var="speech recognition error"/><l>no-speech</l></block><script><custom-block s="Speak %txt"><l>I didn't hear anything for a while. Bye. Click the green flag to start listening again..</l></custom-block><custom-block s="Stop speech recognition"></custom-block></script><script><custom-block s="Speak %txt"><block s="reportJoinWords"><list><l>There was an error. </l><block var="speech recognition error"/></list></block></custom-block><block s="bubble"><block s="reportJoinWords"><list><l>There was an error. </l><block var="speech recognition error"/></list></block></block><custom-block s="Speak %txt then %cmdRing"><l>Try again.</l><block s="reifyScript"><script><custom-block s="listen"></custom-block></script><list></list></block></custom-block></script></block></script><list><l>error</l></list></block></custom-block></script></block-definition><block-definition s="Listen then %'handle response' but if error %'handle error'" type="command" category="sensing"><header></header><code></code><inputs><input type="%cmdRing"></input><input type="%cmdRing"></input></inputs><script><custom-block s="run eCraft2Learn command %txt with %mult%s"><l>start_speech_recognition</l><list><block var="handle response"/><block var="handle error"/></list></custom-block></script></block-definition><block-definition s="Microsoft speech key" type="reporter" category="other"><header></header><code></code><inputs></inputs><script><block s="doReport"><l>Enter your key here</l></block></script></block-definition></blocks>