diff --git a/elutil.js b/apptools.js similarity index 100% rename from elutil.js rename to apptools.js diff --git a/blocks.js b/blocks/blocks.js similarity index 98% rename from blocks.js rename to blocks/blocks.js index 3c69ac2..886161d 100644 --- a/blocks.js +++ b/blocks/blocks.js @@ -1075,20 +1075,27 @@ Blockly.JavaScript['ugj_face_draw'] = function (block) { /******************************* */ Blockly.Blocks['oc_speechcommands_init'] = { init: function () { + this.appendDummyInput() + .appendField("音声コマンド認識を開始"); this.appendValueInput("custom_model") .setCheck("String") - .appendField("音声コマンド認識を開始:カスタムモデル") - // .appendField(""); - this.setInputsInline(true); + .setAlign(Blockly.ALIGN_RIGHT) + .appendField("カスタムモデル"); + this.appendDummyInput() + .setAlign(Blockly.ALIGN_RIGHT) + .appendField(new Blockly.FieldVariable("ラベル"), "classlabels") + .appendField("を取得"); + this.setInputsInline(false); this.setPreviousStatement(true, null); this.setNextStatement(true, null); - this.setTooltip("Tensorflow 音声コマンド認識モデルを初期化します。Google Teachable Machine で作成したカスタムモデルのフォルダパスを指定します。(空欄可)"); + this.setTooltip("Tensorflow 音声コマンド認識モデルを初期化します。Google Teachable Machine で作成したカスタムモデルのフォルダパスを指定します。モデルに含まれるラベルのリストを取得し変数に代入します。"); this.setHelpUrl(""); this.setStyle('multimedia_blocks'); } }; Blockly.JavaScript['oc_speechcommands_init'] = function (block) { var value_custom_model = Blockly.JavaScript.valueToCode(block, 'custom_model', Blockly.JavaScript.ORDER_NONE); + var variable_classlabels = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('classlabels'), Blockly.Names.NameType.VARIABLE); Blockly.JavaScript.provideFunction_( 'require_tfjs', [`const _tf = require('@tensorflow/tfjs-node');`] ); @@ -1110,39 +1117,41 @@ const _recognizer = _speechcommands.create( _checkpointURL, _metadataURL); await _recognizer.ensureModelLoaded(); +${variable_classlabels} = _recognizer.wordLabels(); `; return code; }; Blockly.Blocks['oc_speechcommand_listen'] = { init: function () { this.appendDummyInput() - .appendField("音声コマンドの") - .appendField(new Blockly.FieldVariable("ラベル"), "classlabels") + .appendField("音声コマンドを認識したら"); + this.appendDummyInput() + .setAlign(Blockly.ALIGN_RIGHT) .appendField(new Blockly.FieldVariable("スコア"), "scores") - .appendField("を認識したら"); + .appendField("を取得"); this.appendStatementInput("do") .setCheck(null); - this.setInputsInline(true); + this.appendDummyInput() + .setAlign(Blockly.ALIGN_RIGHT) + .appendField("スコアしきい値") + .appendField(new FieldSlider(0.75, 0, 1, 0.05), "probabilityThreshold"); + this.setInputsInline(false); this.setPreviousStatement(true, null); this.setNextStatement(true, null); - this.setTooltip("音声コマンドを認識するとステートメントをします。「ラベル」「スコア」はリストです。"); + this.setTooltip("音声コマンドを認識するとステートメントを実行します。「スコア」は「ラベル」に対応するリストです。"); this.setHelpUrl(""); this.setStyle('multimedia_blocks'); } }; Blockly.JavaScript['oc_speechcommand_listen'] = function (block) { - var variable_classlabels = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('classlabels'), Blockly.Names.NameType.VARIABLE); var variable_scores = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('scores'), Blockly.Names.NameType.VARIABLE); var statements_do = Blockly.JavaScript.statementToCode(block, 'do'); - var code = `${variable_classlabels} = _recognizer.wordLabels(); -_recognizer.listen(_result => { + var number_probabilitythreshold = block.getFieldValue('probabilityThreshold'); + var code = `_recognizer.listen(_result => { ${variable_scores} = _result.scores; ${statements_do} }, { - // includeSpectrogram: true, - // invokeCallbackOnNoiseAndUnknown: true, - // overlapFactor: 0.50, - probabilityThreshold: 0.75 + probabilityThreshold: ${number_probabilitythreshold} }); `; return code; @@ -1155,10 +1164,9 @@ Blockly.Blocks['ugj_canvas_say'] = { init: function () { this.appendValueInput("say") .setCheck(null); - this.appendValueInput("sec") - .setCheck("Number") - .appendField("と"); this.appendDummyInput() + .appendField("と") + .appendField(new FieldSlider(2, 0, 30, 1), "sec") .appendField("秒言う"); this.setInputsInline(true); this.setPreviousStatement(true, null); @@ -1170,7 +1178,7 @@ Blockly.Blocks['ugj_canvas_say'] = { }; Blockly.JavaScript['ugj_canvas_say'] = function (block) { var value_say = Blockly.JavaScript.valueToCode(block, 'say', Blockly.JavaScript.ORDER_ATOMIC); - var value_sec = Blockly.JavaScript.valueToCode(block, 'sec', Blockly.JavaScript.ORDER_ATOMIC); + var value_sec = block.getFieldValue('sec'); var code = [ `_fukidashi(String(${value_say}), ${value_sec});`, '' diff --git a/index.html b/index.html index fdf6d32..ff82623 100644 --- a/index.html +++ b/index.html @@ -4,10 +4,9 @@
- - + - + @@ -663,16 +662,28 @@ +