Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <!-- Container for the VTutor UI -->
<div class="container relative z-10 flex flex-col gap-2.5 p-5 bg-white bg-opacity-90 rounded-lg max-w-xl mx-auto">
  <div class="input-container flex flex-col gap-2.5">
    <!-- Dropdown for loading multilingual examples -->
    <select id="exampleDropdown" class="w-full p-2 border border-gray-300 rounded-md mb-2">
      <option value="">Load an example...</option>
    </select>

    <!-- Text area for user input -->
    <textarea id="textInput" rows="4" placeholder="Enter text for VTutor to speak..." class="w-full p-2 border border-gray-300 rounded-md resize-none"></textarea>

    <!-- Speak button -->
    <button id="speakButton" class="w-full p-2 bg-blue-500 text-white rounded-md transition-colors duration-200 hover:bg-blue-700 mt-2">
      Speak
    </button>

    <!-- Stop speaking button (initially hidden) -->
    <button id="stopButton" class="w-full p-2 text-white rounded-md bg-red-500 hover:bg-red-700 mt-2" style="display: none">
      Stop Speaking
    </button>

    <!-- Button to reload last spoken text -->
    <button id="againButton" class="w-full p-2 text-white rounded-md bg-gray-700 hover:bg-gray-800 mt-2">
      Load again
    </button>
  </div>
</div>

<!-- Iframe to load the VTutor Unity WebGL application -->
<iframe src="http://full.iframe.sdk.vtutor.tools" id="unity-iframe" class="unity-frame"></iframe>
              
            
!

CSS

              
                .unity-frame {
  position: fixed;
  bottom: 0;
  right: 0;
  width: 50vw;
  height: 100vh;
  border: none;
  z-index: 20;
}

              
            
!

JS

              
                const textInput = document.getElementById("textInput");
const speakButton = document.getElementById("speakButton");
const againButton = document.getElementById("againButton");
const stopButton = document.getElementById("stopButton");
const exampleDropdown = document.getElementById("exampleDropdown");
const unityIframe = document.getElementById("unity-iframe");

let lastSpokenText = ""; // Store the last spoken message

// Trigger VTutor to speak
speakButton.addEventListener("click", () => {
  const message = textInput.value;
  lastSpokenText = message;
  if (unityIframe && unityIframe.contentWindow) {
    unityIframe.contentWindow.postMessage(
      { action: "unitySpeak", message: message },
      "*"
    );
    stopButton.style.display = "block";
    speakButton.style.display = "none";
  }
});

// Reload the last spoken text into the input area
againButton.addEventListener("click", () => {
  if (lastSpokenText) {
    textInput.value = lastSpokenText;
  }
});

// Stop the speaking avatar
stopButton.addEventListener("click", () => {
  if (unityIframe && unityIframe.contentWindow) {
    unityIframe.contentWindow.postMessage({ action: "stopSpeaking" }, "*");
  }
});

// Handle messages from the Unity iframe
const handleIframeMessage = (event) => {
  if (event.data.type === "IFRAME_CLICK") {
    const { x, y } = event.data;
    unityIframe.style.pointerEvents = "none";
    const underlyingElements = document.elementsFromPoint(x, y);
    for (let element of underlyingElements) {
      if (element instanceof HTMLElement) {
        element.click();
        element.focus();
      }
    }
  } else if (event.data.type === "VTuber_Message_Delivery_Complete") {
    stopButton.style.display = "none";
    speakButton.style.display = "block";
  }
};

window.addEventListener("message", handleIframeMessage);

// Populate dropdown with multilingual examples
const examples = {
  "What is VTutor (English)": `VTutor is an open-source Software Development Kit.\nIt is designed to integrate Animated Pedagogical Agents with generative AI capabilities into web applications.`
  // ... (other languages omitted for brevity)
};

Object.keys(examples).forEach((key) => {
  const option = document.createElement("option");
  option.value = examples[key].replaceAll("  ", "");
  option.textContent = key;
  exampleDropdown.appendChild(option);
});

// Set initial example on load
exampleDropdown.selectedIndex = 1;
textInput.value = Object.values(examples)[0];

              
            
!
999px

Console