← Torna al blog

Dev Tips

Un trucchetto al giorno leva le complicazioni di torno! Piccole "scorciatoie" che possono facilitare la vita degli sviluppatori e far risparmiare tempo...e righe di codice.

85

How to detect when speech through the device's microphone

2021-05-21

1// JS Tip of the Day
2// How to detect when speech through the device's microphone
3
4window.SpeechRecognition = window.webkitSpeechRecognition || window.SpeechRecognition;
5
6const recognition = new window.SpeechRecognition();
7recognition.continuous = true;
8
9recognition.onresult = (event) => {
10	const speechToText = event.results[event.resultIndex][0].transcript;
11    console.log(speechToText.trim());
12}
13
14recognition.onerror = (event) => {
15    // ...
16    if (event.error == 'not-allowed') {
17      console.log('fine');
18    }
19} 
20
21recognition.start();
84

Get voice/speech from text with Web Speech API

2021-05-20

1// JS Tip of the Day
2// Get voice/speech from text with Web Speech API
3
4if('speechSynthesis' in window){
5     const heroSpeech = new SpeechSynthesisUtterance('I\'m Batman!');
6     heroSpeech.lang = 'en-US';
7     window.speechSynthesis.speak(heroSpeech);
8 }
9
83

A simple way to misure fetching time with console.time

2021-05-19

1// JS Tip of the Day
2// A simple way to misure fetching time with console.time
3
4console.time('time2hero');
5fetch('https://myheroesapi.com/hero/1')
6.then(response => response.json())
7.then(json => {
8  console.timeEnd('time2hero') // time2hero: 83.51611328125 ms
9});
82

How to check if all array values is truthy

2021-05-18

1// JS Tip of the Day
2// How to check if all array values is truthy
3
4const arr = [1, '2', 'Batman', true, {}, null, undefined, "", ' '];
5console.log(arr.every(v => v)); // false
6
7const anotherArr = [1, '2', 'Batman'];
8console.log(anotherArr.every(v => v)); // true
9
81

Named parameters using objects

2021-05-17

1// JS Tip of the Day
2// Named parameters using objects
3
4whoIsMyHero =  ({ name, weapon = 'Batarang', enemy }) => {
5  console.log(`I'm ${name} and my ${weapon} hits ${enemy}`);
6}
7
8whoIsMyHero({ enemy: 'Joker', name: 'Batman'});
9// I'm Batman and my Batarang hits Joker

Contattaci.

Hai in mente un progetto e vorresti realizzarlo?
Sei interessato a migliorare le competenze del tuo team in ambito di programmazione e sviluppo?
Oppure vuoi semplicemente prendere prendere un caffè con noi e vedere la nostra collezione di Action Figure, allora scrivici tramite questo form.

Se, invece, vuoi far parte del team, guarda le nostre offerte di lavoro.

Questo sito è protetto da reCAPTCHA e si applicano le Norme sulla privacy e i Termini di servizio di Google.