Skip to content

Commit

Permalink
wesbos#18 and wesbos#20 done
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Gromskiy committed Mar 10, 2017
1 parent 9eb45d2 commit 7635e07
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
13 changes: 13 additions & 0 deletions 18 - Adding Up Times with Reduce/index-START.html
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,19 @@
</li>
</ul>
<script>
const vids = Array.from(document.querySelectorAll('[data-time]'));

let seconds = vids.reduce((total, vid) => {
let [min, sec] = vid.dataset.time.split(':');
return total + (+min * 60 + +sec);
}, 0);

let hours = Math.floor(seconds / 3600);
seconds = seconds % 3600;
let mins = Math.floor(seconds / 60);
seconds = seconds % 60;

console.log(`Total time is: ${hours}:${mins}:${seconds}`);
</script>
</body>
</html>
26 changes: 26 additions & 0 deletions 20 - Speech Detection/index-START.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,33 @@
<script>
window.SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;

const speach = new SpeechRecognition();
speach.interimResults = true;
speach.lang = 'en-US';

let p = document.createElement('p');
const words = document.querySelector('.words');
words.appendChild(p);

speach.addEventListener('result', e => {
const transcript = [... e.results]
.map(result => result[0])
.map(result => result.transcript)
.join();
console.log(transcript);
p.textContent = transcript;

if(e.results[0].isFinal) {
p = document.createElement('p');
words.appendChild(p);
}
});

function putAndRestart(){
speach.start();
}
speach.addEventListener('end', putAndRestart)
speach.start();
</script>


Expand Down

0 comments on commit 7635e07

Please sign in to comment.