{"id":347,"date":"2025-11-25T15:15:50","date_gmt":"2025-11-25T15:15:50","guid":{"rendered":"https:\/\/i-cte.org\/robot\/?p=347"},"modified":"2025-11-25T15:26:25","modified_gmt":"2025-11-25T15:26:25","slug":"people-listening","status":"publish","type":"post","link":"https:\/\/i-cte.org\/robot\/people-listening\/","title":{"rendered":"People &#8211; Listening"},"content":{"rendered":"\n<p>This Robot is used for practicing English at level A2. In order to interact with this Robot smoothly, please use a laptop, desktop, or iPad. Do not use Smartphones.<\/p>\n\n\n\n<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n    <meta charset=\"UTF-8\">\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n    <title>People &#8211; Listening<\/title>\n    <style>\n        \/* Reset and Base Styles *\/\n        * {\n            box-sizing: border-box;\n        }\n\n        body {\n            font-family: Arial, sans-serif;\n            background-color: #f4f6f8;\n            margin: 0;\n            padding: 0;\n            display: flex;\n            flex-direction: column;\n            min-height: 100vh;\n        }\n\n        \/* Menu Styles *\/\n        .menu {\n            width: 100%;\n            background-color: #28a745;\n            padding: 10px;\n            text-align: center;\n            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);\n            margin-bottom: 10px;\n            overflow-x: auto;\n            white-space: nowrap;\n        }\n        .menu a {\n            color: #fff;\n            text-decoration: none;\n            margin: 0 10px;\n            font-weight: bold;\n            font-size: 14px;\n            display: inline-block;\n        }\n        .menu a:hover,\n        .menu a:focus {\n            text-decoration: underline;\n            outline: 2px dashed #fff;\n            outline-offset: 4px;\n        }\n\n        \/* Container Styles *\/\n        .container {\n            display: flex;\n            flex-direction: column;\n            align-items: center;\n            padding: 10px;\n            box-sizing: border-box;\n            flex: 1 0 auto;\n            width: 100%;\n        }\n\n        .image-chat-wrapper {\n            display: flex;\n            flex-direction: column;\n            width: 100%;\n            max-width: 800px;\n            flex: 1;\n        }\n\n        .image-container {\n            flex: 1;\n            text-align: center;\n            margin-bottom: 15px;\n        }\n        .image-container img {\n            width: 100%;\n            height: auto;\n            max-height: 260px;\n            object-fit: cover;\n            border-radius: 15px;\n            box-shadow: 0 0 8px 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 #28a745;\n            border-radius: 8px;\n            box-shadow: 0 0 8px rgba(0, 0, 0, 0.1);\n            font-size: 15px;\n            font-weight: bold;\n            color: #28a745;\n            text-align: left;\n            max-height: 220px;\n            overflow-y: auto;\n        }\n\n        .audio-player {\n            margin-top: 10px;\n        }\n        .audio-player audio {\n            width: 100%;\n        }\n\n        .script-button {\n            margin-top: 8px;\n            background-color: #17a2b8;\n            color: #fff;\n            border: none;\n            border-radius: 5px;\n            padding: 8px 12px;\n            font-size: 14px;\n            font-weight: bold;\n            cursor: pointer;\n        }\n        .script-button:hover,\n        .script-button:focus {\n            background-color: #138496;\n            outline: none;\n        }\n\n        .chat-container {\n            background-color: #28a745;\n            border-radius: 15px;\n            box-shadow: 0 0 8px rgba(0, 0, 0, 0.1);\n            border: 3px solid #007bff;\n            overflow: hidden;\n            display: flex;\n            flex-direction: column;\n            height: auto;\n            max-height: 520px;\n            flex: 1;\n        }\n        .chat-header {\n            background-color: #1e7e34;\n            color: #fff;\n            padding: 12px;\n            text-align: center;\n            border-bottom: 1px solid #155724;\n            position: relative;\n        }\n        .chat-header h2 {\n            margin: 0;\n            font-size: 18px;\n        }\n        .chat-header .loader {\n            position: absolute;\n            right: 20px;\n            top: 50%;\n            transform: translateY(-50%);\n            display: none;\n        }\n        .chat-messages {\n            padding: 12px;\n            overflow-y: auto;\n            flex: 1;\n            background-color: #fff;\n            max-height: 340px;\n        }\n        .message {\n            margin-bottom: 10px;\n            padding: 10px;\n            border-radius: 6px;\n            font-size: 14px;\n            line-height: 1.5;\n        }\n        .bot-message {\n            background-color: #17a2b8;\n            color: #fff;\n            text-align: left;\n        }\n\n        .chat-input {\n            display: flex;\n            align-items: center;\n            background-color: #c3e6cb;\n            padding: 10px;\n            justify-content: space-between;\n            flex-wrap: wrap;\n        }\n        .send-button, .stop-button {\n            background-color: #17a2b8;\n            color: #fff;\n            font-weight: bold;\n            border: none;\n            border-radius: 5px;\n            padding: 12px 16px;\n            cursor: pointer;\n            transition: background-color 0.3s;\n            flex: 1;\n            margin: 6px;\n            max-width: 150px;\n            font-size: 16px;\n        }\n        .stop-button {\n            background-color: #dc3545;\n        }\n        .send-button:hover,\n        .stop-button:hover,\n        .send-button:focus,\n        .stop-button:focus {\n            background-color: #218838;\n            outline: none;\n        }\n\n        .voice-selection {\n            margin: 10px 0;\n            width: 100%;\n            max-width: 300px;\n        }\n        .voice-selection label {\n            display: block;\n            margin-bottom: 5px;\n            font-weight: bold;\n            color: #333;\n        }\n        .voice-selection select {\n            width: 100%;\n            padding: 8px;\n            border-radius: 5px;\n            border: 1px solid #ccc;\n            font-size: 14px;\n        }\n\n        .loader {\n            border: 4px solid #f3f3f3;\n            border-top: 4px solid #17a2b8;\n            border-radius: 50%;\n            width: 20px;\n            height: 20px;\n            animation: spin 2s linear infinite;\n            display: inline-block;\n            margin-left: 10px;\n        }\n\n        @keyframes spin {\n            0% { transform: rotate(0deg); }\n            100% { transform: rotate(360deg); }\n        }\n\n        \/* Responsive *\/\n        @media (orientation: portrait) {\n            .image-chat-wrapper {\n                flex-direction: column;\n            }\n            .image-container, .chat-container {\n                width: 100%;\n                max-width: 100%;\n            }\n        }\n\n        @media (orientation: landscape) and (min-width: 600px) {\n            .image-chat-wrapper {\n                flex-direction: row;\n                justify-content: space-between;\n            }\n            .image-container, .chat-container {\n                width: 48%;\n                max-width: 48%;\n            }\n            .word-box {\n                max-height: 200px;\n            }\n            .chat-header h2 {\n                font-size: 20px;\n            }\n            .message {\n                font-size: 15px;\n            }\n            .send-button, .stop-button {\n                font-size: 18px;\n                padding: 14px 20px;\n                max-width: 200px;\n            }\n        }\n\n        @media (max-width: 768px) {\n            .chat-header h2 {\n                font-size: 16px;\n            }\n            .message {\n                font-size: 14px;\n            }\n            .send-button, .stop-button {\n                font-size: 16px;\n                padding: 12px 16px;\n                max-width: 150px;\n            }\n            .word-box {\n                font-size: 15px;\n            }\n            .voice-selection select {\n                font-size: 14px;\n            }\n        }\n\n        @media only screen and (max-device-width: 480px) and (-webkit-min-device-pixel-ratio: 2) {\n            .chat-header h2 {\n                font-size: 18px;\n            }\n            .send-button, .stop-button {\n                padding: 14px 18px;\n                font-size: 16px;\n            }\n            .message {\n                font-size: 14px;\n            }\n            .word-box {\n                font-size: 16px;\n            }\n        }\n    <\/style>\n<\/head>\n<body>\n    <div class=\"menu\">\n      <a href=\"https:\/\/i-cte.org\/robot\/people-conversation\/\">Conversation<\/a>\n      <a href=\"https:\/\/i-cte.org\/robot\/people-vocabulary\/\">Vocabulary<\/a>\n      <a href=\"https:\/\/i-cte.org\/robot\/people-real-life\/\">Real Life<\/a>\n      <a href=\"https:\/\/i-cte.org\/robot\/people-describing-pictures\/\">Describing Pictures<\/a>\n      <a href=\"https:\/\/i-cte.org\/robot\/people-reading-comprehension\/\">Reading<\/a>\n      <a href=\"https:\/\/i-cte.org\/robot\/people-listening\/\">Listening<\/a>\n    <\/div>\n\n    <div class=\"container\">\n        <div class=\"image-chat-wrapper\">\n            <div class=\"image-container\">\n                <img decoding=\"async\" src=\"https:\/\/i-cte.org\/robot\/wp-content\/uploads\/2025\/11\/family.png\"\n                     alt=\"Ruth from the U.S. describing her family\">\n                <div class=\"sentence-text\">\n                    Listen to Ruth from the U.S. describe her family. Then choose the picture and answer T\/F.\n                <\/div>\n\n                <div class=\"audio-player\">\n                    <!-- Change src to the real URL of BTP_L1_SB_060.mp3 on your site -->\n                    <audio id=\"ruth-audio\" controls>\n                        <source src=\"\/mnt\/data\/BTP_L1_SB_060.mp3\" type=\"audio\/mpeg\">\n                        Your browser does not support the audio element.\n                    <\/audio>\n                <\/div>\n\n                <!-- Button to play the script with robot voices -->\n                <button id=\"play-script-btn\" class=\"script-button\" type=\"button\">\n                    Play Script (Robot Voices)\n                <\/button>\n\n                <div id=\"word-box\" class=\"word-box\">\n                    1. Which picture shows Ruth\u2019s parents? A, B, C, or D?<br>\n                    2. Listen again and write T (true) or F (false) for each statement:<br>\n                    1) Ruth has two sisters.<br>\n                    2) Her father is hard-working.<br>\n                    3) He has a difficult job.<br>\n                    4) He isn\u2019t very generous.<br>\n                    5) Her mother is not very outgoing.<br>\n                    6) Her mother is kind.<br>\n                    7) Ruth talks to her mother about her problems.<br>\n                    8) Ruth thinks she looks like her mother.\n                <\/div>\n            <\/div>\n\n            <div class=\"chat-container\">\n                <div class=\"chat-header\">\n                    <h2>People &#8211; Listening<\/h2>\n                    <div class=\"loader\" id=\"synthesis-loader\"><\/div>\n                <\/div>\n                <div class=\"chat-messages\" id=\"chat-messages\">\n                    <!-- Questions will appear here -->\n                <\/div>\n                <div class=\"chat-input\">\n                    <div class=\"voice-selection\">\n                        <label for=\"voice-select\">Choose Voice for Feedback:<\/label>\n                        <select id=\"voice-select\" aria-label=\"Select Voice\">\n                            <option value=\"\">Loading voices&#8230;<\/option>\n                        <\/select>\n                    <\/div>\n                    <button id=\"start-btn\" class=\"send-button\" aria-label=\"Check Answers\">Check Answers<\/button>\n                    <button id=\"stop-btn\" class=\"stop-button\" aria-label=\"Stop Voice\">Stop Voice<\/button>\n                <\/div>\n            <\/div>\n        <\/div>\n    <\/div>\n\n    <div class=\"menu\">\n      <a href=\"https:\/\/i-cte.org\/robot\/people-conversation\/\">Conversation<\/a>\n      <a href=\"https:\/\/i-cte.org\/robot\/people-vocabulary\/\">Vocabulary<\/a>\n      <a href=\"https:\/\/i-cte.org\/robot\/people-real-life\/\">Real Life<\/a>\n      <a href=\"https:\/\/i-cte.org\/robot\/people-describing-pictures\/\">Describing Pictures<\/a>\n      <a href=\"https:\/\/i-cte.org\/robot\/people-reading-comprehension\/\">Reading<\/a>\n      <a href=\"https:\/\/i-cte.org\/robot\/people-listening\/\">Listening<\/a>\n    <\/div>\n\n<script>\n\/* ============================\n   Listening \u2013 Ruth\u2019s family\n   ============================ *\/\n\n\/* Audio script (Interviewer = I, Ruth = R) *\/\nconst listeningScript = `I: Ruth, what can you tell me about your family?\nR: Well, there are three of us: my mom, my dad, and me. I don\u2019t have any brothers or sisters.\nI: OK. Your dad, for example. What\u2019s he like? Is he hard-working?\nR: Well, yes, but he isn\u2019t working right now. He\u2019s looking for a job. He\u2019s very generous, though, when he has money.\nI: What does he look like?\nR: He\u2019s fairly tall, and he has short black hair. He has a mustache, too, and, er \u2026 oh, yes, he\u2019s fairly slim.\nI: And your mom? What about her? What\u2019s she like?\nR: She\u2019s very outgoing and kind. When I have a problem, I know I can talk to her.\nI: Do you look like your mom?\nR: People say we look like each other, but I don\u2019t think so! She\u2019s forty-five and I\u2019m only twenty. I guess it\u2019s because we\u2019re both tall and we have short brown hair.\nI: Do you have a picture of them?\nR: Yes, here you are.\nI: Thanks. Oh, yes, I see \u2026`;\n\n\/* \ud83d\udd11 ANSWER KEY \u2013 matches the script *\/\nconst correctPicture = \"C\"; \/\/ change to correct letter if needed\n\nconst tfStatements = [\n  { id: 1, text: \"Ruth has two sisters.\",          correct: \"f\" },\n  { id: 2, text: \"Her father is hard-working.\",    correct: \"t\" },\n  { id: 3, text: \"He has a difficult job.\",        correct: \"f\" }, \/\/ not working now\n  { id: 4, text: \"He isn\u2019t very generous.\",        correct: \"f\" }, \/\/ he is very generous\n  { id: 5, text: \"Her mother is not very outgoing.\", correct: \"f\" },\n  { id: 6, text: \"Her mother is kind.\",            correct: \"t\" },\n  { id: 7, text: \"Ruth talks to her mother about her problems.\", correct: \"t\" },\n  { id: 8, text: \"Ruth thinks she looks like her mother.\",       correct: \"f\" }\n];\n\nconst summaryMessages = [\n  \"Nice listening! Keep going.\",\n  \"Good job. Listen again and try to improve your score.\",\n  \"You\u2019re doing well. Practice this activity again later.\"\n];\n\nconst positiveMessages = [\n  \"Excellent comprehension!\",\n  \"Great work! You understood Ruth\u2019s description.\",\n  \"Very good! Your answers match the audio.\"\n];\n\n\/* Speech synthesis *\/\nconst speechSynthesisSupported = \"speechSynthesis\" in window;\nlet voices = [];\nlet selectedVoice = null; \/\/ for feedback\nlet maleVoice = null;     \/\/ for I:\nlet femaleVoice = null;   \/\/ for R:\n\nconst desiredVoiceNames = [\n  \"Google US English\",\n  \"Google US English Female\",\n  \"Google UK English Male\",\n  \"Google UK English Female\"\n];\n\n\/* ========== INITIALISE ========== *\/\n\nfunction initialize() {\n  loadVoices();\n\n  if (!speechSynthesisSupported) {\n    appendMessage(\"Sorry, your browser does not support speech synthesis.\", \"bot\");\n  }\n\n  document.getElementById(\"start-btn\").onclick = checkAnswers;\n  document.getElementById(\"stop-btn\").onclick = stopSpeaking;\n  document.getElementById(\"play-script-btn\").onclick = playScript;\n\n  buildTasks();\n  const intro =\n    \"First, listen to Ruth talk about her family without stopping. Then listen again and answer the questions.\";\n  appendMessage(intro, \"bot\");\n  if (speechSynthesisSupported) {\n    showSynthesisLoader(true);\n    sayText(intro, \"en-US\").then(() => showSynthesisLoader(false));\n  }\n}\n\n\/* ========== VOICES ========== *\/\n\nfunction loadVoices() {\n  if (!speechSynthesisSupported) return;\n  voices = window.speechSynthesis.getVoices();\n  if (voices.length === 0) {\n    window.speechSynthesis.onvoiceschanged = () => {\n      voices = window.speechSynthesis.getVoices();\n      populateVoiceList();\n    };\n  } else {\n    populateVoiceList();\n  }\n}\n\nfunction chooseDialogueVoices(filteredVoices) {\n  \/\/ try to pick explicit male\/female voices\n  maleVoice =\n    filteredVoices.find(v => \/male\/i.test(v.name)) ||\n    filteredVoices.find(v => \/UK English Male\/i.test(v.name)) ||\n    null;\n\n  femaleVoice =\n    filteredVoices.find(v => \/female\/i.test(v.name)) ||\n    filteredVoices.find(v => \/US English\/i.test(v.name) && !\/Male\/i.test(v.name)) ||\n    null;\n\n  \/\/ Fallbacks if not found\n  if (!maleVoice && filteredVoices.length > 0) {\n    maleVoice = filteredVoices[0];\n  }\n  if (!femaleVoice) {\n    femaleVoice = filteredVoices.find(v => v !== maleVoice) || maleVoice;\n  }\n}\n\nfunction populateVoiceList() {\n  const voiceSelect = document.getElementById(\"voice-select\");\n  voiceSelect.innerHTML = \"\";\n\n  if (!speechSynthesisSupported) {\n    const option = document.createElement(\"option\");\n    option.value = \"\";\n    option.textContent = \"No voices available\";\n    voiceSelect.appendChild(option);\n    voiceSelect.disabled = true;\n    return;\n  }\n\n  const filteredVoices = voices.filter((voice) =>\n    desiredVoiceNames.includes(voice.name) || voice.lang.startsWith(\"en-\")\n  );\n\n  if (filteredVoices.length === 0) {\n    const option = document.createElement(\"option\");\n    option.value = \"\";\n    option.textContent = \"Default browser voice\";\n    voiceSelect.appendChild(option);\n    voiceSelect.disabled = true;\n    return;\n  }\n\n  filteredVoices.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  \/\/ feedback voice = first voice by default\n  voiceSelect.selectedIndex = 0;\n  selectedVoice = filteredVoices[0];\n\n  \/\/ choose male \/ female for the dialogue\n  chooseDialogueVoices(filteredVoices);\n\n  voiceSelect.onchange = () => {\n    const selectedIndex = voiceSelect.value;\n    selectedVoice = filteredVoices[selectedIndex];\n  };\n}\n\n\/* ========== UI: QUESTIONS ========== *\/\n\nfunction buildTasks() {\n  const chat = document.getElementById(\"chat-messages\");\n  chat.innerHTML = \"\";\n\n  \/\/ Part 1 \u2013 Picture choice\n  const p1Title = document.createElement(\"h3\");\n  p1Title.textContent = \"Part 1 \u2013 Which picture shows Ruth\u2019s parents?\";\n  p1Title.style.margin = \"4px 0\";\n  p1Title.style.fontSize = \"16px\";\n  chat.appendChild(p1Title);\n\n  const p1Instr = document.createElement(\"p\");\n  p1Instr.textContent = \"Choose A, B, C, or D.\";\n  chat.appendChild(p1Instr);\n\n  const pictureBlock = document.createElement(\"div\");\n  pictureBlock.style.marginBottom = \"10px\";\n\n  [\"A\", \"B\", \"C\", \"D\"].forEach((letter) => {\n    const label = document.createElement(\"label\");\n    label.style.marginRight = \"15px\";\n    label.style.cursor = \"pointer\";\n\n    const input = document.createElement(\"input\");\n    input.type = \"radio\";\n    input.name = \"picture-choice\";\n    input.value = letter;\n    input.style.marginRight = \"4px\";\n\n    label.appendChild(input);\n    label.appendChild(document.createTextNode(\" \" + letter));\n    pictureBlock.appendChild(label);\n  });\n\n  const picFeedback = document.createElement(\"div\");\n  picFeedback.id = \"picture-feedback\";\n  picFeedback.style.fontSize = \"13px\";\n  picFeedback.style.marginTop = \"4px\";\n  pictureBlock.appendChild(picFeedback);\n\n  chat.appendChild(pictureBlock);\n\n  \/\/ Part 2 \u2013 T\/F table\n  const p2Title = document.createElement(\"h3\");\n  p2Title.textContent = \"Part 2 \u2013 Listen again and write T (true) or F (false).\";\n  p2Title.style.marginTop = \"8px\";\n  p2Title.style.fontSize = \"16px\";\n  chat.appendChild(p2Title);\n\n  const tfTable = document.createElement(\"table\");\n  tfTable.style.width = \"100%\";\n  tfTable.style.borderCollapse = \"collapse\";\n  tfTable.style.marginTop = \"10px\";\n  tfTable.style.fontSize = \"14px\";\n\n  const headerRow = document.createElement(\"tr\");\n  [\"Sentence\", \"T\", \"F\"].forEach((head) => {\n    const th = document.createElement(\"th\");\n    th.textContent = head;\n    th.style.borderBottom = \"1px solid #ccc\";\n    th.style.padding = \"4px\";\n    th.style.textAlign = head === \"Sentence\" ? \"left\" : \"center\";\n    headerRow.appendChild(th);\n  });\n  tfTable.appendChild(headerRow);\n\n  tfStatements.forEach((stmt) => {\n    const row = document.createElement(\"tr\");\n    row.id = `tf-row-${stmt.id}`;\n\n    const textCell = document.createElement(\"td\");\n    textCell.textContent = stmt.text;\n    textCell.style.padding = \"4px\";\n    textCell.style.verticalAlign = \"top\";\n    row.appendChild(textCell);\n\n    [\"t\", \"f\"].forEach((value) => {\n      const cell = document.createElement(\"td\");\n      cell.style.textAlign = \"center\";\n      cell.style.padding = \"4px\";\n\n      const label = document.createElement(\"label\");\n      label.style.cursor = \"pointer\";\n\n      const input = document.createElement(\"input\");\n      input.type = \"radio\";\n      input.name = `tf${stmt.id}`;\n      input.value = value;\n      input.style.marginRight = \"4px\";\n\n      label.appendChild(input);\n      label.appendChild(document.createTextNode(\"\"));\n      cell.appendChild(label);\n      row.appendChild(cell);\n    });\n\n    tfTable.appendChild(row);\n  });\n\n  chat.appendChild(tfTable);\n}\n\n\/* ========== CHECK ANSWERS ========== *\/\n\nfunction checkAnswers() {\n  let score = 0;\n  let total = tfStatements.length + 1; \/\/ +1 for picture question\n  let unanswered = 0;\n\n  \/\/ Picture\n  const selectedPic = document.querySelector('input[name=\"picture-choice\"]:checked');\n  const picFeedback = document.getElementById(\"picture-feedback\");\n\n  if (!selectedPic) {\n    unanswered++;\n    picFeedback.textContent = \"Please choose A, B, C, or D.\";\n    picFeedback.style.color = \"#856404\";\n  } else if (selectedPic.value === correctPicture) {\n    score++;\n    picFeedback.textContent = \"Correct. Picture \" + correctPicture + \" shows Ruth\u2019s parents.\";\n    picFeedback.style.color = \"#155724\";\n  } else {\n    picFeedback.textContent = \"Not quite. The answer is picture \" + correctPicture + \".\";\n    picFeedback.style.color = \"#721c24\";\n  }\n\n  \/\/ T\/F\n  tfStatements.forEach((stmt) => {\n    const row = document.getElementById(`tf-row-${stmt.id}`);\n    if (row) row.style.backgroundColor = \"\";\n\n    const chosen = document.querySelector(`input[name=\"tf${stmt.id}\"]:checked`);\n    if (!chosen) {\n      unanswered++;\n      if (row) row.style.backgroundColor = \"#fff3cd\"; \/\/ yellow\n      return;\n    }\n\n    if (chosen.value === stmt.correct) {\n      score++;\n      if (row) row.style.backgroundColor = \"#d4edda\"; \/\/ green\n    } else {\n      if (row) row.style.backgroundColor = \"#f8d7da\"; \/\/ red\n    }\n  });\n\n  const resultMessage =\n    `You got ${score} out of ${total} items correct.` +\n    (unanswered > 0 ? ` (${unanswered} item(s) not answered.)` : \"\");\n\n  appendMessage(resultMessage, \"bot\");\n\n  let extra;\n  if (score === total && unanswered === 0) {\n    extra = \"Perfect score! \" + positiveMessages[Math.floor(Math.random() * positiveMessages.length)];\n  } else if (score >= Math.round(total * 0.7)) {\n    extra = positiveMessages[Math.floor(Math.random() * positiveMessages.length)];\n  } else {\n    extra = summaryMessages[Math.floor(Math.random() * summaryMessages.length)];\n  }\n\n  appendMessage(extra, \"bot\");\n\n  if (speechSynthesisSupported) {\n    showSynthesisLoader(true);\n    sayText(resultMessage + \" \" + extra, \"en-US\").then(() => {\n      showSynthesisLoader(false);\n    });\n  }\n}\n\n\/* ========== SCRIPT PLAYER WITH TWO VOICES ========== *\/\n\nfunction playScript() {\n  if (!speechSynthesisSupported) {\n    appendMessage(\"Your browser cannot play the script with robot voices.\", \"bot\");\n    return;\n  }\n  if (!maleVoice || !femaleVoice) {\n    appendMessage(\"Voices are still loading. Please wait a moment and try again.\", \"bot\");\n    loadVoices();\n    return;\n  }\n\n  stopSpeaking();\n  showSynthesisLoader(true);\n\n  const lines = listeningScript.split(\"\\n\").map(l => l.trim()).filter(l => l.length > 0);\n\n  function speakLine(index) {\n    if (index >= lines.length) {\n      showSynthesisLoader(false);\n      return;\n    }\n\n    let line = lines[index];\n    let voiceForLine = selectedVoice || voices[0];\n    let text = line;\n\n    if (line.startsWith(\"I:\")) {\n      text = line.replace(\/^I:\\s*\/, \"\");\n      voiceForLine = maleVoice || voiceForLine;\n    } else if (line.startsWith(\"R:\")) {\n      text = line.replace(\/^R:\\s*\/, \"\");\n      voiceForLine = femaleVoice || voiceForLine;\n    }\n\n    const utterance = new SpeechSynthesisUtterance(text);\n    utterance.lang = \"en-US\";\n    utterance.rate = 1.0;\n    utterance.pitch = 1.0;\n    utterance.voice = voiceForLine;\n\n    utterance.onend = function () {\n      speakLine(index + 1);\n    };\n    utterance.onerror = function () {\n      speakLine(index + 1);\n    };\n\n    window.speechSynthesis.speak(utterance);\n  }\n\n  speakLine(0);\n}\n\n\/* ========== GENERIC SPEECH HELPERS (feedback) ========== *\/\n\nfunction stopSpeaking() {\n  if (speechSynthesisSupported) {\n    window.speechSynthesis.cancel();\n    showSynthesisLoader(false);\n  }\n}\n\nfunction sayText(text, lang) {\n  return new Promise((resolve) => {\n    if (!speechSynthesisSupported) {\n      resolve();\n      return;\n    }\n    const utterance = new SpeechSynthesisUtterance(text);\n    utterance.lang = lang;\n    utterance.rate = 1.0;\n    utterance.pitch = 1.0;\n\n    if (selectedVoice) {\n      utterance.voice = selectedVoice;\n    }\n\n    utterance.onend = function () {\n      resolve();\n    };\n    utterance.onerror = function () {\n      resolve();\n    };\n\n    window.speechSynthesis.speak(utterance);\n  });\n}\n\n\/* ========== UI HELPERS ========== *\/\n\nfunction 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(\"bot-message\");\n  messageElement.innerText = text;\n  messageContainer.appendChild(messageElement);\n  messageContainer.scrollTop = messageContainer.scrollHeight;\n}\n\nfunction showSynthesisLoader(show) {\n  const loader = document.getElementById(\"synthesis-loader\");\n  loader.style.display = show ? \"inline-block\" : \"none\";\n  if (show) {\n    loader.style.borderTop = \"4px solid #17a2b8\";\n  }\n}\n\nwindow.onload = initialize;\n<\/script>\n<\/body>\n<\/html>\n\n","protected":false},"excerpt":{"rendered":"<p>This Robot is used for practicing English at level A2. In order to interact with this Robot smoothly, please use<\/p>\n","protected":false},"author":1,"featured_media":182,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"colormag_page_layout":"default_layout","footnotes":""},"categories":[18,5],"tags":[],"class_list":["post-347","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-a2","category-chatbot"],"_links":{"self":[{"href":"https:\/\/i-cte.org\/robot\/wp-json\/wp\/v2\/posts\/347","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/i-cte.org\/robot\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/i-cte.org\/robot\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/i-cte.org\/robot\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/i-cte.org\/robot\/wp-json\/wp\/v2\/comments?post=347"}],"version-history":[{"count":1,"href":"https:\/\/i-cte.org\/robot\/wp-json\/wp\/v2\/posts\/347\/revisions"}],"predecessor-version":[{"id":348,"href":"https:\/\/i-cte.org\/robot\/wp-json\/wp\/v2\/posts\/347\/revisions\/348"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/i-cte.org\/robot\/wp-json\/wp\/v2\/media\/182"}],"wp:attachment":[{"href":"https:\/\/i-cte.org\/robot\/wp-json\/wp\/v2\/media?parent=347"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/i-cte.org\/robot\/wp-json\/wp\/v2\/categories?post=347"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/i-cte.org\/robot\/wp-json\/wp\/v2\/tags?post=347"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}