Changed around line 1
+ let mediaRecorder;
+ let audioChunks = [];
+ let isRecording = false;
+
+ const recordButton = document.getElementById('recordButton');
+ const audioPlayback = document.getElementById('audioPlayback');
+ const transcription = document.getElementById('transcription');
+ const summary = document.getElementById('summary');
+ const resultsSection = document.querySelector('.results');
+
+ recordButton.addEventListener('click', async () => {
+ if (!isRecording) {
+ try {
+ const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
+ mediaRecorder = new MediaRecorder(stream);
+
+ mediaRecorder.ondataavailable = event => {
+ audioChunks.push(event.data);
+ };
+
+ mediaRecorder.onstop = async () => {
+ const audioBlob = new Blob(audioChunks, { type: 'audio/wav' });
+ audioPlayback.src = URL.createObjectURL(audioBlob);
+ audioPlayback.hidden = false;
+
+ const audioData = await blobToBase64(audioBlob);
+ processAudio(audioData);
+ };
+
+ mediaRecorder.start();
+ isRecording = true;
+ recordButton.textContent = '⏹ Stop';
+ } catch (error) {
+ alert('Error accessing microphone');
+ }
+ } else {
+ mediaRecorder.stop();
+ isRecording = false;
+ recordButton.textContent = '🎤 Record';
+ }
+ });
+
+ async function processAudio(audioData) {
+ try {
+ // Initialize transformers.js
+ const { pipeline } = await import('./transformers.js');
+ const transcriber = await pipeline('automatic-speech-recognition', 'openai/whisper-tiny');
+
+ // Transcribe audio
+ const transcriptionResult = await transcriber(audioData);
+ transcription.textContent = transcriptionResult.text;
+
+ // Summarize text
+ const summarizer = await pipeline('summarization', 'facebook/bart-large-cnn');
+ const summaryResult = await summarizer(transcriptionResult.text);
+ summary.textContent = summaryResult[0].summary_text;
+
+ resultsSection.hidden = false;
+ } catch (error) {
+ console.error('Error processing audio:', error);
+ alert('Error processing audio');
+ }
+ }
+
+ function blobToBase64(blob) {
+ return new Promise((resolve, reject) => {
+ const reader = new FileReader();
+ reader.onloadend = () => resolve(reader.result.split(',')[1]);
+ reader.onerror = reject;
+ reader.readAsDataURL(blob);
+ });
+ }