This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function formatCurrency(valor) { | |
const valorCagado = valor.replaceAll('.', '').replaceAll(',', '').replaceAll(/\D/g, '') | |
const valueWithoutZeros = parseFloat(valorCagado).toString() | |
arrValorCagado = valueWithoutZeros.split('') | |
arrValorCagado.splice(arrValorCagado.length - 2, 0, '.') | |
return Number(arrValorCagado.join('')).toLocaleString('pt-BR', { style: 'currency', currency: 'BRL' }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
onstart() { | |
this.isRecording = true; | |
this.transcription = ''; | |
this.transcriptionElement.innerText = ''; | |
this.btnTranscription.innerHTML = 'Gravando'; | |
this.btnTranscription.classList.add('recording'); | |
} | |
onend() { | |
this.isRecording = false; | |
this.btnTranscription.classList.remove('recording'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
init() { | |
this.audioRecordApi.start(); | |
this.audioRecordApi.continuos = true; | |
this.audioRecordApi.interimResults = true; | |
this.audioRecordApi.lang = 'pt-BR'; | |
this.audioRecordApi.onstart = this.onstart.bind(this); | |
this.audioRecordApi.onend = this.onend.bind(this); | |
this.audioRecordApi.onresult = this.onresult.bind(this); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
render() { | |
this.btnTranscription.addEventListener('click', () => { | |
this.isRecording ? this.audioRecordApi.stop() : this.init(); | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// É bom lembrar que em um ambiente real de desenvolvimento, | |
// essa classe deverá ser abstraida ainda mais. Mas para fins de didatica, deixaremos tudo em apenas uma ;) | |
class SpeechTranscription { | |
constructor() { | |
this.btnTranscription = document.getElementById('button-record'); | |
this.transcriptionElement = document.getElementById('transcription'); | |
this.transcription = ''; | |
this.isRecording = false; | |
this.audioRecordApi = new SpeechApi(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SpeechApi from './SpeechApi'; | |
window.addEventListener('DOMContentLoaded', () => { | |
if (SpeechApi) { | |
const speechRecognition = new SpeechTranscription(); | |
speechRecognition.render(); | |
return; | |
} | |
document.getElementById('main').innerHTML = 'API não esta disponível'; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const SpeechRecognition = | |
window.SpeechRecognition || window.webkitSpeechRecognition; | |
export default SpeechRecognition; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>WebSpeech API - Javascript </title> | |
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons"> | |
</head> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let init = (function () { | |
let div = document.querySelector('h1'); | |
let texto = 'Quero meu texto escrito bem devagar!'; | |
const renderText = (str, elemento) => { | |
div.innerText = ''; | |
let char = str.split('').reverse(); | |
let typer = setInterval(() => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<body> | |
<p> JavaScript - Two-way data binding</p> | |
<input type="text" id="myInput" oninput="twoWay()"> | |
<p id="demo"></p> | |
<p id="resultado"></p> |