From 9553ab707ad5a8ed6e4179454904d6fec1032ea2 Mon Sep 17 00:00:00 2001 From: Deep Koluguri Date: Thu, 14 May 2026 23:56:48 -0400 Subject: [PATCH] feat: connect AI Scribe to real-time Web Speech API (v5) --- dashboard.js | 54 +++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 41 insertions(+), 13 deletions(-) diff --git a/dashboard.js b/dashboard.js index 710e567..8ee8ecb 100644 --- a/dashboard.js +++ b/dashboard.js @@ -131,40 +131,68 @@ if (startRecordBtn) { }; } -// 6. AI Scribe, Summarization & Context Switching Logic +// 6. AI Scribe & Speech Recognition Logic let isScribing = false; let currentPatientId = "#012"; +let recognition; const patientDataStore = { "#012": { notes: "", summary: "" }, "#013": { notes: "", summary: "" }, "#014": { notes: "", summary: "" } }; +if ('webkitSpeechRecognition' in window) { + recognition = new webkitSpeechRecognition(); + recognition.continuous = true; + recognition.interimResults = true; + + recognition.onresult = (event) => { + let interimTranscript = ''; + for (let i = event.resultIndex; i < event.results.length; ++i) { + if (event.results[i].isFinal) { + document.getElementById("consultationNotes").value += event.results[i][0].transcript + '. '; + } + } + }; + + recognition.onerror = (e) => { + console.error("Speech Recognition Error:", e); + isScribing = false; + updateScribeUI(); + }; +} + window.toggleZenScribe = () => { + if (!recognition) { + alert("Speech Recognition not supported in this browser. Please use Chrome or Edge."); + return; + } + + isScribing = !isScribing; + updateScribeUI(); + + if (isScribing) { + recognition.start(); + } else { + recognition.stop(); + generateSummary(); + } +}; + +function updateScribeUI() { const btn = document.getElementById("zenScribeBtn"); const status = document.getElementById("scribeStatus"); - const notesArea = document.getElementById("consultationNotes"); - - isScribing = !isScribing; if (isScribing) { btn.innerText = "🛑 Stop AI Scribe"; btn.style.background = "#EF4444"; status.classList.remove("hidden"); - - // Simulate AI capturing notes - setTimeout(() => { - if (isScribing) { - notesArea.value += "Patient reports symptoms of fatigue and persistent dry cough for 3 days. No fever recorded today. \n"; - } - }, 3000); } else { btn.innerText = "🎙️ Start AI Scribe"; btn.style.background = ""; status.classList.add("hidden"); - generateSummary(); } -}; +} function generateSummary() { const notes = document.getElementById("consultationNotes").value;