Skip to content

Instantly share code, notes, and snippets.

@yskszk63
Created February 7, 2018 14:38
Show Gist options
  • Save yskszk63/414e87c0d143c4dd45b2cdfa8ed28090 to your computer and use it in GitHub Desktop.
Save yskszk63/414e87c0d143c4dd45b2cdfa8ed28090 to your computer and use it in GitHub Desktop.
I can speak.
<form>
<input type="text" class="content" value="" autofocus placeholder="Input text for speak. And enter key press."/>
</form>
const $form = document.querySelector('form');
const $text = document.querySelector('.content');
$form.addEventListener('submit', event => {
event.preventDefault();
const text = $text.value;
if (!text) {
return;
}
const uttar = new SpeechSynthesisUtterance($text.value);
$text.value = '';
uttar.addEventListener('end', () => {
console.log("END");
window.speaking = null;
});
speechSynthesis.speak(uttar);
});
input {
font-size: 32px;
width: 100%;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment