|
<!DOCTYPE html> |
|
<html> |
|
<head> |
|
<title>Whisper, Vicuna, & TTS Demo</title> |
|
</head> |
|
<body> |
|
<div id="gradio-container"></div> |
|
<script src="/js/index.js"></script> |
|
<script> |
|
window.addEventListener('DOMContentLoaded', (event) => { |
|
let recorder; |
|
let chunks =[]; |
|
let audioComponent; |
|
let recognition; |
|
|
|
window.addEventListener('DOMContentLoaded', (event) => { |
|
audioComponent = document.getElementById("mic_audio"); |
|
|
|
|
|
recognition = new webkitSpeechRecognition() || new SpeechRecognition(); |
|
recognition.continuous = true; |
|
recognition.interimResults = false; |
|
|
|
recognition.onresult = event => { |
|
const transcript = event.results.transcript.toLowerCase(); |
|
console.log("Recognized:", transcript); |
|
|
|
if (transcript.includes("start recording")) { |
|
startRecording(); |
|
} else if (transcript.includes("stop recording")) { |
|
stopRecording(); |
|
} |
|
}; |
|
|
|
recognition.onerror = event => { |
|
console.error("Speech recognition error:", event.error); |
|
}; |
|
|
|
recognition.start(); |
|
|
|
}); |
|
|
|
function startRecording() { |
|
navigator.mediaDevices.getUserMedia({ audio: true }) |
|
.then(stream => { |
|
recorder = new MediaRecorder(stream); |
|
recorder.ondataavailable = e => { |
|
if (e.data.size > 0) { |
|
chunks.push(e.data); |
|
} |
|
}; |
|
recorder.start(); |
|
console.log("Recording started."); |
|
}) |
|
.catch(err => console.error('Error accessing microphone:', err)); |
|
} |
|
|
|
function stopRecording() { |
|
if (recorder && recorder.state === "recording") { |
|
recorder.stop(); |
|
recorder.onstop = async () => { |
|
const blob = new Blob(chunks, { type: 'audio/wav' }); |
|
const file = new File([blob], "recording.wav", { type: 'audio/wav' }); |
|
|
|
const dataTransfer = new DataTransfer(); |
|
dataTransfer.items.add(file); |
|
audioComponent.files = dataTransfer.files; |
|
|
|
audioComponent.dispatchEvent(new Event('change')); |
|
|
|
chunks =; |
|
console.log("Recording stopped and data sent."); |
|
}; |
|
} |
|
} |
|
|
|
}); |
|
|
|
</script> |
|
</body> |
|
</html> |