Inspiration

People who speak through text-to-speech are quick with what they planned to say and slow with everything else. Clinic visits rarely follow the plan. The dentist says "we can do the 3D scan now", everyone waits, and typing a reply letter by letter takes a minute or more. Most AAC boards are generic, so the words for this particular visit (bite block, numbing, referral) usually aren't on them.

An AI helper can make that faster, but it can also do real harm here: put words in someone's mouth, or turn their "not yet" into "yes". We wanted the model to handle the wording while the person keeps control of the meaning, and we wanted it to work in a clinic basement with no signal.

What it does

The night before a visit, you drop the clinic's handout (a PDF) into SayAhead in Chrome. Gemini reads it in the cloud and builds a small board for that visit: topics, words and question starters, plus phrases the staff are likely to say. Each topic links back to the page it came from. You check the board, fix anything that's off, and send it to your phone with a 6-character code.

In the room the phone can be offline. You tap a few tiles, say Not yet · 3D scan · Noise, and tap Draft. The on-device model writes a couple of sentences, like "Not yet, the 3D scan is making noise." You pick one and the phone speaks it, or shows it full screen in large type, flipped so the dentist can read it.

Each draft is labelled with where it ran and how long it took ("On this iPhone · 1.4 s · checked"). Before you see a draft, plain code (not AI) checks it against the tiles you tapped. If it drops a tile, flips a refusal, or adds a feeling or question you didn't choose, it's hidden, and you can open it to see why. A tiles-only sentence with no AI is always there too, and Stop, Wait and "Speak as is" never wait for a model.

After the visit you can get a recap of what you said. It's made on the device and never leaves it.

SayAhead runs as a Chrome web app (an installable PWA) and as a native iPhone app.

How we built it

Everything goes through Firebase AI Logic, with a separate model instance and inference mode for each job:

  • Board from the clinic PDF: ONLY_IN_CLOUD, gemini-3.5-flash-lite with JSON schema output.
  • Sentences from tiles: PREFER_ON_DEVICE. Apple Foundation Models on the iPhone, Gemini Nano in Chrome, and cloud Gemini when neither is available.
  • Recap of what was said: ONLY_ON_DEVICE. It is never sent to the cloud. Without an on-device model you get the plain list instead.

Both apps share one contract. The shared/ folder holds the tiles, prompts, board schema, sample handout and test vectors. The meaning guard exists twice, in TypeScript and in Swift, and both run the same test vectors. Each tile lists the words a draft has to contain. Refusals (No, Not yet, Stop, Wait) are marked so they can't be dropped, and a separate rule catches questions the person never asked. If every draft fails, the composer tries once more and tells the model exactly what it dropped.

Two SDK details needed handling. Chrome's on-device path ignores systemInstruction, so our instructions travel inside the prompt. And the JS SDK only falls back to the cloud when Nano is unavailable, not when a call fails, so the composer does that retry itself and labels the result.

Both apps use App Check: reCAPTCHA Enterprise on the hosted web app, the debug provider on the sideloaded iPhone build, and App Attest wired in for App Store builds. Shared boards live in Firestore. A board can be created once and read only by its exact code, nobody can list them, and after 48 hours the rules refuse to read them. A shared board contains only the handout's vocabulary, never what was said.

The web app is Vite, React and TypeScript, served from Firebase Hosting as an offline PWA. The iPhone app is SwiftUI, generated with XcodeGen, with the pure logic in a Swift package tested on Linux CI.

We don't own a Mac. GitHub Actions builds the iPhone app on the xcode-27 runner, we sideload the IPA, and CI takes simulator screenshots in light mode, dark mode and large text.

Challenges we ran into

Small on-device models drop things. In our first probe, "Stop + Pain" came back as just "Stop.", "Will it hurt? + injection" lost the injection, and "Yes + polish" lost the yes. That's the reason the guard exists, and you can see it in the video, where five drafts for "Will it hurt? + injection" get hidden.

The guard had holes of its own. Early on it passed an invented question, "Do I need to see a doctor?", so we added the no-added-question rule and matching for different word endings.

Building and testing an iPhone app with on-device inference and App Check, without a Mac, took some doing. All of it runs through CI and sideloading.

Free-tier limits caught us out too. About 50 cloud calls in two minutes returned 429 errors, and the app told the person "network failed", which was wrong. It now says the cloud model is busy.

Accomplishments that we're proud of

  • 61 taps instead of 466 keystrokes across 12 clinic messages, counting tiles, Draft, picking a draft and Speak. That's 87% fewer.
  • In the cloud run, all 12 messages got a draft that passed the meaning guard on the first try, with a median of 1.5 s.
  • Drafting works fully offline. On an iPhone 16 in airplane mode it usually takes about 1.4 s. A retry after a failed check takes longer, like the 4.0 s in the video.
  • We built for accessibility from the start. An automated axe scan of the web app's screens finds 0 violations, and the iPhone app supports Dynamic Type up to the accessibility sizes, VoiceOver announcements and 48-point touch targets.

The numbers and how we measured them are in docs/MEASUREMENTS.md.

What we learned

Speed wasn't the difference between on-device and cloud. Warm cloud calls took 1.7 to 2.4 s and on-device about 1.4 s, which is close. The reasons to run on the device are working without signal and keeping what someone says about their health on their own phone.

The on-device models didn't refuse medical phrases. We saw no guardrail refusals in 80 probe calls, including "is it cancer" and "I take blood thinners".

Getting a draft was the easy part. Making sure it still meant what the person chose was the harder problem, and it's what makes AI usable for AAC at all.

What's next

Nobody who uses AAC has tested SayAhead yet. That's the most important next step, along with speech-language pathologists. After that comes the App Store: the iPhone app already has its privacy manifest, icon and launch screen, but App Attest registration and the store listing are still to do. We'd also like more languages and more kinds of visits than the sample dental one.

Built With

  • apple-foundation-models
  • chrome-prompt-api
  • cloud-firestore
  • firebase
  • firebase-ai-logic
  • firebase-app-check
  • firebase-hosting
  • gemini
  • gemini-nano
  • recaptcha-enterprise
  • swift
  • swiftui
  • typescript
Share this project:

Updates

Submission history