Changed around line 1
+ const chatBox = document.getElementById('chat-box');
+ const userInput = document.getElementById('user-input');
+ const voiceBtn = document.getElementById('voice-btn');
+ const sendBtn = document.getElementById('send-btn');
+
+ let recognition;
+
+ function addMessage(content, isUser = false) {
+ const messageDiv = document.createElement('div');
+ messageDiv.classList.add('message', isUser ? 'user-message' : 'ai-message');
+ messageDiv.textContent = content;
+ chatBox.appendChild(messageDiv);
+ chatBox.scrollTop = chatBox.scrollHeight;
+ }
+
+ function sendMessage() {
+ const message = userInput.value.trim();
+ if (message) {
+ addMessage(message, true);
+ userInput.value = '';
+ // Here you would typically send the message to the DeepSeek API
+ // and handle the response
+ setTimeout(() => {
+ addMessage('这是一个示例回复。实际应用中,这里会显示DeepSeek的回复。');
+ }, 1000);
+ }
+ }
+
+ function startVoiceRecognition() {
+ if (!('webkitSpeechRecognition' in window)) {
+ alert('您的浏览器不支持语音识别功能');
+ return;
+ }
+
+ recognition = new webkitSpeechRecognition();
+ recognition.lang = 'zh-CN';
+ recognition.continuous = false;
+ recognition.interimResults = false;
+
+ recognition.onresult = function(event) {
+ const transcript = event.results[0][0].transcript;
+ userInput.value = transcript;
+ sendMessage();
+ };
+
+ recognition.onerror = function(event) {
+ console.error('语音识别错误:', event.error);
+ };
+
+ recognition.start();
+ }
+
+ sendBtn.addEventListener('click', sendMessage);
+ voiceBtn.addEventListener('click', startVoiceRecognition);
+
+ userInput.addEventListener('keydown', function(event) {
+ if (event.key === 'Enter' && !event.shiftKey) {
+ event.preventDefault();
+ sendMessage();
+ }
+ });