123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571 |
- /**
- * @license
- * Visual Blocks Editor
- *
- * Copyright 2012 Google Inc.
- * https://developers.google.com/blockly/
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- /**
- * @fileoverview Colour blocks for Blockly.
- * @author fraser@google.com (Neil Fraser)
- */
- 'use strict';
- goog.provide('Blockly.Blocks.voicekit');
- goog.require('Blockly.Blocks');
- /**
- * Common HSV hue for all blocks in this category.
- */
- Blockly.Blocks.voicekit.HUE = "#3382f5";
- Blockly.Blocks["voicekit_from"] = {
- init: function() {
- this.setColour(Blockly.Blocks.voicekit.HUE);
- this.appendValueInput("INPUT")
- .appendField(Blockly.Msg.VOICEKIT_FROM)
- .appendField(new Blockly.FieldDropdown([
- ["aiy.voice","aiy.vocie"],
- ["aiy.assistant","aiy.assistant"],
- ["aiy.assistant.library","aiy.assistant.library"],
- ["google.assistant.library.event","google.assistant.library.event"]
- ]),"FROM")
- this.setPreviousStatement(true);
- this.setNextStatement(true);
- }
- }
- Blockly.Blocks["voicekit_import"] = {
- init:function() {
- this.setColour(Blockly.Blocks.voicekit.HUE);
- this.appendDummyInput()
- .appendField(Blockly.Msg.VOICEKIT_IMPORT_AUTH)
- this.setOutput(true);
- }
- }
- Blockly.Blocks["voicekit_import_tts"] = {
- init:function() {
- this.setColour(Blockly.Blocks.voicekit.HUE);
- this.appendDummyInput()
- .appendField(Blockly.Msg.VOICEKIT_IMPORT_TTS)
- // this.setOutput(true);
- this.setPreviousStatement(true);
- this.setNextStatement(true);
- }
- }
- Blockly.Blocks["voicekit_tts_say"] = {
- init:function() {
- this.setColour(Blockly.Blocks.voicekit.HUE);
- this.appendValueInput("TEXT")
- .appendField(Blockly.Msg.VOICEKIT_IMPORT_TTS_SAY)
- this.setInputsInline(true)
- this.setPreviousStatement(true);
- this.setNextStatement(true);
- }
- }
- Blockly.Blocks["voicekit_set_credential"] = {
- init:function() {
- this.setColour(Blockly.Blocks.voicekit.HUE);
- this.appendValueInput("INPUT")
- .appendField(Blockly.Msg.VOICEKIT_SET_CREDENTIAL)
- .appendField(new Blockly.FieldTextInput("assistant"),"ASSISTANT")
- .appendField(Blockly.Msg.VOICEKIT_SET_FROM)
- this.appendStatementInput("STACK")
- .appendField(Blockly.Msg.VOICEKIT_SET_DO)
- this.setPreviousStatement(true);
- this.setNextStatement(true);
- }
- }
- Blockly.Blocks['voicekit_get_credential'] = {
- init:function() {
- this.setColour(Blockly.Blocks.voicekit.HUE);
- this.appendDummyInput()
- .appendField(Blockly.Msg.VOICEKIT_GET_CREDENTIAL)
- this.setOutput(true);
- }
- }
- Blockly.Blocks['voicekit_import_assistant'] = {
- init:function() {
- this.setColour(Blockly.Blocks.voicekit.HUE);
- this.appendDummyInput()
- .appendField(Blockly.Msg.VOICEKIT_IMPORT_ASSISTANT)
- this.setOutput(true);
- }
- }
- Blockly.Blocks['voicekit_assistant_preNext'] = {
- init:function() {
- this.setColour(Blockly.Blocks.voicekit.HUE)
- this.appendValueInput("INPUT")
- .appendField(Blockly.Msg.VOICEKIT_ASSISTANT)
- this.appendDummyInput()
- .appendField(new Blockly.FieldDropdown([
- ["stop conversation","stop_conversation()"],
- ["start conversation","start_conversation()"]
- ]),"OPERATION")
- this.setInputsInline(true);
- this.setPreviousStatement(true)
- this.setNextStatement(true);
- }
- }
- Blockly.Blocks['voicekit_assistant_output'] = {
- init:function() {
- this.setColour(Blockly.Blocks.voicekit.HUE)
- this.appendValueInput("INPUT")
- .appendField(Blockly.Msg.VOICEKIT_ASSISTANT)
- this.appendDummyInput()
- .appendField(new Blockly.FieldDropdown([
- ["stop conversation","stop_conversation()"],
- ["start conversation","start_conversation()"]
- ]),"OPERATION")
- this.setInputsInline(true);
- // this.setPreviousStatement(true)
- // this.setNextStatement(true);
- this.setOutput(true);
- }
- }
- Blockly.Blocks['voicekit_EventType_import'] = {
- init:function() {
- this.setColour(Blockly.Blocks.voicekit.HUE)
- this.appendDummyInput()
- .appendField(Blockly.Msg.VOICEKIT_EVENTTYPE_IMPORT)
- // this.setInputsInline(true);
- // this.setPreviousStatement(true)
- // this.setNextStatement(true);
- this.setOutput(true);
- }
- }
- Blockly.Blocks['voicekit_event_of'] = {
- init:function() {
- this.setColour(Blockly.Blocks.voicekit.HUE);
- this.appendValueInput("INPUT")
- .appendField(Blockly.Msg.VOICEKIT_EVENT_TYPE_OF)
- this.setInputsInline(true);
- this.setOutput(true);
- }
- }
- Blockly.Blocks['voicekit_run_task'] = {
- init:function(){
- this.setColour(Blockly.Blocks.voicekit.HUE)
- this.appendDummyInput()
- .appendField("_run_task")
- this.setOutput(true)
- }
- }
- Blockly.Blocks['voicekit_process_event'] = {
- init:function() {
- this.setColour(Blockly.Blocks.voicekit.HUE)
- this.appendDummyInput()
- .appendField("_process_event")
- this.setPreviousStatement(true);
- this.setNextStatement(true);
- }
- }
- Blockly.Blocks['voicekit_assistant_start_conversation'] = {
- init:function() {
- this.setColour(Blockly.Blocks.voicekit.HUE)
- this.appendDummyInput()
- .appendField("self_assistant.start_conversation()")
- this.setPreviousStatement(true);
- this.setNextStatement(true);
- }
- }
- Blockly.Blocks['voicekit_send_instructions'] = {
- init:function() {
- this.setColour(Blockly.Blocks.voicekit.HUE)
- this.appendDummyInput()
- .appendField("send_instructions")
- this.appendValueInput("TEXT")
- .appendField("text")
- .setAlign(Blockly.ALIGN_RIGHT)
- this.setPreviousStatement(true);
- this.setNextStatement(true);
- }
- }
- Blockly.Blocks['voicekit_on_button_pressed'] = {
- init:function() {
- this.setColour(Blockly.Blocks.voicekit.HUE)
- this.appendDummyInput()
- .appendField("on_button_pressed")
- this.setOutput(true)
- }
- }
- /**************************
- * simplify *
- ***************************/
- /**
- * voice kit
- * import EventType / auth_helpers / Assistant
- */
- Blockly.Blocks['voicekit_import_aiy'] = {
- init:function() {
- this.setColour(Blockly.Blocks.voicekit.HUE)
- this.appendDummyInput()
- .appendField("import AIY Voice Moudles")
- this.setPreviousStatement(true);
- this.setNextStatement(true);
- },
- }
- /**
- * voice kit init
- *
- */
- Blockly.Blocks['voicekit_init'] = {
- init:function() {
- this.setColour(Blockly.Blocks.voicekit.HUE)
- this.appendDummyInput()
- .appendField("Voicekit Kit")
- this.appendDummyInput()
- .appendField("Assistant Initialization")
- this.itemCount_ = 1;
- this.updateShape_();
- this.setMutator(new Blockly.Mutator(['voicekit_init_item']));
- this.setPreviousStatement(true);
- this.setNextStatement(true);
- },
- /**
- * Create XML to represent print inputs.
- * @return {Element} XML storage element.
- * @this Blockly.Block
- */
- mutationToDom: function(workspace) {
- var container = document.createElement('mutation');
- container.setAttribute('items', this.itemCount_);
- return container;
- },
- /**
- * Parse XML to restore the list inputs.
- * @param {!Element} xmlElement XML storage element.
- * @this Blockly.Block
- */
- domToMutation: function(xmlElement) {
- this.itemCount_ = parseInt(xmlElement.getAttribute('items'), 10);
- this.updateShape_();
- },
- /**
- * Populate the mutator's dialog with this block's components.
- * @param {!Blockly.Workspace} workspace Mutator's workspace.
- * @return {!Blockly.Block} Root block in mutator.
- * @this Blockly.Block
- */
- decompose: function(workspace) {
- var containerBlock = Blockly.Block.obtain(workspace,
- 'voicekit_init_container');
- containerBlock.initSvg();
- var connection = containerBlock.getInput('STACK').connection;
- for (var x = 0; x < this.itemCount_; x++) {
- var itemBlock = Blockly.Block.obtain(workspace, 'voicekit_init_item');
- itemBlock.initSvg();
- connection.connect(itemBlock.previousConnection);
- connection = itemBlock.nextConnection;
- }
- return containerBlock;
- },
- /**
- * Reconfigure this block based on the mutator dialog's components.
- * @param {!Blockly.Block} containerBlock Root block in mutator.
- * @this Blockly.Block
- */
- compose: function(containerBlock) {
- var itemBlock = containerBlock.getInputTargetBlock('STACK');
- // Count number of inputs.
- var connections = [];
- var i = 0;
- while (itemBlock) {
- connections[i] = itemBlock.valueConnection_;
- itemBlock = itemBlock.nextConnection &&
- itemBlock.nextConnection.targetBlock();
- i++;
- }
- this.itemCount_ = i;
- this.updateShape_();
- // Reconnect any child blocks.
- for (var i = 0; i < this.itemCount_; i++) {
- if (connections[i]) {
- this.getInput('ADD' + i).connection.connect(connections[i]);
- }
- }
- },
- /**
- * Store pointers to any connected child blocks.
- * @param {!Blockly.Block} containerBlock Root block in mutator.
- * @this Blockly.Block
- */
- saveConnections: function(containerBlock) {
- // Store a pointer to any connected child blocks.
- var itemBlock = containerBlock.getInputTargetBlock('STACK');
- var x = 0;
- while (itemBlock) {
- var input = this.getInput('ADD' + x);
- itemBlock.valueConnection_ = input && input.connection.targetConnection;
- x++;
- itemBlock = itemBlock.nextConnection &&
- itemBlock.nextConnection.targetBlock();
- }
- },
- /**
- * Modify this block to have the correct number of inputs.
- * @private
- * @this Blockly.Block
- */
- updateShape_: function() {
- // Delete everything.
- if (this.getInput('EMPTY')) {
- this.removeInput('EMPTY');
- } else {
- var i = 0;
- while (this.getInput('ADD' + i)) {
- this.removeInput('ADD' + i);
- i++;
- }
- }
-
- // Rebuild block.
- for (var i = 0; i < this.itemCount_; i++) {
- var input = this.appendValueInput('ADD' + i);
- }
-
- }
- };
- Blockly.Blocks['voicekit_init_container'] = {
- // Container.
- init: function() {
- this.setColour(Blockly.Blocks.voicekit.HUE);
- this.appendDummyInput()
- .appendField('field');
- this.appendStatementInput('STACK');
- this.contextMenu = false;
- }
- };
- Blockly.Blocks['voicekit_init_item'] = {
- // Add items.
- init: function() {
- this.setColour(Blockly.Blocks.voicekit.HUE);
- this.appendDummyInput()
- .appendField('item');
- this.setInputsInline(true);
- this.setPreviousStatement(true);
- this.setNextStatement(true);
- this.contextMenu = false;
- }
- };
- Blockly.Blocks['voicekit_task'] = {
- init:function() {
- this.setColour(Blockly.Blocks.voicekit.HUE)
- this.appendDummyInput()
- .appendField("Task Tread")
- this.setOutput(true)
- }
- }
- Blockly.Blocks['voicekit_can_start'] = {
- init:function() {
- this.setColour(Blockly.Blocks.voicekit.HUE)
- this.appendDummyInput()
- .appendField("Converstation")
- this.setOutput(true)
- }
- }
- Blockly.Blocks['voicekit_asssistant'] = {
- init:function() {
- this.setColour(Blockly.Blocks.voicekit.HUE)
- this.appendDummyInput()
- .appendField("Assistant")
- this.setOutput(true)
- }
- }
- /**
- * voice kit
- * start thread
- */
- Blockly.Blocks['voicekit_start_thread'] = {
- init: function() {
- this.setColour(Blockly.Blocks.voicekit.HUE)
- this.appendDummyInput()
- .appendField("Start task")
- this.setPreviousStatement(true);
- this.setNextStatement(true);
- }
- }
- /**
- * voice kit
- * run task
- */
- Blockly.Blocks['voicekit_runTask'] = {
- init: function() {
- this.setColour(Blockly.Blocks.voicekit.HUE)
- this.appendDummyInput()
- .appendField("Run task")
- this.setPreviousStatement(true);
- this.setNextStatement(true);
- }
- }
- Blockly.Blocks['voicekit_logging_config'] = {
- init: function() {
- this.setColour(Blockly.Blocks.voicekit.HUE)
- this.appendDummyInput()
- .appendField("logging.basicConfig(level = logging.INFO)")
- this.setPreviousStatement(true);
- this.setNextStatement(true);
- }
- }
- Blockly.Blocks['voicekit_myassistant_start'] = {
- init:function() {
- this.setColour(230)
- this.appendDummyInput()
- .appendField(new Blockly.FieldTextInput("MyAssistant"),"INPUT")
- .appendField(".start()")
- this.setPreviousStatement(true);
- this.setNextStatement(true);
- }
- }
- Blockly.Blocks['voicekit_process_event'] = {
- init: function() {
- this.setColour(Blockly.Blocks.voicekit.HUE)
- this.appendDummyInput()
- .appendField("Process Event")
- this.appendStatementInput("STACK");
- this.setPreviousStatement(true);
- this.setNextStatement(true);
- }
- }
- Blockly.Blocks['voicekit_process_eventType'] = {
- init: function() {
- this.setColour(Blockly.Blocks.voicekit.HUE)
- this.appendDummyInput()
- .appendField("Event.type")
- this.setOutput(true);
- }
- }
- Blockly.Blocks['voicekit_EventType_select'] = {
- init: function() {
- this.setColour(Blockly.Blocks.voicekit.HUE)
- this.appendDummyInput()
- .appendField(Blockly.Msg.VOICEKIT_EVENTTYPE_ASSISTANT)
- this.appendDummyInput()
- .appendField(new Blockly.FieldDropdown([
- ["ON_START_FINISHED","ON_START_FINISHED"],
- ["ON_CONVERSATION_TURN_STARTED","ON_CONVERSATION_TURN_STARTED"],
- ["ON_RECOGNIZING_SPEECH_FINISHED","ON_RECOGNIZING_SPEECH_FINISHED"],
- ["ON_END_OF_UTTERANCE","ON_END_OF_UTTERANCE"],
- ["ON_CONVERSATION_TURN_FINISHED","ON_CONVERSATION_TURN_FINISHED"],
- ["ON_ASSISTANT_ERROR","ON_ASSISTANT_ERROR"],
- ["ON_CONVERSATION_TURN_TIMEOUT","ON_CONVERSATION_TURN_TIMEOUT"],
- ["ON_NO_RESPONSE","ON_NO_RESPONSE"],
- ]),"TYPE")
- this.setOutput(true)
- }
- }
- Blockly.Blocks['voicekit_can_start_conversation_self'] = {
- init: function() {
- this.setColour("#ff6381")
- this.appendDummyInput()
- .appendField("Can start conversation")
- this.setOutput(true);
- }
- }
- Blockly.Blocks['voicekit_can_start_conversation'] = {
- init: function() {
- this.setColour("#ff6381")
- this.appendDummyInput()
- .appendField("Can start conversation =")
- .appendField(new Blockly.FieldDropdown([
- ["True","True"],
- ["False","False"],
- ]),"SETTING")
- this.setPreviousStatement(true);
- this.setNextStatement(true)
- }
- }
- Blockly.Blocks['voicekit_assistant_conversation'] = {
- init: function() {
- this.setColour("#ff6381")
- this.appendDummyInput()
- .appendField("Assistant.")
- .appendField(new Blockly.FieldDropdown([
- ["stop_conversation","stop_conversation()"],
- ["start_conversation","start_conversation()"]
- ]),"SETTING")
- this.setPreviousStatement(true);
- this.setNextStatement(true)
- }
- }
- Blockly.Blocks['voicekit_event_args'] = {
- init:function() {
- this.setColour(Blockly.Blocks.voicekit.HUE);
- this.appendDummyInput()
- .appendField(Blockly.Msg.VOICEKIT_EVENT_ARGS)
- this.setInputsInline(true);
- this.setOutput(true)
- }
- }
- Blockly.Blocks['voicekit_event_args_of'] ={
- init:function() {
- this.setColour(Blockly.Blocks.voicekit.HUE)
- this.appendDummyInput()
- .appendField(Blockly.Msg.VOICEKIT_EVENT_ARGS)
- .appendField(Blockly.Msg.VOICEKIT_EVENT_OF)
- .appendField(new Blockly.FieldTextInput("text"),"TEXT")
- this.setInputsInline(true);
- this.setOutput(true)
- }
- }
|