Changed around line 1
+ // Camera functionality
+ const video = document.getElementById('camera-feed');
+ const startCameraBtn = document.getElementById('start-camera');
+
+ startCameraBtn.addEventListener('click', async () => {
+ try {
+ const stream = await navigator.mediaDevices.getUserMedia({ video: true });
+ video.srcObject = stream;
+ video.style.display = 'block';
+ startCameraBtn.style.display = 'none';
+ } catch (error) {
+ alert('无法访问摄像头,请确保已授予权限');
+ }
+ });
+
+ // Document upload functionality
+ const documentUpload = document.getElementById('document-upload');
+ const documentViewer = document.getElementById('document-viewer');
+
+ documentUpload.addEventListener('change', (event) => {
+ const file = event.target.files[0];
+ if (file) {
+ const fileURL = URL.createObjectURL(file);
+ documentViewer.src = fileURL;
+ documentViewer.classList.remove('hidden');
+ }
+ });
+
+ // Voice functionality
+ const startVoiceBtn = document.getElementById('start-voice');
+ const stopVoiceBtn = document.getElementById('stop-voice');
+ let recognition;
+
+ if ('webkitSpeechRecognition' in window) {
+ recognition = new webkitSpeechRecognition();
+ recognition.continuous = true;
+ recognition.interimResults = true;
+ recognition.lang = 'zh-CN';
+
+ recognition.onstart = () => {
+ startVoiceBtn.classList.add('hidden');
+ stopVoiceBtn.classList.remove('hidden');
+ };
+
+ recognition.onend = () => {
+ startVoiceBtn.classList.remove('hidden');
+ stopVoiceBtn.classList.add('hidden');
+ };
+
+ recognition.onresult = (event) => {
+ // Handle voice commands here
+ console.log(event.results);
+ };
+
+ startVoiceBtn.addEventListener('click', () => {
+ recognition.start();
+ });
+
+ stopVoiceBtn.addEventListener('click', () => {
+ recognition.stop();
+ });
+ } else {
+ startVoiceBtn.disabled = true;
+ startVoiceBtn.textContent = '语音识别不可用';
+ }