[update] speech-command ブロックにオーバーラップ係数のパラメータを追加

This commit is contained in:
ocogeclub 2023-01-12 21:59:17 +09:00
parent ef8f659468
commit c9815fbc18
7 changed files with 71 additions and 28 deletions

View File

@ -325,6 +325,15 @@ class appTool {
return this.path.join(this.appDocRoot, filename); return this.path.join(this.appDocRoot, filename);
} }
// Python コードフォーマッタ Black をコール
pyBeautify = (code) => {
let formatted = '';
formatted = require('child_process').spawnSync('python3', ['-m', 'black', '-'], { input: code }).stdout.toString();
if (!formatted) formatted = code;
return formatted;
}
} }
// ブラウザ動作用 // ブラウザ動作用
class webTool { class webTool {
@ -377,6 +386,7 @@ class webTool {
setWsChanged() { ; } setWsChanged() { ; }
killAllChildren() { ; } killAllChildren() { ; }
cleanupGPIO() { ; } cleanupGPIO() { ; }
pyBeautify(code) { return code; }
path = { path = {
join: function (a = '', b = '', c = '', d = '', e = '') { join: function (a = '', b = '', c = '', d = '', e = '') {
const removeTrailingSlash = path => path.endsWith('/') ? path.substr(0, path.length - 1) : path; const removeTrailingSlash = path => path.endsWith('/') ? path.substr(0, path.length - 1) : path;
@ -387,6 +397,7 @@ class webTool {
(e ? '/' + removeTrailingSlash(e) : '') (e ? '/' + removeTrailingSlash(e) : '')
} }
} }
} }
// Electron 動作 / ブラウザ動作自動判別 // Electron 動作 / ブラウザ動作自動判別
@ -437,4 +448,5 @@ if (!is_app) {
} }
throw `ブロック「${block}」は、Web体験版ではご利用になれません。\n詳しくは https://ocoge.club/ をご覧ください。`; throw `ブロック「${block}」は、Web体験版ではご利用になれません。\n詳しくは https://ocoge.club/ をご覧ください。`;
} }
var setscriptlangtopy = () => apptool.lang = 'py';
} }

View File

