krz/daybyday

iOS learning games for young children: days, months, seasons, numbers, letters, animals and more. education ios kids swift https://krz.sh/apps/daybyday/

Commit 9c8e405749

9c8e405749214f8c6e529211637859671a076542

parent: d3cb148c6f

Unsigned

cmc <hello@cleberg.net> · 2026-10-17 21:13 UTC

Voice cleanup (!11)

- Delete `TodayView` (unreachable since part 5, not in the clip catalog). `Category.today`'s `lookAndListenView` points at `TodayRoutineView`.
- Debug builds `assertionFailure` when a spoken sentence has no bundled clip (`SpeechSynthesizer.missingClipWarning(for:)`), so a line missing from `SpokenLines` stops the app in Xcode instead of playing in the system voice.
- `render-voice.py` and `render-voice-elevenlabs.py` exit with an error for `--redo` text not in the line list.
- Correct the haptic comment in `SpeechSynthesizer.speak`.

Tests: 228 pass (new: `uncatalogedLineIsFlagged`). The full suite runs with the assertion on, so no line spoken in tests is uncataloged.

Closes #9

Layout: unified · split

DayByDay.xcodeproj/project.pbxproj −4
@@ -13,7 +13,6 @@
1313 8B1B4FFF2F659AD2005C246F /* BodyPartsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8B1B4FFE2F659AD2005C246F /* BodyPartsView.swift */; };
1414 8B1B50012F659AD3005C246F /* FoodCard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8B1B50002F659AD3005C246F /* FoodCard.swift */; };
1515 8B1B50032F659AD4005C246F /* FoodView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8B1B50022F659AD4005C246F /* FoodView.swift */; };
16 8B57F7282F63BBB4001F6F5E /* TodayView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8B57F7272F63BBB4001F6F5E /* TodayView.swift */; };
1716 8B57F72A2F63BBB5001F6F5E /* NumberCard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8B57F7292F63BBB5001F6F5E /* NumberCard.swift */; };
1817 8B57F72C2F63BBB6001F6F5E /* NumbersView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8B57F72B2F63BBB6001F6F5E /* NumbersView.swift */; };
1918 8B57F72E2F63BBB7001F6F5E /* ColorCard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8B57F72D2F63BBB7001F6F5E /* ColorCard.swift */; };
@@ -44,7 +43,6 @@
4443 8B1B4FFE2F659AD2005C246F /* BodyPartsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BodyPartsView.swift; sourceTree = "<group>"; };
4544 8B1B50002F659AD3005C246F /* FoodCard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FoodCard.swift; sourceTree = "<group>"; };
4645 8B1B50022F659AD4005C246F /* FoodView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FoodView.swift; sourceTree = "<group>"; };
47 8B57F7272F63BBB4001F6F5E /* TodayView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TodayView.swift; sourceTree = "<group>"; };
4846 8B57F7292F63BBB5001F6F5E /* NumberCard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NumberCard.swift; sourceTree = "<group>"; };
4947 8B57F72B2F63BBB6001F6F5E /* NumbersView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NumbersView.swift; sourceTree = "<group>"; };
5048 8B57F72D2F63BBB7001F6F5E /* ColorCard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ColorCard.swift; sourceTree = "<group>"; };
@@ -128,7 +126,6 @@
128126 children = (
129127 8B7051B42F5F908800491D58 /* DayByDay */,
130128 8B7051B32F5F908800491D58 /* Products */,
131 8B57F7272F63BBB4001F6F5E /* TodayView.swift */,
132129 8B57F7292F63BBB5001F6F5E /* NumberCard.swift */,
133130 8B57F72B2F63BBB6001F6F5E /* NumbersView.swift */,
134131 8B57F72D2F63BBB7001F6F5E /* ColorCard.swift */,
@@ -282,7 +279,6 @@
282279 8B57F7342F63BBBA001F6F5E /* ShapesView.swift in Sources */,
283280 8B57F7362F63BBBA001F6F5E /* AnimalCard.swift in Sources */,
284281 8B57F7322F63BBB9001F6F5E /* ShapeCard.swift in Sources */,
285 8B57F7282F63BBB4001F6F5E /* TodayView.swift in Sources */,
286282 8B57F7302F63BBB8001F6F5E /* ColorsView.swift in Sources */,
287283 );
288284 runOnlyForDeploymentPostprocessing = 0;
DayByDay/Home/CategoryHubView.swift +1 −1
@@ -53,7 +53,7 @@ extension Category {
5353 @ViewBuilder
5454 var lookAndListenView: some View {
5555 switch self {
56 case .today: TodayView()
56 case .today: TodayRoutineView()
5757 case .days: DaysOfWeekView()
5858 case .months: MonthsOfYearView()
5959 case .seasons: SeasonsView()
DayByDay/SpeechSynthesizer.swift +14 −2
@@ -64,8 +64,8 @@ final class SpeechSynthesizer: NSObject, AVSpeechSynthesizerDelegate, AVAudioPla
6464 }
6565
6666 func speak(_ text: String, completion: (() -> Void)? = nil) {
67 // Every speak() call is a card tap, so give a gentle tactile bump
68 // alongside the audio. Prepared just before firing for lowest latency.
67 // A gentle tactile bump with every spoken line. Prepared just before
68 // firing for lowest latency.
6969 haptics.prepare()
7070 haptics.impactOccurred()
7171
@@ -75,6 +75,9 @@ final class SpeechSynthesizer: NSObject, AVSpeechSynthesizerDelegate, AVAudioPla
7575
7676 stop()
7777
78 #if DEBUG
79 if let warning = missingClipWarning(for: text) { assertionFailure(warning) }
80 #endif
7881 if let clips = library?.clips(for: text) {
7982 queue = clips
8083 clipCompletion = completion
@@ -91,6 +94,15 @@ final class SpeechSynthesizer: NSObject, AVSpeechSynthesizerDelegate, AVAudioPla
9194 synthesizer.speak(utterance)
9295 }
9396
97 /// Names the sentences the bundled clips lack. Every spoken line belongs
98 /// in `SpokenLines`; one that is missing plays in the system voice.
99 func missingClipWarning(for text: String) -> String? {
100 guard let library, library === ClipLibrary.bundled else { return nil }
101 let missing = SpokenText.sentences(text).filter { library.clip(for: $0) == nil }
102 guard !missing.isEmpty else { return nil }
103 return "No voice clip for \(missing). Add the line to SpokenLines and render it."
104 }
105
94106 /// Stops clips and speech; neither calls its completion.
95107 func stop() {
96108 clipToken += 1
DayByDayTests/SpeechCompletionTests.swift +11
@@ -117,6 +117,17 @@ struct SpeechCompletionTests {
117117 speech.library = ClipLibrary.bundled
118118 }
119119
120 /// A line the bundled clips lack would play in the system voice.
121 @Test func uncatalogedLineIsFlagged() {
122 speech.library = ClipLibrary.bundled
123 #expect(speech.missingClipWarning(for: "Super!") == nil)
124 #expect(speech.missingClipWarning(for: "Super! Not in the catalog.")?.contains("Not in the catalog.") == true)
125 #expect(speech.missingClipWarning(for: "") == nil)
126 speech.library = Self.library
127 #expect(speech.missingClipWarning(for: "Gamma.") == nil)
128 speech.library = ClipLibrary.bundled
129 }
130
120131 @Test func stopDropsClipCompletion() async throws {
121132 speech.library = Self.library
122133 var fired = false
TodayView.swift deleted −84
@@ -1,84 +0,0 @@
1//
2// TodayView.swift
3// DayByDay
4//
5
6import SwiftUI
7
8/// A single-screen summary of today: day of the week, date, month, and season.
9/// The child taps the large card to hear "Today is [day], [month] [date]. It is [season]."
10struct TodayView: View {
11 @State private var isTapped = false
12
13 private var todayText: String {
14 let day = DayOfWeek.current.name
15 let month = MonthOfYear.current.name
16 let date = AppCalendar.current.component(.day, from: Date())
17 let season = Season.current.name
18 return "Today is \(day), \(month) \(date). It is \(season)."
19 }
20
21 var body: some View {
22 ScrollView {
23 VStack(spacing: 32) {
24 // Main today card
25 ZStack {
26 RoundedRectangle(cornerRadius: 32, style: .continuous)
27 .fill(Color.orange.gradient)
28 .shadow(color: Color.orange.opacity(0.4), radius: 8, y: 4)
29
30 VStack(spacing: 20) {
31 Image(systemName: "sun.horizon.fill")
32 .font(.system(size: 80))
33 .foregroundStyle(.white)
34 .symbolRenderingMode(.hierarchical)
35
36 // Day of the week
37 Text(DayOfWeek.current.name)
38 .font(.system(size: 48, weight: .bold, design: .rounded))
39 .foregroundStyle(.white)
40
41 // Date number
42 let dayNumber = AppCalendar.current.component(.day, from: Date())
43 Text("\(dayNumber)")
44 .font(.system(size: 72, weight: .heavy, design: .rounded))
45 .foregroundStyle(.white.opacity(0.9))
46
47 // Month and season
48 HStack(spacing: 24) {
49 Label(MonthOfYear.current.name, systemImage: MonthOfYear.current.symbol)
50 Label(Season.current.name, systemImage: Season.current.symbol)
51 }
52 .font(.system(size: 24, weight: .semibold, design: .rounded))
53 .foregroundStyle(.white.opacity(0.9))
54 }
55 .padding(.vertical, 32)
56 }
57 .frame(height: 420)
58 .scaleEffect(isTapped ? 1.08 : 1.0)
59 .rotation3DEffect(.degrees(isTapped ? 6 : 0), axis: (x: 1, y: 0, z: 0))
60 .animation(.spring(response: 0.35, dampingFraction: 0.5), value: isTapped)
61 .contentShape(RoundedRectangle(cornerRadius: 32, style: .continuous))
62 .onTapGesture {
63 isTapped = true
64 SpeechSynthesizer.shared.speak(todayText)
65 DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) {
66 isTapped = false
67 }
68 }
69 .accessibilityLabel(todayText)
70 .accessibilityAddTraits(.isButton)
71
72 // Tap hint
73 Label("Tap to hear today", systemImage: "speaker.wave.2.fill")
74 .font(.system(size: 22, weight: .medium, design: .rounded))
75 .foregroundStyle(.secondary)
76 }
77 .padding(32)
78 }
79 }
80}
81
82#Preview {
83 TodayView()
84}
scripts/render-voice-elevenlabs.py +3
@@ -129,6 +129,9 @@ def main() -> None:
129129 args = parser.parse_args()
130130
131131 lines = [l for l in args.lines.read_text().splitlines() if l.strip()]
132 unknown = [t for t in args.redo if t not in lines]
133 if unknown:
134 parser.error(f"--redo text not in {args.lines}: {unknown}")
132135 if args.dry_run:
133136 for text in lines:
134137 print(spoken(text))
scripts/render-voice.py +3
@@ -130,6 +130,9 @@ def main() -> None:
130130 args = parser.parse_args()
131131
132132 lines = [l for l in args.lines.read_text().splitlines() if l.strip()]
133 unknown = [t for t in args.redo if t not in lines]
134 if unknown:
135 parser.error(f"--redo text not in {args.lines}: {unknown}")
133136 args.out.mkdir(parents=True, exist_ok=True)
134137 manifest_path = args.out / "voice-manifest.json"
135138 old = {e["text"]: e for e in json.loads(manifest_path.read_text())} if manifest_path.exists() else {}