This directory contains a set of sample apps built with the xg.glass SDK, to help developers quickly understand:
- How to use the unified APIs across different smart glasses
- How to build, install, and run a working glasses app from a single Kotlin entry file
These samples target xg.glass SDK 0.3.0.
If you're new to the SDK, start with the main documentation (see developer guide).
| Example | What it demonstrates | Run command |
|---|---|---|
photo_translator |
Capture a photo, call an OpenAI-compatible vision model, and display the translation. | xg-glass run photo_translator/PhotoTranslatorEntry.kt --sdk /path/to/xg-glass-sdk |
exam_solver |
Auto-capture loop with streaming AI answers and conversation memory. | xg-glass run exam_solver/ExamSolverEntry.kt --sdk /path/to/xg-glass-sdk |
teleprompter |
Simulator-runnable display teleprompter with streaming/paged display degradation and tap/long-press controls. | xg-glass run teleprompter/TeleprompterEntry.kt --sim --sdk /path/to/xg-glass-sdk |
voice_notes |
Simulator-runnable microphone capture with transcription when AI settings are configured, otherwise an honest audio summary. | xg-glass run voice_notes/VoiceNotesEntry.kt --sim --sdk /path/to/xg-glass-sdk |
ai_assistant |
Standalone simulator phone-host app: video stream awareness, latest-frame snapshot on tap/button, OpenAI-compatible vision answer, and display on glasses. | cd ai_assistant && xg-glass run --sim --local_video /path/to/sample.mp4 |
play_feature_delivery |
Standalone Android App Bundle sample that keeps Even + Simulator in the base app and loads the Meta adapter through an on-demand Play Feature Delivery split. | cd play_feature_delivery && ./gradlew :app:bundleDebug |
Install the CLI and clone the SDK checkout once:
pip install xg-glass
git clone https://github.com/hkust-spark/xg-glass-sdkThe SDK checkout is needed when the PyPI-installed CLI runs a single Kotlin entry file. In the examples below, replace /path/to/xg-glass-sdk with your checkout path. If you are running from inside an SDK checkout, the same commands still work without --sdk.
Location: xg-glass-sample/photo_translator
This sample demonstrates a minimal end-to-end flow: capture photo → LLM translate → display on glasses.
- Capture a photo from the glasses camera
- Encode the image as base64 and call OpenAI Chat Completions for image-text translation
- Display the translated result on the glasses
Run the single-file entry directly from this directory:
cd xg-glass-sample/photo_translator
xg-glass run PhotoTranslatorEntry.kt --sdk /path/to/xg-glass-sdkNotes:
xg-glassis installed withpip install xg-glass; for PyPI installs, pass--sdk /path/to/xg-glass-sdkwhen running a single.ktentry.- Before running, replace
YOUR_OPENAI_API_KEY_HEREinPhotoTranslatorEntry.ktwith your own key (this is a placeholder; for real apps, inject secrets securely).
In PhotoTranslatorEntry.kt, the core logic that implements capture → translate → display is essentially just the snippet below (you only need ~10 lines like this to build the full app):
override suspend fun run(ctx: UniversalAppContext): Result<Unit> {
val img = ctx.client.capturePhoto().getOrThrow()
val b64 = Base64.getEncoder().encodeToString(img.jpegBytes)
val req = chatCompletionRequest {
model = ModelId("gpt-4o-mini")
messages { user { content { text("Translate the text in this image to Chinese. Output only the result."); image("data:image/jpeg;base64,$b64") } } }
}
val text = openAI.chatCompletion(req).choices.firstOrNull()?.message?.content.orEmpty().ifBlank { "No text" }
return ctx.client.display(text, DisplayOptions())
}Location: xg-glass-sample/ai_assistant
This standalone Android phone-host app demonstrates the flagship video-stream loop: connect to simulator glasses, start a LOW-tier camera stream, capture the latest stream frame when the glasses tap event or phone button fires, send it to an OpenAI-compatible vision endpoint, and display the answer on the glasses.
Configuration lives in untracked ai_assistant/local.properties or environment variables:
ai.baseUrl=http://10.0.2.2:8765/v1
ai.apiKey=mock-key
ai.model=mock-visionThe endpoint must accept POST /v1/chat/completions with an image_url data URL. OpenAI, DashScope's OpenAI-compatible mode, and Ollama's OpenAI-compatible API can be used by changing ai.baseUrl, ai.apiKey, and ai.model. If any setting is missing, the app logs and displays a clear configuration message and does not crash.
Run hardware-free on an emulator:
cd xg-glass-sample/ai_assistant
xg-glass run --sim --local_video /path/to/sample.mp4Without --local_video, the simulator uses the emulator camera. The sample was verified against a local mock endpoint; any OpenAI-compatible provider with vision support should work.