Skip to content

Commit 5438a69

Browse files
authored
Fix watchOS Build time error in ViewModel
1 parent 5a6e62b commit 5438a69

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Shared/ViewModel.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,19 @@ class ViewModel: ObservableObject {
1515
@Published var messages: [MessageRow] = []
1616
@Published var inputMessage: String = ""
1717

18+
#if !os(watchOS)
1819
private var synthesizer: AVSpeechSynthesizer?
20+
#endif
1921

2022
private let api: ChatGPTAPI
2123

2224
init(api: ChatGPTAPI, enableSpeech: Bool = false) {
2325
self.api = api
26+
#if !os(watchOS)
2427
if enableSpeech {
2528
synthesizer = .init()
2629
}
30+
#endif
2731
}
2832

2933
@MainActor
@@ -84,6 +88,7 @@ class ViewModel: ObservableObject {
8488
}
8589

8690
func speakLastResponse() {
91+
#if !os(watchOS)
8792
guard let synthesizer, let responseText = self.messages.last?.responseText, !responseText.isEmpty else {
8893
return
8994
}
@@ -94,10 +99,13 @@ class ViewModel: ObservableObject {
9499
utterance.pitchMultiplier = 0.8
95100
utterance.postUtteranceDelay = 0.2
96101
synthesizer.speak(utterance )
102+
#endif
97103
}
98104

99105
func stopSpeaking() {
106+
#if !os(watchOS)
100107
synthesizer?.stopSpeaking(at: .immediate)
108+
#endif
101109
}
102110

103111
}

0 commit comments

Comments
 (0)