@ -1131,6 +1131,10 @@ Blockly.Blocks['oc_speechcommand_listen'] = {
.appendField("を取得"); .appendField("を取得");
this.appendStatementInput("do") this.appendStatementInput("do")
.setCheck(null); .setCheck(null);
this.appendDummyInput()
.setAlign(Blockly.ALIGN_RIGHT)
.appendField("オーバーラップ係数")
.appendField(new FieldSlider(0.5, 0, 1, 0.05), "overlapFactor");
this.appendDummyInput() this.appendDummyInput()
.setAlign(Blockly.ALIGN_RIGHT) .setAlign(Blockly.ALIGN_RIGHT)
.appendField("スコアしきい値") .appendField("スコアしきい値")
@ -1147,10 +1151,12 @@ Blockly.JavaScript['oc_speechcommand_listen'] = function (block) {
var variable_scores = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('scores'), 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 statements_do = Blockly.JavaScript.statementToCode(block, 'do');
var number_probabilitythreshold = block.getFieldValue('probabilityThreshold'); var number_probabilitythreshold = block.getFieldValue('probabilityThreshold');
var number_overlapfactor = block.getFieldValue('overlapFactor');
var code = `_recognizer.listen(_result => { var code = `_recognizer.listen(_result => {
${variable_scores} = _result.scores; ${variable_scores} = _result.scores;
${statements_do} ${statements_do}
}, { }, {
overlapFactor: ${number_overlapfactor},
probabilityThreshold: ${number_probabilitythreshold} probabilityThreshold: ${number_probabilitythreshold}
}); });
`; `;
@ -3011,3 +3017,16 @@ Blockly.Python['ugj_controls_foreach'] = function (block) {
// var code = `let _interval = setTimeout(async () => {\n${statements_do}}, ${value_sec}*1000);\n`; // var code = `let _interval = setTimeout(async () => {\n${statements_do}}, ${value_sec}*1000);\n`;
// return code; // return code;
// }; // };
Blockly.defineBlocksWithJsonArray([{
"type": "toggle_lang",
"message0": "MicroPython Mode",
"colour": 0,
"tooltip": "実行すると秘密の MicorPython モードに移行します。JavaScript モードに戻るには、ワークスペースを再読み込みしてください。",
"helpUrl": ""
}]);
Blockly.JavaScript['toggle_lang'] = function (block) {
var code = `apptool.setLang('py');
`;
return code;
};

View File

@ -1,7 +1,20 @@
const current = (function () {
let r = "";
if (document.currentScript) {
r = document.currentScript.src;
} else {
var scripts = document.getElementsByTagName('script'),
script = scripts[scripts.length - 1];
if (script.src) {
r = script.src;
}
}
return r.replace(/[^/]*$/, '')
})();
var flyout_contents = []; var flyout_contents = [];
const registerCategory = (category_dir, subcategories) => { const registerCategory = (category_dir, subcategories) => {
for (let sbctgr of subcategories) { for (let sbctgr of subcategories) {
let fname = ugj_const.blocks_dir + '/' + category_dir + "/" + sbctgr + "/index.js"; let fname = current + category_dir + '/' + sbctgr + "/index.js";
let script = document.createElement('script'); let script = document.createElement('script');
script.type = 'text/javascript'; script.type = 'text/javascript';
script.src = fname; script.src = fname;

View File

@ -688,7 +688,6 @@
</block> --> </block> -->
<block type="oc_speechcommand_listen"> <block type="oc_speechcommand_listen">
<field name="scores" id="|!AWY]V:il;fu;lRwDC*">スコア</field> <field name="scores" id="|!AWY]V:il;fu;lRwDC*">スコア</field>
<field name="probabilityThreshold">0.75</field>
</block> </block>
<label text="_" web-line="4.0" web-line-width="200"></label> <label text="_" web-line="4.0" web-line-width="200"></label>
</category> </category>
@ -969,7 +968,7 @@
</shadow> </shadow>
</value> </value>
</block> </block>
<block type="ugj_dev_run_js"></block> <!-- <block type="ugj_dev_run_js"></block> -->
<label text="_" web-line="4.0" web-line-width="200"></label> <label text="_" web-line="4.0" web-line-width="200"></label>
</category> </category>
<category name="スニペット" css-icon="customIcon fas fa-egg" categorystyle="snippets_category"> <category name="スニペット" css-icon="customIcon fas fa-egg" categorystyle="snippets_category">
@ -1049,9 +1048,9 @@
<script src="./node_modules/@blockly/field-slider/dist/index.js"></script> <script src="./node_modules/@blockly/field-slider/dist/index.js"></script>
<script src="./lib/custom-dialog.js"></script> <script src="./lib/custom-dialog.js"></script>
<script src="./blocks/blocks.js"></script> <script src="./blocks/blocks.js"></script>
<script src="./blocks/index.js"></script>
<script src="./apptool.js"></script> <script src="./apptool.js"></script>
<script src="./index.js"></script> <script src="./index.js"></script>
<script src="./blocks/index.js"></script>
<script src="./node_modules/js-beautify/js/lib/beautify.js"></script> <script src="./node_modules/js-beautify/js/lib/beautify.js"></script>
<script src="./node_modules/prismjs/prism.js"></script> <script src="./node_modules/prismjs/prism.js"></script>
<script src="./node_modules/prismjs/components/prism-python.js"></script> <script src="./node_modules/prismjs/components/prism-python.js"></script>

View File

@ -362,18 +362,18 @@ const ugj_asyncIife = code => {
return code; return code;
} }
// Python コードフォーマッタ Black をコール // // Python コードフォーマッタ Black をコール
const ugj_pyBeautify = (code) => { // const ugj_pyBeautify = (code) => {
let formatted = ''; // let formatted = '';
formatted = require('child_process').spawnSync('python3', ['-m', 'black', '-'], { input: code }).stdout.toString(); // formatted = require('child_process').spawnSync('python3', ['-m', 'black', '-'], { input: code }).stdout.toString();
if (!formatted) formatted = code; // if (!formatted) formatted = code;
return formatted; // return formatted;
} // }
// コードフォーマッティング // コードフォーマッティング
const ugj_formatCode = code => { const ugj_formatCode = code => {
if (apptool.lang == 'py') // フォーマッティング if (apptool.lang == 'py') // フォーマッティング
code = ugj_pyBeautify(code); code = apptool.pyBeautify(code);
else else
code = js_beautify(code, { indent_size: 2 }); code = js_beautify(code, { indent_size: 2 });
return code; return code;

28
package-lock.json generated
View File

@ -21,14 +21,14 @@
"dracula-prism": "^2.1.13", "dracula-prism": "^2.1.13",
"js-beautify": "^1.14.7", "js-beautify": "^1.14.7",
"node-abi": "^3.31.0", "node-abi": "^3.31.0",
"nodemailer": "^6.8.0", "nodemailer": "^6.9.0",
"prismjs": "^1.29.0" "prismjs": "^1.29.0"
}, },
"devDependencies": { "devDependencies": {
"@electron-forge/cli": "^6.0.4", "@electron-forge/cli": "^6.0.4",
"@electron-forge/maker-deb": "^6.0.4", "@electron-forge/maker-deb": "^6.0.4",
"@electron/rebuild": "^3.2.10", "@electron/rebuild": "^3.2.10",
"electron": "^22.0.0" "electron": "^22.0.1"
} }
}, },
"local_modules/pigpio": { "local_modules/pigpio": {
@ -2107,9 +2107,9 @@
"integrity": "sha512-ncTzHV7NvsQZkYe1DW7cbDLm0YpzHmZF5r/iyP3ZnQtMiJ+pjzisCiMNI+Sj+xQF5pXhSHxSB3uDbsBTzY/c2A==" "integrity": "sha512-ncTzHV7NvsQZkYe1DW7cbDLm0YpzHmZF5r/iyP3ZnQtMiJ+pjzisCiMNI+Sj+xQF5pXhSHxSB3uDbsBTzY/c2A=="
}, },
"node_modules/electron": { "node_modules/electron": {
"version": "22.0.0", "version": "22.0.1",
"resolved": "https://registry.npmjs.org/electron/-/electron-22.0.0.tgz", "resolved": "https://registry.npmjs.org/electron/-/electron-22.0.1.tgz",
"integrity": "sha512-cgRc4wjyM+81A0E8UGv1HNJjL1HBI5cWNh/DUIjzYvoUuiEM0SS0hAH/zaFQ18xOz2ced6Yih8SybpOiOYJhdg==", "integrity": "sha512-05X/UmQOtUYwFmytY4/rc+4Iz+LYzHhftRZDkx1GQzyX/BxopStddG8LMcx3SESNk25F2J93oHv1Lzs6QWeCjA==",
"dev": true, "dev": true,
"hasInstallScript": true, "hasInstallScript": true,
"dependencies": { "dependencies": {
@ -4482,9 +4482,9 @@
} }
}, },
"node_modules/nodemailer": { "node_modules/nodemailer": {
"version": "6.8.0", "version": "6.9.0",
"resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.8.0.tgz", "resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.9.0.tgz",
"integrity": "sha512-EjYvSmHzekz6VNkNd12aUqAco+bOkRe3Of5jVhltqKhEsjw/y0PYPJfp83+s9Wzh1dspYAkUW/YNQ350NATbSQ==", "integrity": "sha512-jFaCEGTeT3E/m/5R2MHWiyQH3pSARECRUDM+1hokOYc3lQAAG7ASuy+2jIsYVf+RVa9zePopSQwKNVFH8DKUpA==",
"engines": { "engines": {
"node": ">=6.0.0" "node": ">=6.0.0"
} }
@ -7885,9 +7885,9 @@
} }
}, },
"electron": { "electron": {
"version": "22.0.0", "version": "22.0.1",
"resolved": "https://registry.npmjs.org/electron/-/electron-22.0.0.tgz", "resolved": "https://registry.npmjs.org/electron/-/electron-22.0.1.tgz",
"integrity": "sha512-cgRc4wjyM+81A0E8UGv1HNJjL1HBI5cWNh/DUIjzYvoUuiEM0SS0hAH/zaFQ18xOz2ced6Yih8SybpOiOYJhdg==", "integrity": "sha512-05X/UmQOtUYwFmytY4/rc+4Iz+LYzHhftRZDkx1GQzyX/BxopStddG8LMcx3SESNk25F2J93oHv1Lzs6QWeCjA==",
"dev": true, "dev": true,
"requires": { "requires": {
"@electron/get": "^2.0.0", "@electron/get": "^2.0.0",
@ -9678,9 +9678,9 @@
"dev": true "dev": true
}, },
"nodemailer": { "nodemailer": {
"version": "6.8.0", "version": "6.9.0",
"resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.8.0.tgz", "resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.9.0.tgz",
"integrity": "sha512-EjYvSmHzekz6VNkNd12aUqAco+bOkRe3Of5jVhltqKhEsjw/y0PYPJfp83+s9Wzh1dspYAkUW/YNQ350NATbSQ==" "integrity": "sha512-jFaCEGTeT3E/m/5R2MHWiyQH3pSARECRUDM+1hokOYc3lQAAG7ASuy+2jIsYVf+RVa9zePopSQwKNVFH8DKUpA=="
}, },
"nopt": { "nopt": {
"version": "5.0.0", "version": "5.0.0",

View File

@ -25,7 +25,7 @@
"@electron-forge/cli": "^6.0.4", "@electron-forge/cli": "^6.0.4",
"@electron-forge/maker-deb": "^6.0.4", "@electron-forge/maker-deb": "^6.0.4",
"@electron/rebuild": "^3.2.10", "@electron/rebuild": "^3.2.10",
"electron": "^22.0.0" "electron": "^22.0.1"
}, },
"dependencies": { "dependencies": {
"@blockly/field-slider": "^4.0.4", "@blockly/field-slider": "^4.0.4",
@ -40,7 +40,7 @@
"dracula-prism": "^2.1.13", "dracula-prism": "^2.1.13",
"js-beautify": "^1.14.7", "js-beautify": "^1.14.7",
"node-abi": "^3.31.0", "node-abi": "^3.31.0",
"nodemailer": "^6.8.0", "nodemailer": "^6.9.0",
"prismjs": "^1.29.0" "prismjs": "^1.29.0"
}, },
"config": { "config": {