mirror of
https://github.com/ocogeclub/ocoge.git
synced 2024-11-21 15:19:48 +00:00
[update] speech-command ブロックにオーバーラップ係数のパラメータを追加
This commit is contained in:
parent
ef8f659468
commit
c9815fbc18
12
apptool.js
12
apptool.js
@ -325,6 +325,15 @@ class appTool {
|
||||
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 {
|
||||
@ -377,6 +386,7 @@ class webTool {
|
||||
setWsChanged() { ; }
|
||||
killAllChildren() { ; }
|
||||
cleanupGPIO() { ; }
|
||||
pyBeautify(code) { return code; }
|
||||
path = {
|
||||
join: function (a = '', b = '', c = '', d = '', e = '') {
|
||||
const removeTrailingSlash = path => path.endsWith('/') ? path.substr(0, path.length - 1) : path;
|
||||
@ -387,6 +397,7 @@ class webTool {
|
||||
(e ? '/' + removeTrailingSlash(e) : '')
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Electron 動作 / ブラウザ動作自動判別
|
||||
@ -437,4 +448,5 @@ if (!is_app) {
|
||||
}
|
||||
throw `ブロック「${block}」は、Web体験版ではご利用になれません。\n詳しくは https://ocoge.club/ をご覧ください。`;
|
||||
}
|
||||
var setscriptlangtopy = () => apptool.lang = 'py';
|
||||
}
|
||||
|
@ -1131,6 +1131,10 @@ Blockly.Blocks['oc_speechcommand_listen'] = {
|
||||
.appendField("を取得");
|
||||
this.appendStatementInput("do")
|
||||
.setCheck(null);
|
||||
this.appendDummyInput()
|
||||
.setAlign(Blockly.ALIGN_RIGHT)
|
||||
.appendField("オーバーラップ係数")
|
||||
.appendField(new FieldSlider(0.5, 0, 1, 0.05), "overlapFactor");
|
||||
this.appendDummyInput()
|
||||
.setAlign(Blockly.ALIGN_RIGHT)
|
||||
.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 statements_do = Blockly.JavaScript.statementToCode(block, 'do');
|
||||
var number_probabilitythreshold = block.getFieldValue('probabilityThreshold');
|
||||
var number_overlapfactor = block.getFieldValue('overlapFactor');
|
||||
var code = `_recognizer.listen(_result => {
|
||||
${variable_scores} = _result.scores;
|
||||
${statements_do}
|
||||
}, {
|
||||
overlapFactor: ${number_overlapfactor},
|
||||
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`;
|
||||
// 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;
|
||||
};
|
||||
|
@ -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 = [];
|
||||
const registerCategory = (category_dir, 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');
|
||||
script.type = 'text/javascript';
|
||||
script.src = fname;
|
||||
|
@ -688,7 +688,6 @@
|
||||
</block> -->
|
||||
<block type="oc_speechcommand_listen">
|
||||
<field name="scores" id="|!AWY]V:il;fu;lRwDC*">スコア</field>
|
||||
<field name="probabilityThreshold">0.75</field>
|
||||
</block>
|
||||
<label text="_" web-line="4.0" web-line-width="200"></label>
|
||||
</category>
|
||||
@ -969,7 +968,7 @@
|
||||
</shadow>
|
||||
</value>
|
||||
</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>
|
||||
</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="./lib/custom-dialog.js"></script>
|
||||
<script src="./blocks/blocks.js"></script>
|
||||
<script src="./blocks/index.js"></script>
|
||||
<script src="./apptool.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/prismjs/prism.js"></script>
|
||||
<script src="./node_modules/prismjs/components/prism-python.js"></script>
|
||||
|
16
index.js
16
index.js
@ -362,18 +362,18 @@ const ugj_asyncIife = code => {
|
||||
return code;
|
||||
}
|
||||
|
||||
// Python コードフォーマッタ Black をコール
|
||||
const ugj_pyBeautify = (code) => {
|
||||
let formatted = '';
|
||||
formatted = require('child_process').spawnSync('python3', ['-m', 'black', '-'], { input: code }).stdout.toString();
|
||||
if (!formatted) formatted = code;
|
||||
return formatted;
|
||||
}
|
||||
// // Python コードフォーマッタ Black をコール
|
||||
// const ugj_pyBeautify = (code) => {
|
||||
// let formatted = '';
|
||||
// formatted = require('child_process').spawnSync('python3', ['-m', 'black', '-'], { input: code }).stdout.toString();
|
||||
// if (!formatted) formatted = code;
|
||||
// return formatted;
|
||||
// }
|
||||
|
||||
// コードフォーマッティング
|
||||
const ugj_formatCode = code => {
|
||||
if (apptool.lang == 'py') // フォーマッティング
|
||||
code = ugj_pyBeautify(code);
|
||||
code = apptool.pyBeautify(code);
|
||||
else
|
||||
code = js_beautify(code, { indent_size: 2 });
|
||||
return code;
|
||||
|
28
package-lock.json
generated
28
package-lock.json
generated
@ -21,14 +21,14 @@
|
||||
"dracula-prism": "^2.1.13",
|
||||
"js-beautify": "^1.14.7",
|
||||
"node-abi": "^3.31.0",
|
||||
"nodemailer": "^6.8.0",
|
||||
"nodemailer": "^6.9.0",
|
||||
"prismjs": "^1.29.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@electron-forge/cli": "^6.0.4",
|
||||
"@electron-forge/maker-deb": "^6.0.4",
|
||||
"@electron/rebuild": "^3.2.10",
|
||||
"electron": "^22.0.0"
|
||||
"electron": "^22.0.1"
|
||||
}
|
||||
},
|
||||
"local_modules/pigpio": {
|
||||
@ -2107,9 +2107,9 @@
|
||||
"integrity": "sha512-ncTzHV7NvsQZkYe1DW7cbDLm0YpzHmZF5r/iyP3ZnQtMiJ+pjzisCiMNI+Sj+xQF5pXhSHxSB3uDbsBTzY/c2A=="
|
||||
},
|
||||
"node_modules/electron": {
|
||||
"version": "22.0.0",
|
||||
"resolved": "https://registry.npmjs.org/electron/-/electron-22.0.0.tgz",
|
||||
"integrity": "sha512-cgRc4wjyM+81A0E8UGv1HNJjL1HBI5cWNh/DUIjzYvoUuiEM0SS0hAH/zaFQ18xOz2ced6Yih8SybpOiOYJhdg==",
|
||||
"version": "22.0.1",
|
||||
"resolved": "https://registry.npmjs.org/electron/-/electron-22.0.1.tgz",
|
||||
"integrity": "sha512-05X/UmQOtUYwFmytY4/rc+4Iz+LYzHhftRZDkx1GQzyX/BxopStddG8LMcx3SESNk25F2J93oHv1Lzs6QWeCjA==",
|
||||
"dev": true,
|
||||
"hasInstallScript": true,
|
||||
"dependencies": {
|
||||
@ -4482,9 +4482,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/nodemailer": {
|
||||
"version": "6.8.0",
|
||||
"resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.8.0.tgz",
|
||||
"integrity": "sha512-EjYvSmHzekz6VNkNd12aUqAco+bOkRe3Of5jVhltqKhEsjw/y0PYPJfp83+s9Wzh1dspYAkUW/YNQ350NATbSQ==",
|
||||
"version": "6.9.0",
|
||||
"resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.9.0.tgz",
|
||||
"integrity": "sha512-jFaCEGTeT3E/m/5R2MHWiyQH3pSARECRUDM+1hokOYc3lQAAG7ASuy+2jIsYVf+RVa9zePopSQwKNVFH8DKUpA==",
|
||||
"engines": {
|
||||
"node": ">=6.0.0"
|
||||
}
|
||||
@ -7885,9 +7885,9 @@
|
||||
}
|
||||
},
|
||||
"electron": {
|
||||
"version": "22.0.0",
|
||||
"resolved": "https://registry.npmjs.org/electron/-/electron-22.0.0.tgz",
|
||||
"integrity": "sha512-cgRc4wjyM+81A0E8UGv1HNJjL1HBI5cWNh/DUIjzYvoUuiEM0SS0hAH/zaFQ18xOz2ced6Yih8SybpOiOYJhdg==",
|
||||
"version": "22.0.1",
|
||||
"resolved": "https://registry.npmjs.org/electron/-/electron-22.0.1.tgz",
|
||||
"integrity": "sha512-05X/UmQOtUYwFmytY4/rc+4Iz+LYzHhftRZDkx1GQzyX/BxopStddG8LMcx3SESNk25F2J93oHv1Lzs6QWeCjA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@electron/get": "^2.0.0",
|
||||
@ -9678,9 +9678,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"nodemailer": {
|
||||
"version": "6.8.0",
|
||||
"resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.8.0.tgz",
|
||||
"integrity": "sha512-EjYvSmHzekz6VNkNd12aUqAco+bOkRe3Of5jVhltqKhEsjw/y0PYPJfp83+s9Wzh1dspYAkUW/YNQ350NATbSQ=="
|
||||
"version": "6.9.0",
|
||||
"resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.9.0.tgz",
|
||||
"integrity": "sha512-jFaCEGTeT3E/m/5R2MHWiyQH3pSARECRUDM+1hokOYc3lQAAG7ASuy+2jIsYVf+RVa9zePopSQwKNVFH8DKUpA=="
|
||||
},
|
||||
"nopt": {
|
||||
"version": "5.0.0",
|
||||
|
@ -25,7 +25,7 @@
|
||||
"@electron-forge/cli": "^6.0.4",
|
||||
"@electron-forge/maker-deb": "^6.0.4",
|
||||
"@electron/rebuild": "^3.2.10",
|
||||
"electron": "^22.0.0"
|
||||
"electron": "^22.0.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@blockly/field-slider": "^4.0.4",
|
||||
@ -40,7 +40,7 @@
|
||||
"dracula-prism": "^2.1.13",
|
||||
"js-beautify": "^1.14.7",
|
||||
"node-abi": "^3.31.0",
|
||||
"nodemailer": "^6.8.0",
|
||||
"nodemailer": "^6.9.0",
|
||||
"prismjs": "^1.29.0"
|
||||
},
|
||||
"config": {
|
||||
|
Loading…
Reference in New Issue
Block a user