Commit 9c8e405749
Unsigned
Layout: unified · split
DayByDay.xcodeproj/project.pbxproj −4
| @@ -13,7 +13,6 @@ | |||
| 13 | 8B1B4FFF2F659AD2005C246F /* BodyPartsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8B1B4FFE2F659AD2005C246F /* BodyPartsView.swift */; }; | 13 | 8B1B4FFF2F659AD2005C246F /* BodyPartsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8B1B4FFE2F659AD2005C246F /* BodyPartsView.swift */; }; |
| 14 | 8B1B50012F659AD3005C246F /* FoodCard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8B1B50002F659AD3005C246F /* FoodCard.swift */; }; | 14 | 8B1B50012F659AD3005C246F /* FoodCard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8B1B50002F659AD3005C246F /* FoodCard.swift */; }; |
| 15 | 8B1B50032F659AD4005C246F /* FoodView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8B1B50022F659AD4005C246F /* FoodView.swift */; }; | 15 | 8B1B50032F659AD4005C246F /* FoodView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8B1B50022F659AD4005C246F /* FoodView.swift */; }; |
| 16 | 8B57F7282F63BBB4001F6F5E /* TodayView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8B57F7272F63BBB4001F6F5E /* TodayView.swift */; }; | ||
| 17 | 8B57F72A2F63BBB5001F6F5E /* NumberCard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8B57F7292F63BBB5001F6F5E /* NumberCard.swift */; }; | 16 | 8B57F72A2F63BBB5001F6F5E /* NumberCard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8B57F7292F63BBB5001F6F5E /* NumberCard.swift */; }; |
| 18 | 8B57F72C2F63BBB6001F6F5E /* NumbersView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8B57F72B2F63BBB6001F6F5E /* NumbersView.swift */; }; | 17 | 8B57F72C2F63BBB6001F6F5E /* NumbersView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8B57F72B2F63BBB6001F6F5E /* NumbersView.swift */; }; |
| 19 | 8B57F72E2F63BBB7001F6F5E /* ColorCard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8B57F72D2F63BBB7001F6F5E /* ColorCard.swift */; }; | 18 | 8B57F72E2F63BBB7001F6F5E /* ColorCard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8B57F72D2F63BBB7001F6F5E /* ColorCard.swift */; }; |
| @@ -44,7 +43,6 @@ | |||
| 44 | 8B1B4FFE2F659AD2005C246F /* BodyPartsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BodyPartsView.swift; sourceTree = "<group>"; }; | 43 | 8B1B4FFE2F659AD2005C246F /* BodyPartsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BodyPartsView.swift; sourceTree = "<group>"; }; |
| 45 | 8B1B50002F659AD3005C246F /* FoodCard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FoodCard.swift; sourceTree = "<group>"; }; | 44 | 8B1B50002F659AD3005C246F /* FoodCard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FoodCard.swift; sourceTree = "<group>"; }; |
| 46 | 8B1B50022F659AD4005C246F /* FoodView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FoodView.swift; sourceTree = "<group>"; }; | 45 | 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>"; }; | ||
| 48 | 8B57F7292F63BBB5001F6F5E /* NumberCard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NumberCard.swift; sourceTree = "<group>"; }; | 46 | 8B57F7292F63BBB5001F6F5E /* NumberCard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NumberCard.swift; sourceTree = "<group>"; }; |
| 49 | 8B57F72B2F63BBB6001F6F5E /* NumbersView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NumbersView.swift; sourceTree = "<group>"; }; | 47 | 8B57F72B2F63BBB6001F6F5E /* NumbersView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NumbersView.swift; sourceTree = "<group>"; }; |
| 50 | 8B57F72D2F63BBB7001F6F5E /* ColorCard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ColorCard.swift; sourceTree = "<group>"; }; | 48 | 8B57F72D2F63BBB7001F6F5E /* ColorCard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ColorCard.swift; sourceTree = "<group>"; }; |
| @@ -128,7 +126,6 @@ | |||
| 128 | children = ( | 126 | children = ( |
| 129 | 8B7051B42F5F908800491D58 /* DayByDay */, | 127 | 8B7051B42F5F908800491D58 /* DayByDay */, |
| 130 | 8B7051B32F5F908800491D58 /* Products */, | 128 | 8B7051B32F5F908800491D58 /* Products */, |
| 131 | 8B57F7272F63BBB4001F6F5E /* TodayView.swift */, | ||
| 132 | 8B57F7292F63BBB5001F6F5E /* NumberCard.swift */, | 129 | 8B57F7292F63BBB5001F6F5E /* NumberCard.swift */, |
| 133 | 8B57F72B2F63BBB6001F6F5E /* NumbersView.swift */, | 130 | 8B57F72B2F63BBB6001F6F5E /* NumbersView.swift */, |
| 134 | 8B57F72D2F63BBB7001F6F5E /* ColorCard.swift */, | 131 | 8B57F72D2F63BBB7001F6F5E /* ColorCard.swift */, |
| @@ -282,7 +279,6 @@ | |||
| 282 | 8B57F7342F63BBBA001F6F5E /* ShapesView.swift in Sources */, | 279 | 8B57F7342F63BBBA001F6F5E /* ShapesView.swift in Sources */, |
| 283 | 8B57F7362F63BBBA001F6F5E /* AnimalCard.swift in Sources */, | 280 | 8B57F7362F63BBBA001F6F5E /* AnimalCard.swift in Sources */, |
| 284 | 8B57F7322F63BBB9001F6F5E /* ShapeCard.swift in Sources */, | 281 | 8B57F7322F63BBB9001F6F5E /* ShapeCard.swift in Sources */, |
| 285 | 8B57F7282F63BBB4001F6F5E /* TodayView.swift in Sources */, | ||
| 286 | 8B57F7302F63BBB8001F6F5E /* ColorsView.swift in Sources */, | 282 | 8B57F7302F63BBB8001F6F5E /* ColorsView.swift in Sources */, |
| 287 | ); | 283 | ); |
| 288 | runOnlyForDeploymentPostprocessing = 0; | 284 | runOnlyForDeploymentPostprocessing = 0; |
DayByDay/Home/CategoryHubView.swift +1 −1
| @@ -53,7 +53,7 @@ extension Category { | |||
| 53 | @ViewBuilder | 53 | @ViewBuilder |
| 54 | var lookAndListenView: some View { | 54 | var lookAndListenView: some View { |
| 55 | switch self { | 55 | switch self { |
| 56 | case .today: TodayView() | 56 | case .today: TodayRoutineView() |
| 57 | case .days: DaysOfWeekView() | 57 | case .days: DaysOfWeekView() |
| 58 | case .months: MonthsOfYearView() | 58 | case .months: MonthsOfYearView() |
| 59 | case .seasons: SeasonsView() | 59 | case .seasons: SeasonsView() |
DayByDay/SpeechSynthesizer.swift +14 −2
| @@ -64,8 +64,8 @@ final class SpeechSynthesizer: NSObject, AVSpeechSynthesizerDelegate, AVAudioPla | |||
| 64 | } | 64 | } |
| 65 | 65 | ||
| 66 | func speak(_ text: String, completion: (() -> Void)? = nil) { | 66 | func speak(_ text: String, completion: (() -> Void)? = nil) { |
| 67 | // Every speak() call is a card tap, so give a gentle tactile bump | 67 | // A gentle tactile bump with every spoken line. Prepared just before |
| 68 | // alongside the audio. Prepared just before firing for lowest latency. | 68 | // firing for lowest latency. |
| 69 | haptics.prepare() | 69 | haptics.prepare() |
| 70 | haptics.impactOccurred() | 70 | haptics.impactOccurred() |
| 71 | 71 | ||
| @@ -75,6 +75,9 @@ final class SpeechSynthesizer: NSObject, AVSpeechSynthesizerDelegate, AVAudioPla | |||
| 75 | 75 | ||
| 76 | stop() | 76 | stop() |
| 77 | 77 | ||
| 78 | #if DEBUG | ||
| 79 | if let warning = missingClipWarning(for: text) { assertionFailure(warning) } | ||
| 80 | #endif | ||
| 78 | if let clips = library?.clips(for: text) { | 81 | if let clips = library?.clips(for: text) { |
| 79 | queue = clips | 82 | queue = clips |
| 80 | clipCompletion = completion | 83 | clipCompletion = completion |
| @@ -91,6 +94,15 @@ final class SpeechSynthesizer: NSObject, AVSpeechSynthesizerDelegate, AVAudioPla | |||
| 91 | synthesizer.speak(utterance) | 94 | synthesizer.speak(utterance) |
| 92 | } | 95 | } |
| 93 | 96 | ||
| 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 | |||
| 94 | /// Stops clips and speech; neither calls its completion. | 106 | /// Stops clips and speech; neither calls its completion. |
| 95 | func stop() { | 107 | func stop() { |
| 96 | clipToken += 1 | 108 | clipToken += 1 |
DayByDayTests/SpeechCompletionTests.swift +11
| @@ -117,6 +117,17 @@ struct SpeechCompletionTests { | |||
| 117 | speech.library = ClipLibrary.bundled | 117 | speech.library = ClipLibrary.bundled |
| 118 | } | 118 | } |
| 119 | 119 | ||
| 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 | |||
| 120 | @Test func stopDropsClipCompletion() async throws { | 131 | @Test func stopDropsClipCompletion() async throws { |
| 121 | speech.library = Self.library | 132 | speech.library = Self.library |
| 122 | var fired = false | 133 | var fired = false |
TodayView.swift deleted −84
| @@ -1,84 +0,0 @@ | |||
| 1 | // | ||
| 2 | // TodayView.swift | ||
| 3 | // DayByDay | ||
| 4 | // | ||
| 5 | |||
| 6 | import 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]." | ||
| 10 | struct 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: | |||
| 129 | args = parser.parse_args() | 129 | args = parser.parse_args() |
| 130 | 130 | ||
| 131 | lines = [l for l in args.lines.read_text().splitlines() if l.strip()] | 131 | 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}") | ||
| 132 | if args.dry_run: | 135 | if args.dry_run: |
| 133 | for text in lines: | 136 | for text in lines: |
| 134 | print(spoken(text)) | 137 | print(spoken(text)) |
scripts/render-voice.py +3
| @@ -130,6 +130,9 @@ def main() -> None: | |||
| 130 | args = parser.parse_args() | 130 | args = parser.parse_args() |
| 131 | 131 | ||
| 132 | lines = [l for l in args.lines.read_text().splitlines() if l.strip()] | 132 | 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}") | ||
| 133 | args.out.mkdir(parents=True, exist_ok=True) | 136 | args.out.mkdir(parents=True, exist_ok=True) |
| 134 | manifest_path = args.out / "voice-manifest.json" | 137 | manifest_path = args.out / "voice-manifest.json" |
| 135 | old = {e["text"]: e for e in json.loads(manifest_path.read_text())} if manifest_path.exists() else {} | 138 | old = {e["text"]: e for e in json.loads(manifest_path.read_text())} if manifest_path.exists() else {} |