{"id":1777,"date":"2024-10-01T14:24:27","date_gmt":"2024-10-01T14:24:27","guid":{"rendered":"https:\/\/phamho.com\/book\/?p=1777"},"modified":"2024-10-01T14:29:27","modified_gmt":"2024-10-01T14:29:27","slug":"spanish-can-you","status":"publish","type":"post","link":"https:\/\/phamho.com\/book\/spanish-can-you\/","title":{"rendered":"Spanish &#8211; Can you?"},"content":{"rendered":"\n<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n    <meta charset=\"UTF-8\">\n    <title>Spanish &#8211; Can you?<\/title>\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"> <!-- Viewport meta tag for responsiveness -->\n    <style>\n        \/* Base Styles *\/\n        body {\n            font-family: Arial, sans-serif;\n            background-color: #ffffff;\n            margin: 0;\n            padding: 0;\n            display: flex;\n            justify-content: center;\n            align-items: center;\n            min-height: 100vh; \/* Changed from fixed height to min-height for better responsiveness *\/\n            flex-direction: column;\n        }\n        .menu {\n            width: 100%;\n            background-color: #d97b0f;\n            padding: 10px;\n            text-align: center;\n            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);\n            margin-bottom: 20px;\n            overflow-x: auto; \/* Allows horizontal scrolling if menu items exceed screen width *\/\n            white-space: nowrap;\n        }\n        .menu a {\n            color: #fff;\n            text-decoration: none;\n            margin: 0 10px; \/* Reduced margin for better spacing on smaller screens *\/\n            font-weight: bold;\n            font-size: 16px; \/* Increased font size for readability on mobile *\/\n            display: inline-block;\n            padding: 8px 12px; \/* Added padding for larger touch targets *\/\n        }\n        .menu a:hover {\n            text-decoration: underline;\n        }\n        .container {\n            display: flex;\n            flex-direction: column; \/* Stack elements vertically on mobile *\/\n            align-items: center;\n            width: 90%; \/* Use percentage for better responsiveness *\/\n            max-width: 800px; \/* Limit maximum width for larger screens *\/\n        }\n        .image-container {\n            text-align: center;\n            margin-bottom: 20px;\n        }\n        .image-container img {\n            width: 100%; \/* Ensure image scales with container *\/\n            height: auto;\n            border-radius: 20px;\n            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);\n            object-fit: cover; \/* Ensures the image covers the container without distortion *\/\n        }\n        .sentence-text {\n            margin: 10px 0;\n            font-weight: bold;\n            color: #333;\n            font-size: 18px; \/* Increased font size for better visibility *\/\n            text-align: center; \/* Center align text on mobile *\/\n        }\n        .word-box {\n            margin-top: 10px;\n            padding: 10px;\n            background-color: #fff;\n            border: 2px solid #026c96;\n            border-radius: 10px;\n            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);\n            font-size: 16px; \/* Adjusted font size for readability *\/\n            font-weight: bold;\n            color: #026c96;\n            text-align: left;\n            max-height: 300px;\n            overflow-y: auto;\n            width: 100%; \/* Ensure it takes full width of the container *\/\n        }\n        .voice-selection {\n            margin-top: 20px;\n            width: 100%;\n            text-align: center;\n        }\n        .voice-selection label {\n            display: block;\n            margin-bottom: 8px;\n            font-size: 16px;\n            color: #333;\n        }\n        .voice-selection select {\n            width: 80%;\n            max-width: 400px;\n            padding: 8px 12px;\n            font-size: 16px;\n            border: 2px solid #026c96;\n            border-radius: 5px;\n            background-color: #ffffff;\n            color: #026c96;\n            cursor: pointer;\n            box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);\n        }\n        .voice-selection select:focus {\n            outline: none;\n            border-color: #d97b0f;\n            box-shadow: 0 0 5px rgba(217, 123, 15, 0.5);\n        }\n\n        .chat-container {\n            width: 100%; \/* Full width on mobile *\/\n            background-color: #026c96;\n            border-radius: 20px;\n            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);\n            overflow: hidden;\n        }\n        .chat-header {\n            background-color: #d97b0f;\n            color: #fff;\n            padding: 15px; \/* Increased padding for touch areas *\/\n            text-align: center;\n            border-bottom: 1px solid #69010a;\n        }\n        .chat-header h2 {\n            margin: 0;\n            font-size: 20px; \/* Increased font size for better readability *\/\n        }\n        .chat-messages {\n            padding: 15px;\n            overflow-y: auto;\n            max-height: 300px;\n            background-color: #fff;\n        }\n        .message {\n            margin-bottom: 10px;\n            padding: 10px;\n            border-radius: 5px;\n            font-size: 16px; \/* Adjusted font size for readability *\/\n            line-height: 1.5;\n        }\n        .user-message {\n            background-color: #4caf50;\n            color: #fff;\n            text-align: right;\n        }\n        .bot-message {\n            background-color: #2196f3;\n            color: #fff;\n            text-align: left;\n        }\n        .chat-input {\n            display: flex;\n            flex-direction: column; \/* Stack buttons vertically on smaller screens *\/\n            align-items: stretch;\n            background-color: #a3e106;\n            padding: 10px;\n        }\n        .chat-input button {\n            background-color: #17c686;\n            color: #fff;\n            font-weight: bold;\n            border: none;\n            border-radius: 5px;\n            padding: 12px 20px;\n            cursor: pointer;\n            transition: background-color 0.3s;\n            margin: 5px 0; \/* Vertical spacing between buttons *\/\n            font-size: 16px; \/* Increased font size for touch readability *\/\n        }\n        .chat-input .stop-button {\n            background-color: #c86722;\n        }\n        .chat-input button:hover {\n            opacity: 0.9; \/* Subtle feedback on hover *\/\n        }\n\n        \/* Responsive Adjustments *\/\n        @media (min-width: 600px) {\n            .container {\n                flex-direction: row; \/* Side-by-side layout *\/\n                justify-content: center;\n                align-items: flex-start;\n            }\n            .image-container {\n                width: 50%;\n                margin-right: 20px;\n            }\n            .chat-container {\n                width: 50%;\n            }\n            .chat-input {\n                flex-direction: row; \/* Horizontal layout for buttons *\/\n                justify-content: space-between;\n            }\n            .chat-input button {\n                margin: 0 5px; \/* Horizontal spacing *\/\n                flex: 1; \/* Equal width buttons *\/\n            }\n            .voice-selection select {\n                width: 60%;\n            }\n        }\n    <\/style>\n<\/head>\n<body>\n    <div class=\"menu\">\n      <a href=\"https:\/\/phamho.com\/book\/2024\/09\/30\/spanish-do-you-like\/\">Do you like?<\/a>\n        <a href=\"https:\/\/phamho.com\/book\/2024\/10\/01\/spanish-do-you-have\/\">Do you have?<\/a>\n        <a href=\"https:\/\/phamho.com\/book\/2024\/10\/01\/spanish-can-you\/\">Can you?<\/a>\n        <a href=\"https:\/\/phamho.com\/book\/2024\/10\/01\/spanish-simple-conversations\/\">Simple conversations<\/a>  \n        <a href=\"https:\/\/phamho.com\/book\/2024\/10\/01\/spanish-daily-conversations\/\">Daily Conversations<\/a> \n        <a href=\"https:\/\/phamho.com\/book\/2024\/09\/30\/spanish-family\/\">Family<\/a>\n    <\/div>\n\n    <div class=\"container\">\n        <div class=\"image-container\">\n            <img decoding=\"async\" src=\"https:\/\/phamho.com\/book\/wp-content\/uploads\/2024\/08\/8d7efe04-a355-4214-a6cb-48d660b80124.webp\" alt=\"Lesson Robot\">\n            <div class=\"sentence-text\">See the questions and answers in this box<\/div>\n            <div id=\"word-box\" class=\"word-box\">\n                <!-- Learned questions will appear here -->\n            <\/div>\n            <!-- Voice Selection Dropdown -->\n            <div class=\"voice-selection\">\n                <label for=\"voice-select\"><strong>Choose Spanish Voice:<\/strong><\/label>\n                <select id=\"voice-select\">\n                    <option value=\"\">Loading voices&#8230;<\/option>\n                <\/select>\n            <\/div>\n        <\/div>\n        <div class=\"chat-container\">\n            <div class=\"chat-header\">  \n                <h2>Spanish &#8211; Can you?<\/h2>\n            <\/div>\n            <div class=\"chat-messages\" id=\"chat-messages\">\n                <!-- Messages will appear here -->\n            <\/div>\n            <div class=\"chat-input\">\n                <button id=\"start-btn\" class=\"send-button\">Start Lesson<\/button>\n                <button id=\"stop-btn\" class=\"stop-button\" disabled>Stop<\/button>\n            <\/div>\n        <\/div>\n    <\/div>\n\n    <script>\n        \/\/ Feature detection for Speech Recognition\n        const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;\n        const isSpeechRecognitionSupported = SpeechRecognition !== undefined;\n        let recognition;\n        if (isSpeechRecognitionSupported) {\n            recognition = new SpeechRecognition();\n            recognition.lang = 'es-ES';\n            recognition.interimResults = false;\n            recognition.maxAlternatives = 1;\n        } else {\n            alert('Your browser does not support speech recognition. Please use a compatible browser like Firefox for Android.');\n        }\n\n        \/\/ Check for Speech Synthesis support\n        const speechSynthesisSupported = 'speechSynthesis' in window;\n\n        \/\/ Updated Questions data focusing on likes and dislikes\n        const questions = [\n        {\n        question: \"\u00bfPuedes cocinar?\",\n        translation: \"Can you cook?\",\n        keywords: [\"puedo\", \"cocinar\"],\n        sampleAnswer: \"S\u00ed, puedo cocinar.\",\n        sampleTranslation: \"Yes, I can cook.\"\n    },\n    {\n        question: \"\u00bfPuedes cantar?\",\n        translation: \"Can you sing?\",\n        keywords: [\"puedo\", \"cantar\"],\n        sampleAnswer: \"S\u00ed, puedo cantar.\",\n        sampleTranslation: \"Yes, I can sing.\"\n    },\n    {\n        question: \"\u00bfPuedes comer pl\u00e1tano?\",\n        translation: \"Can you eat a banana?\",\n        keywords: [\"puedo\", \"comer\", \"pl\u00e1tano\"],\n        sampleAnswer: \"S\u00ed, puedo comer pl\u00e1tano.\",\n        sampleTranslation: \"Yes, I can eat a banana.\"\n    },\n    {\n        question: \"\u00bfPuedes bailar?\",\n        translation: \"Can you dance?\",\n        keywords: [\"puedo\", \"bailar\"],\n        sampleAnswer: \"S\u00ed, puedo bailar.\",\n        sampleTranslation: \"Yes, I can dance.\"\n    },\n    {\n        question: \"\u00bfPuedes nadar?\",\n        translation: \"Can you swim?\",\n        keywords: [\"puedo\", \"nadar\"],\n        sampleAnswer: \"S\u00ed, puedo nadar.\",\n        sampleTranslation: \"Yes, I can swim.\"\n    },\n    {\n        question: \"\u00bfPuedes leer?\",\n        translation: \"Can you read?\",\n        keywords: [\"puedo\", \"leer\"],\n        sampleAnswer: \"S\u00ed, puedo leer.\",\n        sampleTranslation: \"Yes, I can read.\"\n    },\n    {\n        question: \"\u00bfPuedes escribir?\",\n        translation: \"Can you write?\",\n        keywords: [\"puedo\", \"escribir\"],\n        sampleAnswer: \"S\u00ed, puedo escribir.\",\n        sampleTranslation: \"Yes, I can write.\"\n    },\n    {\n        question: \"\u00bfPuedes dibujar?\",\n        translation: \"Can you draw?\",\n        keywords: [\"puedo\", \"dibujar\"],\n        sampleAnswer: \"S\u00ed, puedo dibujar.\",\n        sampleTranslation: \"Yes, I can draw.\"\n    },\n    {\n        question: \"\u00bfPuedes jugar al f\u00fatbol?\",\n        translation: \"Can you play soccer?\",\n        keywords: [\"puedo\", \"jugar\", \"f\u00fatbol\"],\n        sampleAnswer: \"S\u00ed, puedo jugar al f\u00fatbol.\",\n        sampleTranslation: \"Yes, I can play soccer.\"\n    },\n    {\n        question: \"\u00bfPuedes hablar ingl\u00e9s?\",\n        translation: \"Can you speak English?\",\n        keywords: [\"puedo\", \"hablar\", \"ingl\u00e9s\"],\n        sampleAnswer: \"S\u00ed, puedo hablar ingl\u00e9s.\",\n        sampleTranslation: \"Yes, I can speak English.\"\n    },\n    {\n        question: \"\u00bfPuedes tocar un instrumento?\",\n        translation: \"Can you play an instrument?\",\n        keywords: [\"puedo\", \"tocar\", \"instrumento\"],\n        sampleAnswer: \"S\u00ed, puedo tocar la guitarra.\",\n        sampleTranslation: \"Yes, I can play the guitar.\"\n    },\n    {\n        question: \"\u00bfPuedes viajar?\",\n        translation: \"Can you travel?\",\n        keywords: [\"puedo\", \"viajar\"],\n        sampleAnswer: \"S\u00ed, puedo viajar.\",\n        sampleTranslation: \"Yes, I can travel.\"\n    },\n    {\n        question: \"\u00bfPuedes cocinar comida mexicana?\",\n        translation: \"Can you cook Mexican food?\",\n        keywords: [\"puedo\", \"cocinar\", \"comida mexicana\"],\n        sampleAnswer: \"S\u00ed, puedo cocinar comida mexicana.\",\n        sampleTranslation: \"Yes, I can cook Mexican food.\"\n    },\n    {\n        question: \"\u00bfPuedes conducir?\",\n        translation: \"Can you drive?\",\n        keywords: [\"puedo\", \"conducir\"],\n        sampleAnswer: \"S\u00ed, puedo conducir.\",\n        sampleTranslation: \"Yes, I can drive.\"\n    },\n    {\n        question: \"\u00bfPuedes cuidar ni\u00f1os?\",\n        translation: \"Can you take care of children?\",\n        keywords: [\"puedo\", \"cuidar\", \"ni\u00f1os\"],\n        sampleAnswer: \"S\u00ed, puedo cuidar ni\u00f1os.\",\n        sampleTranslation: \"Yes, I can take care of children.\"\n    },\n    {\n        question: \"\u00bfPuedes ense\u00f1ar espa\u00f1ol?\",\n        translation: \"Can you teach Spanish?\",\n        keywords: [\"puedo\", \"ense\u00f1ar\", \"espa\u00f1ol\"],\n        sampleAnswer: \"S\u00ed, puedo ense\u00f1ar espa\u00f1ol.\",\n        sampleTranslation: \"Yes, I can teach Spanish.\"\n    },\n    {\n        question: \"\u00bfPuedes hacer ejercicio?\",\n        translation: \"Can you exercise?\",\n        keywords: [\"puedo\", \"hacer\", \"ejercicio\"],\n        sampleAnswer: \"S\u00ed, puedo hacer ejercicio.\",\n        sampleTranslation: \"Yes, I can exercise.\"\n    },\n    {\n        question: \"\u00bfPuedes ayudarme?\",\n        translation: \"Can you help me?\",\n        keywords: [\"puedo\", \"ayudarme\"],\n        sampleAnswer: \"S\u00ed, puedo ayudarte.\",\n        sampleTranslation: \"Yes, I can help you.\"\n    },\n    {\n        question: \"\u00bfPuedes arreglar esto?\",\n        translation: \"Can you fix this?\",\n        keywords: [\"puedo\", \"arreglar\", \"esto\"],\n        sampleAnswer: \"S\u00ed, puedo arreglar esto.\",\n        sampleTranslation: \"Yes, I can fix this.\"\n    },\n    {\n        question: \"\u00bfPuedes buscar informaci\u00f3n?\",\n        translation: \"Can you look for information?\",\n        keywords: [\"puedo\", \"buscar\", \"informaci\u00f3n\"],\n        sampleAnswer: \"S\u00ed, puedo buscar informaci\u00f3n.\",\n        sampleTranslation: \"Yes, I can look for information.\"\n    }\n];\n\n\n        let currentQuestionIndex = 0;\n        let repeatAttempts = 0;\n        const stopKeywords = [\"adi\u00f3s\", \"chao\", \"bye\", \"bye bye\", \"goodbye\", \"stop\"];\n        let lessonStarted = false;\n        let voicesLoaded = false;\n        let selectedVoice = null; \/\/ To store the user's selected voice\n\n        \/\/ DOM Elements\n        const voiceSelect = document.getElementById('voice-select');\n        const startBtn = document.getElementById('start-btn');\n        const stopBtn = document.getElementById('stop-btn');\n\n        window.addEventListener('load', function() {\n            if (speechSynthesisSupported) {\n                loadVoices();\n            } else {\n                alert('Sorry, your browser does not support speech synthesis. Please use a compatible browser for the best experience.');\n                appendMessage('Speech synthesis not supported in your browser.', 'bot');\n            }\n        });\n\n        function loadVoices() {\n            const voices = window.speechSynthesis.getVoices();\n\n            if (voices.length !== 0) {\n                populateVoiceList();\n            } else {\n                window.speechSynthesis.onvoiceschanged = populateVoiceList;\n            }\n        }\n\n        function populateVoiceList() {\n            const voices = window.speechSynthesis.getVoices().filter(voice => voice.lang.startsWith('es'));\n            \n            \/\/ Define preferred native Spanish voice names\n            const preferredSpanishVoiceNames = [\n                'Google espa\u00f1ol', \/\/ Common in Chrome\n                'Microsoft Helena - Spanish (Spain)', \/\/ Common in Windows\n                'Microsoft Sabina - Spanish (Mexico)', \/\/ Common in Windows\n                'Apple Mar\u00eda', \/\/ Common in macOS\n                'Apple Satu' \/\/ Another common in macOS\n            ];\n\n            \/\/ Filter voices to include only preferred native voices\n            const nativeSpanishVoices = voices.filter(voice => preferredSpanishVoiceNames.includes(voice.name));\n\n            voiceSelect.innerHTML = ''; \/\/ Clear existing options\n\n            if (nativeSpanishVoices.length === 0) {\n                \/\/ If no preferred voices are found, inform the user\n                voiceSelect.innerHTML = '<option value=\"\">No native Spanish voices available<\/option>';\n                selectedVoice = null;\n                greetUser();\n                return;\n            }\n\n            nativeSpanishVoices.forEach((voice, index) => {\n                const option = document.createElement('option');\n                option.value = index;\n                option.textContent = `${voice.name} (${voice.lang})`;\n                voiceSelect.appendChild(option);\n            });\n\n            \/\/ Set default voice if available\n            if (nativeSpanishVoices.length > 0) {\n                selectedVoice = nativeSpanishVoices[0];\n                voiceSelect.value = '0';\n                greetUser();\n            } else {\n                greetUser();\n            }\n        }\n\n        \/\/ Handle voice selection\n        voiceSelect.addEventListener('change', function() {\n            const selectedIndex = parseInt(this.value, 10);\n            const voices = window.speechSynthesis.getVoices().filter(voice => voice.lang.startsWith('es'));\n\n            \/\/ Define preferred native Spanish voice names\n            const preferredSpanishVoiceNames = [\n                'Google espa\u00f1ol', \/\/ Common in Chrome\n                'Microsoft Helena - Spanish (Spain)', \/\/ Common in Windows\n                'Microsoft Sabina - Spanish (Mexico)', \/\/ Common in Windows\n                'Apple Mar\u00eda', \/\/ Common in macOS\n                'Apple Satu' \/\/ Another common in macOS\n            ];\n\n            \/\/ Filter voices to include only preferred native voices\n            const nativeSpanishVoices = voices.filter(voice => preferredSpanishVoiceNames.includes(voice.name));\n\n            if (nativeSpanishVoices[selectedIndex]) {\n                selectedVoice = nativeSpanishVoices[selectedIndex];\n                console.log(`Selected voice: ${selectedVoice.name}`);\n            } else {\n                selectedVoice = null;\n            }\n        });\n\n        function greetUser() {\n            const greeting = \"\u00a1Bienvenido! En esta lecci\u00f3n, Te har\u00e9 20 preguntas sencillas de tipo \u00bfPuedes? en espa\u00f1ol. Repetir\u00e9 cada pregunta dos veces. Haz clic en 'Comenzar Lecci\u00f3n' para empezar.\";\n            appendMessage(greeting, 'bot');\n            sayText(greeting, 'es', true);\n        }\n\n        startBtn.addEventListener('click', function() {\n            if (!isSpeechRecognitionSupported) {\n                alert('Speech recognition is not supported in your browser. The lesson cannot proceed.');\n                return;\n            }\n            if (lessonStarted) {\n                alert('La lecci\u00f3n ya ha comenzado.');\n                return;\n            }\n            currentQuestionIndex = 0;\n            repeatAttempts = 0;\n            lessonStarted = true;\n            startLesson();\n            \/\/ Disable the start button to prevent multiple starts\n            startBtn.disabled = true;\n            stopBtn.disabled = false;\n        });\n\n        stopBtn.addEventListener('click', function() {\n            endLesson(true); \/\/ User stopped the lesson\n            \/\/ Re-enable the start button\n            startBtn.disabled = false;\n            this.disabled = true;\n        });\n\n        function startLesson() {\n            if (currentQuestionIndex < questions.length) {\n                const questionObj = questions[currentQuestionIndex];\n                const formattedQuestion = formatSentence(questionObj.question);\n\n                appendMessage(`Pregunta: '${formattedQuestion}'`, 'bot');\n                addQuestionToBox(formattedQuestion, questionObj.translation, questionObj.sampleAnswer, questionObj.sampleTranslation);\n\n                \/\/ Say the question in Spanish twice\n                sayText(formattedQuestion, \"es\", false, function() {\n                    sayText(formattedQuestion, \"es\", false, function() {\n                        \/\/ Prompt user to answer\n                        listenUserResponse(questionObj);\n                    });\n                });\n            } else {\n                endLesson();\n            }\n        }\n\n        function listenUserResponse(questionObj) {\n            recognition.start();\n            appendMessage(\"Escuchando tu respuesta...\", 'bot'); \/\/ Inform the user that listening has started\n\n            recognition.onresult = function(event) {\n                let userInput = event.results[0][0].transcript.trim();\n                appendMessage(userInput, 'user');\n\n                if (stopKeywords.includes(userInput.toLowerCase())) {\n                    endLesson(true); \/\/ User requested to stop the lesson\n                    return;\n                }\n\n                processUserResponse(userInput, questionObj);\n            };\n\n            recognition.onspeechend = function() {\n                recognition.stop();\n            };\n\n            recognition.onerror = function(event) {\n                let errorMessage = '';\n                switch(event.error) {\n                    case 'no-speech':\n                        errorMessage = 'No se detect\u00f3 habla. Por favor, intenta de nuevo.';\n                        break;\n                    case 'audio-capture':\n                        errorMessage = 'Acceso al micr\u00f3fono denegado. Por favor, verifica tus configuraciones.';\n                        break;\n                    case 'not-allowed':\n                        errorMessage = 'Permiso para usar el micr\u00f3fono denegado.';\n                        break;\n                    default:\n                        errorMessage = 'Ocurri\u00f3 un error: ' + event.error;\n                }\n                appendMessage(errorMessage, 'bot');\n                sayText(errorMessage, 'es', true);\n            };\n        }\n\n        function processUserResponse(userInput, questionObj) {\n            \/\/ Normalize user's response\n            let normalizedUserInput = normalizeSentence(userInput);\n            normalizedUserInput = normalizeNumbers(normalizedUserInput);\n\n            \/\/ Normalize keywords\n            let normalizedKeywords = questionObj.keywords.map(keyword => normalizeNumbers(normalizeSentence(keyword)));\n\n            \/\/ Check for keywords in the user's response\n            let keywordsFound = normalizedKeywords.filter(keyword => normalizedUserInput.includes(keyword));\n\n            if (keywordsFound.length === normalizedKeywords.length) {\n                const positiveMessage = \"\u00a1Excelente! Tu respuesta es muy buena.\";\n                appendMessage(positiveMessage, 'bot');\n                sayText(positiveMessage, 'es', true);\n                repeatAttempts = 0; \/\/ Reset attempts counter\n                currentQuestionIndex++;\n                setTimeout(startLesson, 2000); \/\/ Move to next question after 2 seconds\n            } else {\n                repeatAttempts++;\n                if (repeatAttempts < 2) {\n                    const missingKeywords = questionObj.keywords.filter((keyword, index) => !normalizedUserInput.includes(normalizedKeywords[index]));\n                    const correctionMessage = `No escuch\u00e9 las palabras: ${missingKeywords.join(', ')}. Por favor, intenta de nuevo.`;\n                    appendMessage(correctionMessage, 'bot');\n                    sayText(correctionMessage, 'es', true);\n                    setTimeout(() => listenUserResponse(questionObj), 2000); \/\/ Give the user another chance\n                } else {\n                    \/\/ Provide sample answer\n                    const sampleAnswerMessage = `No te preocupes. Aqu\u00ed tienes una respuesta de ejemplo: '${questionObj.sampleAnswer}'.`;\n                    appendMessage(sampleAnswerMessage, 'bot');\n                    sayText(\"No te preocupes. Aqu\u00ed tienes una respuesta de ejemplo.\", 'es', true, () => {\n                        sayText(questionObj.sampleAnswer, 'es', false, () => {\n                            \/\/ Proceed to the next question\n                            repeatAttempts = 0;\n                            currentQuestionIndex++;\n                            setTimeout(startLesson, 2000);\n                        });\n                    });\n                }\n            }\n        }\n\n        function addQuestionToBox(question, translation, sampleAnswer, sampleTranslation) {\n            const wordBox = document.getElementById('word-box');\n            const questionElement = document.createElement('div');\n            questionElement.innerHTML = `<strong>P:<\/strong> '${question}' - '${translation}'<br><strong>R:<\/strong> '${sampleAnswer}' - '${sampleTranslation}'`;\n            wordBox.appendChild(questionElement);\n            wordBox.scrollTop = wordBox.scrollHeight;\n        }\n\n        function endLesson(userStopped = false) {\n            lessonStarted = false;\n            let message;\n            if (userStopped) {\n                message = \"\u00a1Gracias por participar! Espero que hayas disfrutado la lecci\u00f3n.\";\n            } else {\n                message = \"\u00a1Bien hecho! Has respondido todas las preguntas sobre gustos. \u00a1Sigue practicando!\";\n            }\n            appendMessage(message, \"bot\");\n            sayText(message, \"es\", true);\n            \/\/ Re-enable the start button and disable stop button\n            startBtn.disabled = false;\n            stopBtn.disabled = true;\n        }\n\n        function sayText(text, lang, preferFemale, callback) {\n            if (!speechSynthesisSupported) return;\n            const utterance = new SpeechSynthesisUtterance(text);\n            utterance.lang = lang;\n\n            \/\/ Adjust rate and pitch for Spanish to improve naturalness\n            if (lang.startsWith('es')) {\n                utterance.rate = 0.9; \/\/ Slightly slower\n                utterance.pitch = 1.1; \/\/ Slightly higher pitch\n            } else {\n                utterance.rate = 1.0;\n                utterance.pitch = 1.0;\n            }\n\n            \/\/ Use the selected voice if available\n            if (selectedVoice) {\n                utterance.voice = selectedVoice;\n            }\n\n            utterance.onend = function() {\n                if (callback) callback();\n            };\n\n            window.speechSynthesis.speak(utterance);\n        }\n\n        function appendMessage(text, sender) {\n            const messageContainer = document.getElementById('chat-messages');\n            const messageElement = document.createElement('div');\n            messageElement.classList.add('message');\n            messageElement.classList.add(sender === 'bot' ? 'bot-message' : 'user-message');\n            messageElement.innerText = text;\n            messageContainer.appendChild(messageElement);\n            messageContainer.scrollTop = messageContainer.scrollHeight;\n        }\n\n        function formatSentence(sentence) {\n            \/\/ Trim whitespace\n            sentence = sentence.trim();\n            if (sentence.length === 0) return sentence;\n            \n            \/\/ Capitalize the first character\n            let firstChar = sentence.charAt(0).toUpperCase();\n            let restOfSentence = sentence.slice(1);\n            let formattedSentence = firstChar + restOfSentence;\n            \n            \/\/ Check if the sentence is a question\n            const isQuestion = formattedSentence.endsWith('?');\n            \n            if (isQuestion) {\n                \/\/ Ensure it starts with '\u00bf'\n                if (!formattedSentence.startsWith('\u00bf')) {\n                    formattedSentence = '\u00bf' + formattedSentence;\n                }\n            } else {\n                \/\/ Ensure it ends with a period\n                if (!formattedSentence.endsWith('.')) {\n                    formattedSentence += '.';\n                }\n            }\n    \n        return formattedSentence;\n          }\n\n        function normalizeSentence(sentence) {\n            \/\/ Remove punctuation and convert to lowercase for comparison\n            return sentence.replace(\/[.,!?\u00bf\u00a1]\/g, '').toLowerCase().trim();\n        }\n\n        function normalizeNumbers(text) {\n            \/\/ Map number words to digits (updated for possible number usage)\n            const numberWords = {\n                'cero': 0,\n                'uno': 1,\n                'una': 1,\n                'dos': 2,\n                'tres': 3,\n                'cuatro': 4,\n                'cinco': 5,\n                'seis': 6,\n                'siete': 7,\n                'ocho': 8,\n                'nueve': 9,\n                'diez': 10\n                \/\/ Add more numbers as needed\n            };\n\n            \/\/ Regular expression to match numbers in words\n            const numberPattern = new RegExp('\\\\b(' + Object.keys(numberWords).join('|') + ')\\\\b', 'gi');\n\n            text = text.replace(numberPattern, function(match) {\n                match = match.toLowerCase();\n                if (numberWords[match] !== undefined) {\n                    return numberWords[match].toString();\n                }\n                return match;\n            });\n\n            return text;\n        }\n\n    <\/script>\n<\/body>\n<\/html>\n\n","protected":false},"excerpt":{"rendered":"<p>Spanish &#8211; Can you? Do you like? Do you have? Can you? Simple conversations Daily Conversations Family See the questions and answers in this box Choose Spanish Voice: Loading voices&#8230; Spanish &#8211; Can you? Start Lesson Stop<\/p>\n","protected":false},"author":1,"featured_media":1393,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[38,42,34,33],"tags":[],"class_list":["post-1777","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-activities","category-interaction","category-robots","category-spanish"],"featured_image_src":"https:\/\/phamho.com\/book\/wp-content\/uploads\/2024\/06\/DALL\u00b7E-2024-06-09-12.04.13-A-group-of-secondary-school-girls-and-boys-talking-in-a-school-hallway.-The-students-are-wearing-school-uniforms-with-girls-in-skirts-and-boys-in-tro-1024x585.webp","blog_images":{"medium":"https:\/\/phamho.com\/book\/wp-content\/uploads\/2024\/06\/DALL\u00b7E-2024-06-09-12.04.13-A-group-of-secondary-school-girls-and-boys-talking-in-a-school-hallway.-The-students-are-wearing-school-uniforms-with-girls-in-skirts-and-boys-in-tro-300x171.webp","large":"https:\/\/phamho.com\/book\/wp-content\/uploads\/2024\/06\/DALL\u00b7E-2024-06-09-12.04.13-A-group-of-secondary-school-girls-and-boys-talking-in-a-school-hallway.-The-students-are-wearing-school-uniforms-with-girls-in-skirts-and-boys-in-tro-1024x585.webp"},"ams_acf":[],"_links":{"self":[{"href":"https:\/\/phamho.com\/book\/wp-json\/wp\/v2\/posts\/1777","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/phamho.com\/book\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/phamho.com\/book\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/phamho.com\/book\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/phamho.com\/book\/wp-json\/wp\/v2\/comments?post=1777"}],"version-history":[{"count":2,"href":"https:\/\/phamho.com\/book\/wp-json\/wp\/v2\/posts\/1777\/revisions"}],"predecessor-version":[{"id":1782,"href":"https:\/\/phamho.com\/book\/wp-json\/wp\/v2\/posts\/1777\/revisions\/1782"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/phamho.com\/book\/wp-json\/wp\/v2\/media\/1393"}],"wp:attachment":[{"href":"https:\/\/phamho.com\/book\/wp-json\/wp\/v2\/media?parent=1777"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/phamho.com\/book\/wp-json\/wp\/v2\/categories?post=1777"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/phamho.com\/book\/wp-json\/wp\/v2\/tags?post=1777"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}