A VegaOS TV app that teaches you another language while you watch.
This app is a proof of concept that streams a small catalogue of videos. The user will first complete a quiz and thereafter watch a video with the English translations removed.
- Gemini for video subtitle transcription and translation
- React Native with Typescript for app development
- GitHub Pages to host the videos, captions and lexicons
- Cloudflared to test a local backend
- Install node.js through the website or command line.
- Clone this repository and open the project in VS Code.
- Install the Vega Studio plugin.
- Install the app's node packages, in the project root:
npm i- Install the backend's node packages:
cd backend
npm i- [Stream from local media] Only to run your own backend (see below): install cloudflared. This sets up a tunnel so the emulator can stream videos from your computer.
- Windows:
winget install --id Cloudflare.cloudflared - Mac:
brew install cloudflared(install Homebrew first)
- Windows:
- Install
ffmpegif you will make captions (see below).
-
The catalogue (each video's id, title, length in seconds, HSK level and credit) is
backend/catalogue.json. Put each catalogue video in its own folder,backend/media/<id>/, asvideo.mp4, with its thumbnail asthumbnail.jpg. -
Put the dictionaries that each video's lexicon (its teachable words) is made from in
backend/data:cedict_ts.u8: CC-CEDICT, unzipped from https://www.mdbg.net/chinese/dictionary?page=cc-cedicthsk.tsv: the HSK 3.0 word list, oneword<TAB>levelline per word (levels 7 to 9 can be written as 7)
-
Make the captions ahead of time. In
backend, runMac / Linux / Git Bash:
GEMINI_API_KEY=YOUR_API_KEY GEMINI_MODEL=YOUR_GEMINI_MODEL npm run captions
Windows PowerShell:
$env:GEMINI_API_KEY="YOUR_API_KEY"; $env:GEMINI_MODEL="YOUR_GEMINI_MODEL"; npm run captions
This captions every catalogue video that has none yet, and saves
captions.jsonandlexicon.jsonbeside each video.npm run captions -- <id>remakes one video's captions and lexicon (this overwrites hand fixes). -
Check each video's captions by eye: the script prints every line's timings. Play the video and fix any line that starts or ends at the wrong moment in its
captions.json(startandendare seconds). -
Skim each
lexicon.jsonand fix any bad gloss by hand.npm run lexicon -- <id>inbackendremakes one from its captions and prints it (this overwrites hand fixes).
The app loads the catalogue and each video's files from the team's shared copy on GitHub Pages, https://alisakujou0711.github.io/captlearn-media (the captlearn-media repo). That address is written into the app when it is built (SHARED_BACKEND_URL in backendUrl.js), so nobody's computer needs to be running.
In Vega Studio, build the app with the wrench button, then press the play button to launch it in the emulator. If the app can't reach its files, it shows an error screen with a Try again button: check that the TV or emulator is online.
After adding a video or fixing captions or lexicons in backend, copy backend/catalogue.json and the changed backend/media/<id>/ folders into the same places in a clone of captlearn-media, then commit and push it. GitHub Pages serves the new files within about ten minutes; the app picks them up without a rebuild. Each file must be under 100 MB.
To try files that aren't on GitHub Pages yet, run the backend on your computer and reach it through a tunnel. You need two command lines open.
- Start the backend. From the project root:
You should see
cd backend npm startCaptLearn backend on :8080. It only serves files, so it needs no Gemini key. To use another port, setPORTfirst (e.g.$env:PORT=3000; npm startin PowerShell) and use it in the tunnel command. To check it works, open http://localhost:8080/catalogue.json in a browser. - Start the tunnel in a new command line:
Copy the url it prints, e.g.
cloudflared tunnel --url http://localhost:8080
https://funky-but-interesting-name.trycloudflare.com. A quick tunnel's url changes every time you start it. - Copy
.env.exampleto.envin the project root and setBACKEND_URLto the tunnel url:(SettingBACKEND_URL=https://funky-but-interesting-name.trycloudflare.comBACKEND_URLin the environment also works, and wins over.env; both win over the shared default.) Build the app again whenever the url changes, and delete.envto go back to GitHub Pages.
- App:
npm testin the project root. - Backend:
npm testinbackend.
- Project is offline
- Check for internet connection
- Ensure
backendis running - Ensure app has finished building/rebuilding before launching in emulator