Speak with the browser's voice
Updated
An AI agent’s Text To Speech on the WebAPI provider speaks a line when a UI button is pressed, using the browser’s own voices: no AI service is needed.
Press Speak to hear the guide. The voices are the browser's own, so they differ between browsers and systems. Drag to orbit the camera, scroll to zoom.
Speak with the browser's voice
#pragma lifecycle(startup)
let voice;
async function listVoices() { try { const offer = await voice.getCapabilities(new AbortController().signal); log('Voices offered by this browser:', offer.voices.length); } catch (error) { log('Could not read the voices:', error.message); }}
async function welcome() { try { await voice.speak({ text: 'Welcome to the gallery. Ask me anything about the paintings.' }); log('Finished speaking.'); } catch (error) { log('Speech stopped:', error.message); }}
function startup() { voice = findEntity('Guide').getComponent(AITextToSpeechComponent); log('Speaking with the', voice.props.provider, 'provider'); listVoices();
on('kiosk/speak', (event) => { if (event.eventType === EventType.UIButton.Press) welcome(); });}How it works
Section titled “How it works”The script is explained step by step in Speak with the browser’s voice.
Open it in XR Creator
Section titled “Open it in XR Creator”Download the project file below, then import it in XR Hub with Projects › New › Import, as described in Projects and templates. It opens in XR Creator with the same scene you see running above, each script already attached to its Behavior entity. From there you can edit the scripts, adjust components and their props, preview your changes, and deploy the result as a world of your own.
BrowserVoice.xrproj