Technical overview
How Cue to Cue is built: for contributors, reviewers and anyone porting it.
At a glance
| Platform | iOS / iPadOS 17+, SwiftUI, Swift 5 mode |
|---|---|
| Bundle ID | com.jamesnevada.cueline |
| Size | ~18k lines of Swift across 39 files; no third-party dependencies |
| Networking | Supabase (accounts, subscriptions, feature board) only when signed in or browsing ideas; Apple Speech for transcription. |
| Storage | Local JSON + files in the app's Documents directory |
| Frameworks | SwiftUI, Observation, AVFoundation, Speech, Vision, VisionKit, PDFKit, PhotosUI, Charts, CoreText |
Data model
ScriptStore (an @Observable class) holds [Script] and persists it to Documents/scripts.json. Saves are debounced (0.8 s) and encoded off the main thread; the store flushes synchronously when the app leaves the foreground.
Script: title, scenes, the user's characters, cast, voice settings, latest score per line chunk, delivery history, practice progress, saved loops, practice log, character work.ScriptScene→[ScriptLine]. A line with no character is a stage direction.ScriptLine: text, speaker(s), optional recording + timed transcript, chunk breaks, blocking cues, stage notes, actor note, "work on" flag.- All new fields are optional so older saved files keep decoding.
Files: recordings in Documents/Audio, imported PDFs in Documents/PDFs, journal photos in Documents/Journal. Preferences use @AppStorage/UserDefaults.
Speech pipeline
SpeechListenerstreams the mic (AVAudioEnginetap) intoSFSpeechAudioBufferRecognitionRequest, on-device when supported. It restarts tasks across long pauses and stitches results withTranscriptAccumulator, which tells new utterances apart from revisions using timestamps. A simple RMS voice-activity detector tracks whether the user actually made a sound (used for interjection-only lines like "Ugh!").CueMatcheraligns heard words to the expected line with a fuzzy longest-common-subsequence. Word similarity layers: canonical forms (numbers, ordinals, letters), contractions and run-together words, filler families (uh/ah/ugh/argh…), prefix and edit distance scaled by length, a Soundex-like key, and, in "Close enough" mode, a phonetic key with voiced/unvoiced merges.keepAfterEchoremoves runs of the scene partner's words picked up by the mic, unless the user's own line contains them in order.CueMatcher.shouldAdvancedecides when a line is finished (end matched, coverage and silence thresholds, scaled by the "Wait for me" setting).Scorerproduces aLineScore: accuracy, missed and out-of-order tokens, prompted flag, and for Speed/Pacing practice, pickup time and words-per-minute.
Transcription of recordings (Transcriber) uses SFSpeechURLRecognitionRequest with server recognition allowed, contextual hints from the line text and cast, sentence breaks at pauses, and a tidy-up pass.
Rehearsal engine
RehearsalEngine builds a list of steps (play / listen / cue / direction) from the scene items, honouring review targets, loops, ranges and modes, then runs them as an async loop. It handles overlaps (/), cut-offs (-), lines said together, joint lines, early listening for timed entrances, until-passed repeats, shortened cues, and loop passes. Partner audio comes from recordings via AVAudioPlayer (with word timing for highlighting) or AVSpeechSynthesizer.
Practice sessions
NotecardSession: deck, rounds until all pass, hints, Line?DrillSession: Repetition, New Choice, Until Word Perfect; keeps the mic open between tries and starts a fresh transcript each try.CueQuizView: Guess the cue.BlockingSession: say / choose / place answers, scored by strictness.- Each session appends a
PracticeRecordtoScript.practiceLogon finish;InsightsViewcharts them with Swift Charts.
Script import
ScriptReaderreads PDFs line by line with layout (position, indent, italics), or images viaVNRecognizeTextRequest(merging same-row fragments). It removes crossed-out text from PDF strikeout/ink/line annotations, a pixel "ink map" for drawn strikes and scribbles, and Markdown~~…~~. It drops title pages, repeating headers/footers, watermarks and side markers, and joins speeches across page breaks.ScriptParserturns text into scenes and lines: screenplay cues (with CONT'D / MORE handling), colon, acting-edition and wide-gap formats, inline directions to stage notes, place labels and camera directions excluded from characters.
Blocking and stage
BlockingCue (action, area, exact position, target, prop, entrance/exit side, trigger) lives on lines. StageTimeline replays cues into per-line snapshots; StageDiagram draws the set, wings, backstage, audience, tokens and move arrows. A small cache avoids recomputing timelines on every redraw.
Accounts and payments
Supabase provides auth (email + password) and Postgres. Tables: profiles, entitlements (Stripe / Apple / Google / admin comp), feature_requests, feature_votes, all with row-level security. Clients only call security-definer RPCs: my_account, feature_board, submit_feature_request, vote_feature and the admin_* functions. Edge functions: stripe-checkout, stripe-portal, stripe-webhook, apple-verify (App Store Server API), google-verify (Play Developer API), delete-account. The iOS app uses StoreKit 2 and calls Supabase over plain HTTPS (no SDK).
Permissions and privacy
| Key | Why |
|---|---|
NSMicrophoneUsageDescription | Recording partners' lines; hearing yours |
NSSpeechRecognitionUsageDescription | Transcribing and recognizing lines |
NSCameraUsageDescription | Scanning script pages |
PrivacyInfo.xcprivacy declares no tracking and the UserDefaults required-reason API (CA92.1). ITSAppUsesNonExemptEncryption is NO.
Building
xcodebuild -project CueLine.xcodeproj -scheme CueLine \
-configuration Release -destination 'generic/platform=iOS' \
-archivePath build/CueLine.xcarchive archive
Then upload the archive from Xcode's Organizer (or xcodebuild -exportArchive with an App Store export options plist).