viewof scores = {
const form = html`<form>
<style>
button[name=listen] {
background: #2dc244;
color: white;
border: none;
border-radius: 4px;
font-size: 24px;
font-weight: bold;
padding: 8px 20px;
margin-bottom: 8px;
cursor: pointer;
width: 220px;
}
button[name=listen]:hover {
background: #0e9923;
}
button.active[name=listen] {
background: #ff4136;
}
</style>
<button name=listen>Listen</button>
</form>`;
const button = form.listen;
form.value = new Map(d3.permute(words.map(word => [word, 0]), order));
button.onclick = async event => {
event.preventDefault();
if (recognizer.isListening()) {
button.disabled = true;
button.textContent = "Stopping…";
await recognizer.stopListening();
button.classList.remove("active");
button.textContent = "Listen";
button.disabled = false;
return;
}
button.textContent = "Stop";
button.classList.add("active");
recognizer.listen(({scores}) => {
form.value = new Map(d3.permute(Array.from(scores, (s, i) => [words[i], s]), order));
form.dispatchEvent(new CustomEvent("input"));
}, {
probabilityThreshold: 0.75
});
};
invalidation.then(() => {
if (recognizer.isListening()) {
recognizer.stopListening();
}
});
return form;
}