Permalink
Browse files

web speech api

  • Loading branch information...
stoyan committed Mar 13, 2018
1 parent 0a1d589 commit d614f8f162404a412fc812e53a7f9ad67adfc719
Showing with 22 additions and 2 deletions.
  1. +22 −2 src/App.js
@@ -33,6 +33,16 @@ const dictionary = {


const iOS = !!navigator.platform && /iPad|iPhone|iPod/.test(navigator.platform);
let webvoices = null;
if (
'SpeechSynthesisUtterance' in window &&
'speechSynthesis' in window &&
'onvoiceschanged' in speechSynthesis
) {
speechSynthesis.onvoiceschanged = () => {
webvoices = speechSynthesis.getVoices().filter(v => v.lang === 'it-IT' && v.localService);
}
}

let term;

@@ -74,7 +84,10 @@ function getAnswer(i) {
);
}

function getAudio() {
function getAudio() {
if (webvoices){
return [];
}
const word = justLetters(term[0]);
return [
new Audio(`italiano/voices/Alice/${word}.mp3`),
@@ -143,7 +156,14 @@ class App extends Component {
say() {
this.pause();
this.setState({pause: false});
this.state.audio[Math.floor(Math.random() * this.state.audio.length)].play();
if (webvoices) {
const u = new SpeechSynthesisUtterance(term[0]);
u.voice = webvoices[Math.floor(Math.random() * webvoices.length)];
speechSynthesis.speak(u);
} else {
this.state.audio[Math.floor(Math.random() * this.state.audio.length)].play();
}

}

toggleSettings() {

0 comments on commit d614f8f

Please sign in to comment.