音声入力するUserScript
code:script.js
(() => {
if (!webkitSpeechRecognition) return
const isMobile = () => /mobile/i.test(navigator.userAgent)
const writeText = (text) => {
console.log('writeText', text);
const textarea = document.getElementById("text-input");
const reactKey = Object.keys(textarea).find((key) => key.startsWith("__reactFiber"));
textareareactKey.return.return.stateNode._stores.find((store) => store.constructor.name === "Cursor").focus();
document.execCommand('insertText', null, text);
}
const recognition = new webkitSpeechRecognition()
if (!isMobile()) recognition.continuous = true
recognition.onresult = (e) => {
const result = e.resultse.results.length - 1;
const item = result0;
writeText(item.transcript + '\n');
}
let enable = false
scrapbox.PageMenu.addMenu({
title: 'speech input',
image: 'https://gyazo.com/6bf5e32e41ac980fa35334d9030ff962/thumb/48',
onClick: () => {
recognition.start();
// stopはブラウザからやる
//if (!isMobile()) enable = !enable;
}
});
})();
参考
/shokai/音声入力Menu