{"id":1549,"date":"2024-09-16T02:49:00","date_gmt":"2024-09-16T02:49:00","guid":{"rendered":"https:\/\/phamho.com\/book\/?p=1549"},"modified":"2024-09-23T03:25:14","modified_gmt":"2024-09-23T03:25:14","slug":"spanish-vocabulary","status":"publish","type":"post","link":"https:\/\/phamho.com\/book\/spanish-vocabulary\/","title":{"rendered":"Spanish Vocabulary &#8211; Family"},"content":{"rendered":"\n<!DOCTYPE html>\n<html lang=\"es\">\n<head>\n    <meta charset=\"UTF-8\">\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n    <title>Spanish Vocabulary &#8211; Family<\/title>\n    <style>\n        body {\n            font-family: Arial, sans-serif;\n            background-color: #ffffff;\n            margin: 0;\n            padding: 0;\n            display: flex;\n            flex-direction: column; \/* Stack elements vertically *\/\n            min-height: 100vh;\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            flex-shrink: 0;\n            overflow-x: auto;\n            white-space: nowrap;\n        }\n        .menu a {\n            color: #fff;\n            text-decoration: none;\n            margin: 0 8px;\n            font-weight: bold;\n            font-size: 14px;\n            display: inline-block;\n        }\n        .menu a:hover {\n            text-decoration: underline;\n        }\n        .container {\n            display: flex;\n            flex-wrap: wrap;\n            flex: 1 0 auto;\n            padding: 10px;\n            box-sizing: border-box;\n            justify-content: center;\n        }\n        .image-container, .chat-container {\n            width: 100%;\n            max-width: 600px;\n            margin-bottom: 20px;\n        }\n        .image-container {\n            text-align: center;\n        }\n        .image-container img {\n            width: 100%;\n            height: auto;\n            border-radius: 20px;\n            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);\n        }\n        .sentence-text {\n            margin: 10px 0;\n            font-weight: bold;\n            color: #333;\n            font-size: 16px;\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: 18px;\n            font-weight: bold;\n            color: #026c96;\n            text-align: left;\n            max-height: 300px;\n            overflow-y: auto;\n        }\n        .chat-container {\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: 10px;\n            text-align: center;\n            border-bottom: 1px solid #69010a;\n        }\n        .chat-header h2 {\n            margin: 0;\n            font-size: 18px;\n        }\n        .chat-messages {\n            padding: 10px;\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: 14px;\n            line-height: 1.4;\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            align-items: center;\n            background-color: #a3e106;\n            padding: 10px;\n            justify-content: center;\n        }\n        .send-button, .stop-button {\n            background-color: #17c686;\n            color: #fff;\n            font-weight: bold;\n            border: none;\n            border-radius: 5px;\n            padding: 8px 10px;\n            cursor: pointer;\n            transition: background-color 0.3s;\n            flex: 1;\n            margin: 0 5px;\n            max-width: 150px;\n            font-size: 14px;\n        }\n        .stop-button {\n            background-color: #c86722;\n        }\n        .chat-input input {\n            flex: 2;\n            padding: 8px;\n            margin-right: 10px;\n            border: 2px solid #026c96;\n            border-radius: 5px;\n            font-size: 16px;\n        }\n\n        \/* Adjustments for smaller screens *\/\n        @media (max-width: 600px) {\n            .menu a {\n                margin: 0 5px;\n                font-size: 12px;\n            }\n            .sentence-text {\n                font-size: 14px;\n            }\n            .word-box {\n                font-size: 14px;\n                max-height: 200px;\n            }\n            .chat-header h2 {\n                font-size: 16px;\n            }\n            .chat-messages {\n                max-height: 200px;\n            }\n            .message {\n                font-size: 13px;\n            }\n            .send-button, .stop-button {\n                padding: 6px 8px;\n                font-size: 12px;\n                max-width: 120px;\n            }\n            .chat-input input {\n                font-size: 14px;\n            }\n        }\n        @media (max-width: 400px) {\n            .menu a {\n                margin: 0 3px;\n                font-size: 11px;\n            }\n            .sentence-text {\n                font-size: 13px;\n            }\n            .word-box {\n                font-size: 13px;\n                max-height: 150px;\n            }\n            .chat-header h2 {\n                font-size: 14px;\n            }\n            .chat-messages {\n                max-height: 150px;\n            }\n            .message {\n                font-size: 12px;\n            }\n            .send-button, .stop-button {\n                padding: 5px 6px;\n                font-size: 11px;\n                max-width: 100px;\n            }\n            .chat-input input {\n                font-size: 12px;\n            }\n        }\n    <\/style>\n<\/head>\n<body>\n    <div class=\"menu\">\n        <a href=\"https:\/\/phamho.com\/book\/2024\/09\/16\/spanish-vocabulary\/\">Vocabulary<\/a>\n        <a href=\"https:\/\/phamho.com\/book\/2024\/09\/17\/spanish-sentences-family\/\">Sentences<\/a>\n        <a href=\"https:\/\/phamho.com\/book\/2024\/09\/17\/spanish-yes-no-questions\/\">Yes\/No Questions<\/a>\n        <a href=\"https:\/\/phamho.com\/book\/2024\/09\/17\/spanish-wh-questions-family\/\">WH Questions<\/a>  \n        <a href=\"https:\/\/phamho.com\/book\/2024\/09\/18\/spanish-interaction-family\/\">Internactions<\/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\/09\/DALL\u00b7E-2024-09-15-18.17.33-A-classroom-scene-where-advanced-robots-are-teaching-English-to-B1-level-students.-The-robots-have-a-humanoid-design-with-sleek-metallic-bodies-and-f.webp\" alt=\"Lecci\u00f3n Robot\">\n            <div class=\"sentence-text\">Mira el vocabulario en esta caja<\/div>\n            <div id=\"word-box\" class=\"word-box\">\n                <!-- Learned family-related words and phrases will be displayed here -->\n            <\/div>\n        <\/div>\n        <div class=\"chat-container\">\n            <div class=\"chat-header\">  \n              <h2>Spanish Vocabulary &#8211; Family<\/h2>\n            <\/div>\n            <div class=\"chat-messages\" id=\"chat-messages\">\n                <!-- Messages will appear here -->\n            <\/div>\n            <div class=\"chat-input\">\n                <input type=\"text\" id=\"user-input\" placeholder=\"Type your answer here...\" style=\"display: none;\" \/>\n                <button id=\"submit-btn\" class=\"send-button\" style=\"display: none;\">Submit<\/button>\n                <button id=\"start-btn\" class=\"send-button\">Start Lesson<\/button>\n                <button id=\"stop-btn\" class=\"stop-button\">Stop<\/button>\n            <\/div>\n        <\/div>\n    <\/div>\n\n    <script>\n    const vocabulary = [\n        { word: \"la familia\", translation: \"the family\" },\n        { word: \"el padre\", translation: \"the father\" },\n        { word: \"la madre\", translation: \"the mother\" },\n        { word: \"el hermano\", translation: \"the brother\" },\n        { word: \"la hermana\", translation: \"the sister\" },\n        { word: \"el abuelo\", translation: \"the grandfather\" },\n        { word: \"la abuela\", translation: \"the grandmother\" },\n        { word: \"el hijo\", translation: \"the son\" },\n        { word: \"la hija\", translation: \"the daughter\" },\n        { word: \"el t\u00edo\", translation: \"the uncle\" },\n        { word: \"la t\u00eda\", translation: \"the aunt\" },\n        { word: \"el primo\", translation: \"the cousin (male)\" },\n        { word: \"la prima\", translation: \"the cousin (female)\" },\n        { word: \"el esposo\", translation: \"the husband\" },\n        { word: \"la esposa\", translation: \"the wife\" },\n        { word: \"los padres\", translation: \"the parents\" },\n        { word: \"los abuelos\", translation: \"the grandparents\" },\n        { word: \"los hermanos\", translation: \"the siblings\" },\n        { word: \"los hijos\", translation: \"the children\" },\n        { word: \"los primos\", translation: \"the cousins\" }\n    ];\n\n    let currentWordIndex = 0;\n    let repeatAttempts = 0;\n    let isSpeechRecognitionSupported = false;\n    let recognition;\n\n    const stopKeywords = [\"adi\u00f3s\", \"goodbye\", \"good bye\", \"bye\", \"bye bye\", \"byebye\", \"hasta luego\", \"chao\"];\n    const speechSynthesisSupported = 'speechSynthesis' in window;\n\n    \/\/ Feature detection for Speech Recognition\n    if (window.SpeechRecognition || window.webkitSpeechRecognition) {\n        isSpeechRecognitionSupported = true;\n        recognition = new (window.SpeechRecognition || window.webkitSpeechRecognition)();\n        recognition.lang = 'es-ES';\n        recognition.interimResults = false;\n        recognition.maxAlternatives = 1;\n    }\n\n    window.onload = function() {\n        if (speechSynthesisSupported) {\n            if (window.speechSynthesis.getVoices().length === 0) {\n                \/\/ Voices not loaded yet, wait for the event\n                window.speechSynthesis.onvoiceschanged = function() {\n                    greetUser();\n                };\n            } else {\n                \/\/ Voices already loaded\n                greetUser();\n            }\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        if (!isSpeechRecognitionSupported) {\n            \/\/ Show text input and submit button\n            document.getElementById('user-input').style.display = 'block';\n            document.getElementById('submit-btn').style.display = 'block';\n            \/\/ Optionally hide the start button\n            \/\/ document.getElementById('start-btn').style.display = 'none';\n        }\n    };\n\n    function greetUser() {\n        let greeting = \"Welcome! In this lesson, you will learn 20 words and phrases about family in Spanish. I will say each word or phrase twice, and then you will repeat.\";\n        if (!isSpeechRecognitionSupported) {\n            greeting += \" Your browser does not support voice input, so please type your responses in the text box below.\";\n        }\n        greeting += \" Are you ready? Click Start Lesson to begin.\";\n        appendMessage(greeting, 'bot');\n        sayText(greeting, 'en');\n    }\n\n    document.getElementById('start-btn').onclick = function() {\n        currentWordIndex = 0;\n        repeatAttempts = 0;\n        startVocabularyLesson();\n    };\n\n    document.getElementById('stop-btn').onclick = function() {\n        endLesson(true); \/\/ Stop the lesson when \"Stop\" button is clicked\n    };\n\n    \/\/ Handle submit button click\n    document.getElementById('submit-btn').onclick = function() {\n        let userInput = document.getElementById('user-input').value.trim().toLowerCase();\n        document.getElementById('user-input').value = '';\n        if (userInput) {\n            processUserResponse(userInput);\n        }\n    };\n\n    \/\/ Allow pressing 'Enter' to submit the answer\n    document.getElementById('user-input').addEventListener('keypress', function(event) {\n        if (event.key === 'Enter') {\n            event.preventDefault();\n            document.getElementById('submit-btn').click();\n        }\n    });\n\n    function startVocabularyLesson() {\n        if (currentWordIndex < vocabulary.length) {\n            const word = vocabulary[currentWordIndex].word;\n            const translation = vocabulary[currentWordIndex].translation;\n\n            appendMessage(`'${word}' - '${translation}'`, 'bot');\n            addWordToBox(word, translation);\n            sayText(word, \"es\", function() {\n                setTimeout(() => {\n                    sayText(word, \"es\", function() {\n                        setTimeout(() => {\n                            if (isSpeechRecognitionSupported) {\n                                \/\/ Prompt user to repeat\n                                appendMessage(`Please repeat after me: '${word}'`, 'bot');\n                                sayText(\"Please repeat after me:\", \"en\", function() {\n                                    sayText(`${word}`, \"es\", function() {\n                                        listenUserResponse(word);\n                                    });\n                                });\n                            } else {\n                                \/\/ Prompt user to type\n                                appendMessage(`Please type the word '${word}' in the text box below.`, 'bot');\n                                sayText(`Please type the word '${word}' in the text box below.`, \"en\");\n                                \/\/ Focus the text input\n                                document.getElementById('user-input').focus();\n                            }\n                        }, 500); \/\/ Small pause before prompt\n                    });\n                }, 500); \/\/ Small pause before second repetition\n            });\n        } else {\n            endLesson();\n        }\n    }\n\n    function listenUserResponse(expectedWord) {\n        recognition.start();\n\n        recognition.onresult = function(event) {\n            let userInput = event.results[0][0].transcript.trim().toLowerCase();\n            appendMessage(userInput, 'user');\n\n            processUserResponse(userInput, expectedWord);\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 speech detected. Please try again or type your answer.';\n                    break;\n                case 'audio-capture':\n                    errorMessage = 'Microphone access denied. Please check your settings or type your answer.';\n                    break;\n                case 'not-allowed':\n                    errorMessage = 'Permission to use microphone denied.';\n                    break;\n                default:\n                    errorMessage = 'An error occurred: ' + event.error;\n            }\n            appendMessage(errorMessage, 'bot');\n            sayText(errorMessage, 'en');\n        };\n    }\n\n    function processUserResponse(userInput, expectedWord = vocabulary[currentWordIndex].word) {\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        if (userInput.toLowerCase() === expectedWord.toLowerCase()) {\n            const positiveMessage = \"Great! Your pronunciation is good.\";\n            appendMessage(positiveMessage, 'bot');\n            sayText(positiveMessage, 'en'); \/\/ Feedback in English\n            repeatAttempts = 0; \/\/ Reset the attempts counter\n            currentWordIndex++;\n            setTimeout(startVocabularyLesson, 2000); \/\/ Move to next word after 2 seconds\n        } else {\n            repeatAttempts++;\n            if (repeatAttempts < 2) {\n                appendMessage(`That's not correct. Listen again: '${expectedWord}'. Now try again.`, 'bot');\n\n                \/\/ Split the message into parts\n                sayText(\"That's not correct. Listen again:\", 'en', function() {\n                    sayText(`${expectedWord}`, 'es', function() {\n                        sayText(\"Now try again.\", 'en', function() {\n                            setTimeout(() => {\n                                if (isSpeechRecognitionSupported) {\n                                    \/\/ Prompt user to repeat\n                                    appendMessage(`Please repeat after me: '${expectedWord}'`, 'bot');\n                                    sayText(\"Please repeat after me:\", \"en\", function() {\n                                        sayText(`${expectedWord}`, \"es\", function() {\n                                            listenUserResponse(expectedWord);\n                                        });\n                                    });\n                                } else {\n                                    \/\/ Focus the text input\n                                    document.getElementById('user-input').focus();\n                                }\n                            }, 500); \/\/ Small pause before prompt\n                        });\n                    });\n                });\n            } else {\n                const nextWordMessage = `You've tried twice. The correct word is '${expectedWord}'. Let's move on to the next word.`;\n                appendMessage(nextWordMessage, 'bot');\n                sayText(nextWordMessage, 'en'); \/\/ Feedback in English\n                repeatAttempts = 0; \/\/ Reset the attempts counter\n                currentWordIndex++;\n                setTimeout(startVocabularyLesson, 2000); \/\/ Move to next word after 2 seconds\n            }\n        }\n    }\n\n    function addWordToBox(word, translation) {\n        const wordBox = document.getElementById('word-box');\n        const wordElement = document.createElement('div');\n        wordElement.innerText = `'${word}' - '${translation}'`;\n        wordBox.appendChild(wordElement);\n    }\n\n    function endLesson(userStopped = false) {\n        let message;\n        if (userStopped) {\n            message = \"Thank you for learning today! I hope you enjoyed the lesson.\";\n        } else {\n            message = \"Well done! You've learned 20 words and phrases related to family. Keep practicing!\";\n        }\n        appendMessage(message, \"bot\");\n        sayText(message, \"en\"); \/\/ End feedback in English\n    }\n\n    function sayText(text, lang, callback) {\n        if (!speechSynthesisSupported) {\n            if (callback) callback();\n            return;\n        }\n        const utterance = new SpeechSynthesisUtterance(text);\n        utterance.lang = lang;\n        \/\/ Adjust rate and pitch for Spanish\n        if (lang.startsWith('es')) {\n            utterance.rate = 0.9;\n            utterance.pitch = 1.1;\n        } else {\n            utterance.rate = 1.0;\n            utterance.pitch = 1.0;\n        }\n        const voices = window.speechSynthesis.getVoices();\n        let selectedVoice = voices.find(voice => voice.lang === lang);\n        if (!selectedVoice) {\n            \/\/ Fallback to any voice that matches the language\n            selectedVoice = voices.find(voice => voice.lang.startsWith(lang));\n        }\n        if (selectedVoice) {\n            utterance.voice = selectedVoice;\n        }\n        utterance.onend = function() {\n            if (callback) callback();\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    <\/script>\n<\/body>\n<\/html>\n\n","protected":false},"excerpt":{"rendered":"<p>Spanish Vocabulary &#8211; Family Vocabulary Sentences Yes\/No Questions WH Questions Internactions Mira el vocabulario en esta caja Spanish Vocabulary &#8211; Family Submit Start Lesson Stop<\/p>\n","protected":false},"author":1,"featured_media":1430,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[40,34,33,36],"tags":[],"class_list":["post-1549","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-family","category-robots","category-spanish","category-spanish-vocabulary"],"featured_image_src":"https:\/\/phamho.com\/book\/wp-content\/uploads\/2024\/08\/163abc3a-5b10-4eb5-9562-b9ad98ada23d.webp","blog_images":{"medium":"https:\/\/phamho.com\/book\/wp-content\/uploads\/2024\/08\/163abc3a-5b10-4eb5-9562-b9ad98ada23d-300x300.webp","large":"https:\/\/phamho.com\/book\/wp-content\/uploads\/2024\/08\/163abc3a-5b10-4eb5-9562-b9ad98ada23d.webp"},"ams_acf":[],"_links":{"self":[{"href":"https:\/\/phamho.com\/book\/wp-json\/wp\/v2\/posts\/1549","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=1549"}],"version-history":[{"count":8,"href":"https:\/\/phamho.com\/book\/wp-json\/wp\/v2\/posts\/1549\/revisions"}],"predecessor-version":[{"id":1658,"href":"https:\/\/phamho.com\/book\/wp-json\/wp\/v2\/posts\/1549\/revisions\/1658"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/phamho.com\/book\/wp-json\/wp\/v2\/media\/1430"}],"wp:attachment":[{"href":"https:\/\/phamho.com\/book\/wp-json\/wp\/v2\/media?parent=1549"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/phamho.com\/book\/wp-json\/wp\/v2\/categories?post=1549"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/phamho.com\/book\/wp-json\/wp\/v2\/tags?post=1549"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}