@@ -45,9 +45,11 @@ - (id)init {
4545 [self ->synth setDelegate: self ];
4646 print_verbose (" Text-to-Speech: AVSpeechSynthesizer initialized." );
4747 } else {
48+ #if MAC_OS_X_VERSION_MIN_REQUIRED < 140000
4849 self->synth = [[NSSpeechSynthesizer alloc ] init ];
4950 [self ->synth setDelegate: self ];
5051 print_verbose (" Text-to-Speech: NSSpeechSynthesizer initialized." );
52+ #endif
5153 }
5254 return self;
5355}
@@ -90,6 +92,8 @@ - (void)speechSynthesizer:(AVSpeechSynthesizer *)av_synth didFinishSpeechUtteran
9092
9193// NSSpeechSynthesizer callback (macOS 10.4+)
9294
95+ // Deprecated in macOS 14.0, needs to be removed when compiling with min macOS 14.0.
96+ #if MAC_OS_X_VERSION_MIN_REQUIRED < 140000
9397- (void )speechSynthesizer:(NSSpeechSynthesizer *)ns_synth willSpeakWord:(NSRange )characterRange ofString:(NSString *)string {
9498 if (!paused && have_utterance) {
9599 // Convert from UTF-16 to UTF-32 position.
@@ -118,6 +122,7 @@ - (void)speechSynthesizer:(NSSpeechSynthesizer *)ns_synth didFinishSpeaking:(BOO
118122 speaking = false ;
119123 [self update ];
120124}
125+ #endif
121126
122127- (void )update {
123128 if (!speaking && queue.size () > 0 ) {
@@ -138,6 +143,7 @@ - (void)update {
138143 ids[new_utterance] = message.id ;
139144 [av_synth speakUtterance: new_utterance];
140145 } else {
146+ #if MAC_OS_X_VERSION_MIN_REQUIRED < 140000
141147 NSSpeechSynthesizer *ns_synth = synth;
142148 [ns_synth setObject: nil forProperty: NSSpeechResetProperty error: nil ];
143149 [ns_synth setVoice: [NSString stringWithUTF8String: message.voice.utf8 ().get_data ()]];
@@ -149,6 +155,7 @@ - (void)update {
149155 last_utterance = message.id ;
150156 have_utterance = true ;
151157 [ns_synth startSpeakingString: [NSString stringWithUTF8String: message.text.utf8 ().get_data ()]];
158+ #endif
152159 }
153160 DisplayServer::get_singleton ()->tts_post_utterance_event (DisplayServerEnums::TTS_UTTERANCE_STARTED , message.id );
154161 queue.pop_front ();
@@ -162,8 +169,10 @@ - (void)pauseSpeaking {
162169 AVSpeechSynthesizer *av_synth = synth;
163170 [av_synth pauseSpeakingAtBoundary: AVSpeechBoundaryImmediate];
164171 } else {
172+ #if MAC_OS_X_VERSION_MIN_REQUIRED < 140000
165173 NSSpeechSynthesizer *ns_synth = synth;
166174 [ns_synth pauseSpeakingAtBoundary: NSSpeechImmediateBoundary];
175+ #endif
167176 }
168177 paused = true ;
169178}
@@ -173,8 +182,10 @@ - (void)resumeSpeaking {
173182 AVSpeechSynthesizer *av_synth = synth;
174183 [av_synth continueSpeaking ];
175184 } else {
185+ #if MAC_OS_X_VERSION_MIN_REQUIRED < 140000
176186 NSSpeechSynthesizer *ns_synth = synth;
177187 [ns_synth continueSpeaking ];
188+ #endif
178189 }
179190 paused = false ;
180191}
@@ -188,11 +199,13 @@ - (void)stopSpeaking {
188199 AVSpeechSynthesizer *av_synth = synth;
189200 [av_synth stopSpeakingAtBoundary: AVSpeechBoundaryImmediate];
190201 } else {
202+ #if MAC_OS_X_VERSION_MIN_REQUIRED < 140000
191203 NSSpeechSynthesizer *ns_synth = synth;
192204 if (have_utterance) {
193205 DisplayServer::get_singleton ()->tts_post_utterance_event (DisplayServerEnums::TTS_UTTERANCE_CANCELED , last_utterance);
194206 }
195207 [ns_synth stopSpeaking ];
208+ #endif
196209 }
197210 have_utterance = false ;
198211 speaking = false ;
@@ -252,6 +265,7 @@ - (Array)getVoices {
252265 list.push_back (voice_d);
253266 }
254267 } else {
268+ #if MAC_OS_X_VERSION_MIN_REQUIRED < 140000
255269 for (NSString *voiceIdentifierString in [NSSpeechSynthesizer availableVoices ]) {
256270 NSString *voiceLocaleIdentifier = [[NSSpeechSynthesizer attributesForVoice: voiceIdentifierString] objectForKey: NSVoiceLocaleIdentifier ];
257271 NSString *voiceName = [[NSSpeechSynthesizer attributesForVoice: voiceIdentifierString] objectForKey: NSVoiceName ];
@@ -261,6 +275,7 @@ - (Array)getVoices {
261275 voice_d[" language" ] = String ([voiceLocaleIdentifier UTF8String ]);
262276 list.push_back (voice_d);
263277 }
278+ #endif
264279 }
265280 return list;
266281}
0 commit comments