Download client.html from jibay/test: direct link, hf CLI and curl.
- Browser
- Download file 2.03 kB
-
https://huggingface.co/spaces/jibay/test/resolve/main/client.html
- Command line
-
hf download hf://spaces/jibay/test/client.html
-
curl -L -o client.html https://huggingface.co/spaces/jibay/test/resolve/main/client.html
2.03 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8" /> | |
| <title>Record and Stream Audio</title> | |
| </head> | |
| <body> | |
| <button id="recordButton">Start Record</button> | |
| <button id="stopButton" disabled>Stop Record</button> | |
| <script> | |
| let stream, socket, audioContext, source, processor; | |
| const recordButton = document.querySelector('#recordButton'); | |
| recordButton.addEventListener('click', () => { | |
| navigator.mediaDevices.getUserMedia({ audio: true }) | |
| .then(stream => { | |
| socket = new WebSocket("ws://localhost:8115/audio-stream"); | |
| socket.addEventListener('open', event => { | |
| console.log('WebSocket connection established'); | |
| recordButton.disabled = true; | |
| stopButton.disabled = false; | |
| }); | |
| socket.addEventListener('close', event => { | |
| console.log('WebSocket connection closed'); | |
| recordButton.disabled = false; | |
| stopButton.disabled = true; | |
| }); | |
| audioContext = new AudioContext(); | |
| source = audioContext.createMediaStreamSource(stream); | |
| processor = audioContext.createScriptProcessor(4096, 1, 1); | |
| source.connect(processor); | |
| processor.connect(audioContext.destination); | |
| processor.onaudioprocess = function(event) { | |
| const data = event.inputBuffer.getChannelData(0); | |
| socket.send(data); | |
| }; | |
| // Stop recording when "Stop Record" button is clicked | |
| const stopButton = document.querySelector('#stopButton'); | |
| stopButton.addEventListener('click', () => { | |
| socket.close(); | |
| stream.getTracks().forEach(track => { | |
| track.stop(); | |
| }); | |
| audioContext.close(); | |
| }); | |
| }) | |
| .catch(error => { | |
| console.log('Failed to get user media:', error); | |
| }); | |
| }); | |
| </script> | |
| </body> | |
| </html> | |