UNPKG

@comsultia/speech2text

Version:

Google Speech to Text plugin using websockets to communicate with backend

65 lines (61 loc) 2.05 kB
<!DOCTYPE html> <html> <head> <title>WebSocket Google Speech To Text</title> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <meta name="robots" content="index,follow" /> <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" /> <link href="./public/css/styles.css" media="all" rel="stylesheet" type="text/css" /> <script src="./public/js/complete-min.js"></script> </head> <body> <main> <h1>WebSocket Google Speech To Text</h1> <div class="recorder"> <div class="recorder-buttons"> <button id="btn-start-recording" class="btn-start-recording">Start</button> <button id="btn-stop-recording" class="btn-stop-recording" disabled>Stop</button> </div> <div id="result-wrapper" class="result-wrapper"> <div class="loading-holder"></div> <h2>Result:</h2> <div id="result" class="result"></div> </div> </div> </main> <script> let loadingHolder = document.querySelector('.loading-holder'); // init speech-to-text-websocket plugin speech2text.init({ debug: true, url: 'wss://xx.dev.domain.sk:{PORT}/nodejs/', elementStart: '#btn-start-recording', elementStop: '#btn-stop-recording', elementResult: '#result', defaultTimeout: 3000, onConnecting: function() { console.log('waiting for websocket connection....'); }, onConnection: function() { console.log('websocket connected....'); }, onNotSupported: function() { console.log('web audio not supported'); }, onStart: function() { loadingHolder.classList.add('speech-loading'); }, onBlock: function() { console.log('microphone blocked'); }, onError: function() { console.log('websocket connection error'); }, onEnd: function() { loadingHolder.classList.remove('speech-loading'); } }); </script> </body> </html>