Captions of the guide's speech
Updated
An AI Caption shows what the guide’s AI Speech To Text hears: her own lines spoken through the browser’s voice, and the Radio, which an AI Speech Capture marker selects for transcription.
Press Next line: the guide speaks with your browser's voice and her caption appears above her, also in the log. Transcribing the Radio needs the AI service, which this preview does not have: the log reports it instead. Drag outside the panel to orbit the camera.
Captions of the guide's speech
#pragma lifecycle(startup, dispose)
const LINES = [ 'Welcome to the museum. The first gallery is on your left.', 'This statue is older than the building around it.', 'Mind the step on your way to the garden.',];let voice;let next = 0;let stopTranscripts;
async function speakNext() { const text = LINES[next]; next = (next + 1) % LINES.length; try { await voice.speak({ text }); } catch (error) { log('Speech stopped:', error.message); }}
function startup() { const guide = findEntity('Guide'); voice = guide.getComponent(AITextToSpeechComponent); const stt = guide.getComponent(AISpeechToTextComponent);
guide.getComponent(AICaptionComponent).setProps({ fontSize: 26, color: '#fde68a', backgroundColor: 'rgba(15, 23, 42, 0.8)', billboard: true, });
// The text the captions show: the guide's lines and the marked Radio. stopTranscripts = stt.subscribeTranscripts((event) => { if (event.type === 'text' && event.final) log('caption:', event.text); if (event.type === 'error') log('Transcription problem:', event.message); });
on('guide/speak', (event) => { if (event.eventType === EventType.UIButton.Press) speakNext(); });}
function dispose() { if (stopTranscripts) stopTranscripts();}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.
SpokenCaptions.xrproj