objc2-avf-audio 0.3.2

Bindings to the AVFAudio framework
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::ffi::*;
use core::ptr::NonNull;
use objc2::__framework_prelude::*;
use objc2_foundation::*;

use crate::*;

/// [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avspeechboundary?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct AVSpeechBoundary(pub NSInteger);
impl AVSpeechBoundary {
    #[doc(alias = "AVSpeechBoundaryImmediate")]
    pub const Immediate: Self = Self(0);
    #[doc(alias = "AVSpeechBoundaryWord")]
    pub const Word: Self = Self(1);
}

unsafe impl Encode for AVSpeechBoundary {
    const ENCODING: Encoding = NSInteger::ENCODING;
}

unsafe impl RefEncode for AVSpeechBoundary {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avspeechsynthesisvoicequality?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct AVSpeechSynthesisVoiceQuality(pub NSInteger);
impl AVSpeechSynthesisVoiceQuality {
    #[doc(alias = "AVSpeechSynthesisVoiceQualityDefault")]
    pub const Default: Self = Self(1);
    #[doc(alias = "AVSpeechSynthesisVoiceQualityEnhanced")]
    pub const Enhanced: Self = Self(2);
    #[doc(alias = "AVSpeechSynthesisVoiceQualityPremium")]
    pub const Premium: Self = Self(3);
}

unsafe impl Encode for AVSpeechSynthesisVoiceQuality {
    const ENCODING: Encoding = NSInteger::ENCODING;
}

unsafe impl RefEncode for AVSpeechSynthesisVoiceQuality {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avspeechsynthesisvoicegender?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct AVSpeechSynthesisVoiceGender(pub NSInteger);
impl AVSpeechSynthesisVoiceGender {
    #[doc(alias = "AVSpeechSynthesisVoiceGenderUnspecified")]
    pub const Unspecified: Self = Self(0);
    #[doc(alias = "AVSpeechSynthesisVoiceGenderMale")]
    pub const Male: Self = Self(1);
    #[doc(alias = "AVSpeechSynthesisVoiceGenderFemale")]
    pub const Female: Self = Self(2);
}

unsafe impl Encode for AVSpeechSynthesisVoiceGender {
    const ENCODING: Encoding = NSInteger::ENCODING;
}

unsafe impl RefEncode for AVSpeechSynthesisVoiceGender {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// Markers used in the output event callback. Used for providing metadata on synthesized audio.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avspeechsynthesismarkermark?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct AVSpeechSynthesisMarkerMark(pub NSInteger);
impl AVSpeechSynthesisMarkerMark {
    #[doc(alias = "AVSpeechSynthesisMarkerMarkPhoneme")]
    pub const Phoneme: Self = Self(0);
    #[doc(alias = "AVSpeechSynthesisMarkerMarkWord")]
    pub const Word: Self = Self(1);
    #[doc(alias = "AVSpeechSynthesisMarkerMarkSentence")]
    pub const Sentence: Self = Self(2);
    #[doc(alias = "AVSpeechSynthesisMarkerMarkParagraph")]
    pub const Paragraph: Self = Self(3);
    #[doc(alias = "AVSpeechSynthesisMarkerMarkBookmark")]
    pub const Bookmark: Self = Self(4);
}

unsafe impl Encode for AVSpeechSynthesisMarkerMark {
    const ENCODING: Encoding = NSInteger::ENCODING;
}

unsafe impl RefEncode for AVSpeechSynthesisMarkerMark {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avspeechutteranceminimumspeechrate?language=objc)
    pub static AVSpeechUtteranceMinimumSpeechRate: c_float;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avspeechutterancemaximumspeechrate?language=objc)
    pub static AVSpeechUtteranceMaximumSpeechRate: c_float;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avspeechutterancedefaultspeechrate?language=objc)
    pub static AVSpeechUtteranceDefaultSpeechRate: c_float;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avspeechsynthesisvoiceidentifieralex?language=objc)
    pub static AVSpeechSynthesisVoiceIdentifierAlex: &'static NSString;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avspeechsynthesisipanotationattribute?language=objc)
    pub static AVSpeechSynthesisIPANotationAttribute: &'static NSString;
}

/// [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avspeechsynthesizerbuffercallback?language=objc)
#[cfg(all(feature = "AVAudioBuffer", feature = "block2"))]
pub type AVSpeechSynthesizerBufferCallback = *mut block2::DynBlock<dyn Fn(NonNull<AVAudioBuffer>)>;

/// [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avspeechsynthesizermarkercallback?language=objc)
#[cfg(feature = "block2")]
pub type AVSpeechSynthesizerMarkerCallback =
    *mut block2::DynBlock<dyn Fn(NonNull<NSArray<AVSpeechSynthesisMarker>>)>;

/// [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avspeechsynthesispersonalvoiceauthorizationstatus?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct AVSpeechSynthesisPersonalVoiceAuthorizationStatus(pub NSUInteger);
impl AVSpeechSynthesisPersonalVoiceAuthorizationStatus {
    /// The app's authorization status has not yet been determined.
    ///
    /// When your app's status is not determined, calling the requestAuthorization: method prompts the user to grant or deny authorization.
    #[doc(alias = "AVSpeechSynthesisPersonalVoiceAuthorizationStatusNotDetermined")]
    pub const NotDetermined: Self = Self(0);
    /// The user denied your app's request to use personal voices.
    #[doc(alias = "AVSpeechSynthesisPersonalVoiceAuthorizationStatusDenied")]
    pub const Denied: Self = Self(1);
    /// Personal voices are unsupported on this device.
    #[doc(alias = "AVSpeechSynthesisPersonalVoiceAuthorizationStatusUnsupported")]
    pub const Unsupported: Self = Self(2);
    /// The user granted your app's request to use personal voices.
    #[doc(alias = "AVSpeechSynthesisPersonalVoiceAuthorizationStatusAuthorized")]
    pub const Authorized: Self = Self(3);
}

unsafe impl Encode for AVSpeechSynthesisPersonalVoiceAuthorizationStatus {
    const ENCODING: Encoding = NSUInteger::ENCODING;
}

unsafe impl RefEncode for AVSpeechSynthesisPersonalVoiceAuthorizationStatus {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avspeechsynthesisvoicetraits?language=objc)
// NS_OPTIONS
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct AVSpeechSynthesisVoiceTraits(pub NSUInteger);
bitflags::bitflags! {
    impl AVSpeechSynthesisVoiceTraits: NSUInteger {
        #[doc(alias = "AVSpeechSynthesisVoiceTraitNone")]
        const None = 0;
/// The voice is generally for novelty purposes, for example a character's voice in a game.
        #[doc(alias = "AVSpeechSynthesisVoiceTraitIsNoveltyVoice")]
        const IsNoveltyVoice = 1<<0;
/// The voice is was generated by, and belongs to the user. Voices with this trait will only be avilable when AVSpeechSynthesizer.personalVoiceAuthorizationStatus is AVSpeechSynthesisPersonalVoiceAuthorizationStatusAuthorized
        #[doc(alias = "AVSpeechSynthesisVoiceTraitIsPersonalVoice")]
        const IsPersonalVoice = 1<<1;
    }
}

unsafe impl Encode for AVSpeechSynthesisVoiceTraits {
    const ENCODING: Encoding = NSUInteger::ENCODING;
}

unsafe impl RefEncode for AVSpeechSynthesisVoiceTraits {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

extern "C" {
    /// Posted when available voices for speech synthesis on the system have changed. For example, if new 3rd party voices are available through a downloaded app, or if a new personal voice is available and the app is authorized to access personal voices.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avspeechsynthesisavailablevoicesdidchangenotification?language=objc)
    pub static AVSpeechSynthesisAvailableVoicesDidChangeNotification: &'static NSNotificationName;
}

extern_class!(
    /// AVSpeechSynthesisVoice encapsulates the attributes of the voice used to synthesize speech on the system.
    ///
    ///
    /// Retrieve a voice by specifying the language code your text should be spoken in, or by using voiceWithIdentifier
    /// for a known voice identifier.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avspeechsynthesisvoice?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct AVSpeechSynthesisVoice;
);

unsafe impl Send for AVSpeechSynthesisVoice {}

unsafe impl Sync for AVSpeechSynthesisVoice {}

extern_conformance!(
    unsafe impl NSCoding for AVSpeechSynthesisVoice {}
);

extern_conformance!(
    unsafe impl NSObjectProtocol for AVSpeechSynthesisVoice {}
);

extern_conformance!(
    unsafe impl NSSecureCoding for AVSpeechSynthesisVoice {}
);

impl AVSpeechSynthesisVoice {
    extern_methods!(
        #[unsafe(method(speechVoices))]
        #[unsafe(method_family = none)]
        pub unsafe fn speechVoices() -> Retained<NSArray<AVSpeechSynthesisVoice>>;

        #[unsafe(method(currentLanguageCode))]
        #[unsafe(method_family = none)]
        pub unsafe fn currentLanguageCode() -> Retained<NSString>;

        /// Use a BCP-47 language tag to specify the desired language and region.
        ///
        /// Parameter `languageCode`: Specifies the BCP-47 language tag that represents the voice.
        ///
        /// The default is the system's region and language.
        /// Passing in nil will return the default voice.
        /// Passing in an invalid languageCode will return nil.
        /// Will return enhanced quality voice if available, default quality otherwise.
        /// Examples: en-US (U.S. English), fr-CA (French Canadian)
        #[unsafe(method(voiceWithLanguage:))]
        #[unsafe(method_family = none)]
        pub unsafe fn voiceWithLanguage(
            language_code: Option<&NSString>,
        ) -> Option<Retained<AVSpeechSynthesisVoice>>;

        /// Retrieve a voice by its identifier.
        ///
        /// Parameter `identifier`: A unique identifier for a voice.
        ///
        /// Passing in an invalid identifier will return nil.
        /// Returns nil if the identifier is valid, but the voice is not available on device (i.e. not yet downloaded by the user).
        #[unsafe(method(voiceWithIdentifier:))]
        #[unsafe(method_family = none)]
        pub unsafe fn voiceWithIdentifier(
            identifier: &NSString,
        ) -> Option<Retained<AVSpeechSynthesisVoice>>;

        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(language))]
        #[unsafe(method_family = none)]
        pub unsafe fn language(&self) -> Retained<NSString>;

        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(identifier))]
        #[unsafe(method_family = none)]
        pub unsafe fn identifier(&self) -> Retained<NSString>;

        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(name))]
        #[unsafe(method_family = none)]
        pub unsafe fn name(&self) -> Retained<NSString>;

        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(quality))]
        #[unsafe(method_family = none)]
        pub unsafe fn quality(&self) -> AVSpeechSynthesisVoiceQuality;

        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(gender))]
        #[unsafe(method_family = none)]
        pub unsafe fn gender(&self) -> AVSpeechSynthesisVoiceGender;

        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(audioFileSettings))]
        #[unsafe(method_family = none)]
        pub unsafe fn audioFileSettings(&self) -> Retained<NSDictionary<NSString, AnyObject>>;

        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(voiceTraits))]
        #[unsafe(method_family = none)]
        pub unsafe fn voiceTraits(&self) -> AVSpeechSynthesisVoiceTraits;
    );
}

/// Methods declared on superclass `NSObject`.
impl AVSpeechSynthesisVoice {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;
    );
}

extern_class!(
    /// AVSpeechUtterance is the atom of speaking a string or pausing the synthesizer.
    ///
    ///
    /// To start speaking, specify the AVSpeechSynthesisVoice and the string to be spoken, then optionally change the rate, pitch or volume if desired.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avspeechutterance?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct AVSpeechUtterance;
);

extern_conformance!(
    unsafe impl NSCoding for AVSpeechUtterance {}
);

extern_conformance!(
    unsafe impl NSCopying for AVSpeechUtterance {}
);

unsafe impl CopyingHelper for AVSpeechUtterance {
    type Result = Self;
}

extern_conformance!(
    unsafe impl NSObjectProtocol for AVSpeechUtterance {}
);

extern_conformance!(
    unsafe impl NSSecureCoding for AVSpeechUtterance {}
);

impl AVSpeechUtterance {
    extern_methods!(
        #[unsafe(method(speechUtteranceWithString:))]
        #[unsafe(method_family = none)]
        pub unsafe fn speechUtteranceWithString(string: &NSString) -> Retained<Self>;

        #[unsafe(method(speechUtteranceWithAttributedString:))]
        #[unsafe(method_family = none)]
        pub unsafe fn speechUtteranceWithAttributedString(
            string: &NSAttributedString,
        ) -> Retained<Self>;

        /// A speech utterance that expects markup written using the Speech Synthesis Markup Language (SSML) standard.
        /// Returns nil if invalid SSML is passed in.
        #[unsafe(method(speechUtteranceWithSSMLRepresentation:))]
        #[unsafe(method_family = none)]
        pub unsafe fn speechUtteranceWithSSMLRepresentation(
            string: &NSString,
        ) -> Option<Retained<Self>>;

        #[unsafe(method(initWithString:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithString(this: Allocated<Self>, string: &NSString) -> Retained<Self>;

        #[unsafe(method(initWithAttributedString:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithAttributedString(
            this: Allocated<Self>,
            string: &NSAttributedString,
        ) -> Retained<Self>;

        /// A speech utterance that expects markup written using the Speech Synthesis Markup Language (SSML)  standard.
        ///
        ///
        /// Uses SSML markup to add attributes. If using SSML to request voices that fall under certain attributes, a single
        /// utterance may be split into multiple parts, each sent to the appropriate synthesizer. If no voice matches the properties,
        /// the voice in the
        /// `voice`property of the utterance will be used. If no
        /// `voice`is specified, the system's default
        /// will be used.
        /// `AVSpeechUtterance`properties that affect the prosidy of a voice such as
        /// `rate,``pitchMultiplier,``pitchMultiplier`will not apply to an utterance that uses an SSML representation.
        ///
        /// Returns nil if invalid SSML is passed in.
        #[unsafe(method(initWithSSMLRepresentation:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithSSMLRepresentation(
            this: Allocated<Self>,
            string: &NSString,
        ) -> Option<Retained<Self>>;

        #[unsafe(method(voice))]
        #[unsafe(method_family = none)]
        pub unsafe fn voice(&self) -> Option<Retained<AVSpeechSynthesisVoice>>;

        /// Setter for [`voice`][Self::voice].
        #[unsafe(method(setVoice:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setVoice(&self, voice: Option<&AVSpeechSynthesisVoice>);

        #[unsafe(method(speechString))]
        #[unsafe(method_family = none)]
        pub unsafe fn speechString(&self) -> Retained<NSString>;

        #[unsafe(method(attributedSpeechString))]
        #[unsafe(method_family = none)]
        pub unsafe fn attributedSpeechString(&self) -> Retained<NSAttributedString>;

        #[unsafe(method(rate))]
        #[unsafe(method_family = none)]
        pub unsafe fn rate(&self) -> c_float;

        /// Setter for [`rate`][Self::rate].
        #[unsafe(method(setRate:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setRate(&self, rate: c_float);

        #[unsafe(method(pitchMultiplier))]
        #[unsafe(method_family = none)]
        pub unsafe fn pitchMultiplier(&self) -> c_float;

        /// Setter for [`pitchMultiplier`][Self::pitchMultiplier].
        #[unsafe(method(setPitchMultiplier:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setPitchMultiplier(&self, pitch_multiplier: c_float);

        #[unsafe(method(volume))]
        #[unsafe(method_family = none)]
        pub unsafe fn volume(&self) -> c_float;

        /// Setter for [`volume`][Self::volume].
        #[unsafe(method(setVolume:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setVolume(&self, volume: c_float);

        #[unsafe(method(prefersAssistiveTechnologySettings))]
        #[unsafe(method_family = none)]
        pub unsafe fn prefersAssistiveTechnologySettings(&self) -> bool;

        /// Setter for [`prefersAssistiveTechnologySettings`][Self::prefersAssistiveTechnologySettings].
        #[unsafe(method(setPrefersAssistiveTechnologySettings:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setPrefersAssistiveTechnologySettings(
            &self,
            prefers_assistive_technology_settings: bool,
        );

        #[unsafe(method(preUtteranceDelay))]
        #[unsafe(method_family = none)]
        pub unsafe fn preUtteranceDelay(&self) -> NSTimeInterval;

        /// Setter for [`preUtteranceDelay`][Self::preUtteranceDelay].
        #[unsafe(method(setPreUtteranceDelay:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setPreUtteranceDelay(&self, pre_utterance_delay: NSTimeInterval);

        #[unsafe(method(postUtteranceDelay))]
        #[unsafe(method_family = none)]
        pub unsafe fn postUtteranceDelay(&self) -> NSTimeInterval;

        /// Setter for [`postUtteranceDelay`][Self::postUtteranceDelay].
        #[unsafe(method(setPostUtteranceDelay:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setPostUtteranceDelay(&self, post_utterance_delay: NSTimeInterval);
    );
}

/// Methods declared on superclass `NSObject`.
impl AVSpeechUtterance {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;
    );
}

extern_class!(
    /// AVSpeechSynthesizer allows speaking of speech utterances with a basic queuing mechanism.
    ///
    ///
    /// Create an instance of AVSpeechSynthesizer to start generating synthesized speech by using AVSpeechUtterance objects.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avspeechsynthesizer?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct AVSpeechSynthesizer;
);

extern_conformance!(
    unsafe impl NSObjectProtocol for AVSpeechSynthesizer {}
);

impl AVSpeechSynthesizer {
    extern_methods!(
        #[unsafe(method(delegate))]
        #[unsafe(method_family = none)]
        pub unsafe fn delegate(
            &self,
        ) -> Option<Retained<ProtocolObject<dyn AVSpeechSynthesizerDelegate>>>;

        /// Setter for [`delegate`][Self::delegate].
        ///
        /// This is a [weak property][objc2::topics::weak_property].
        #[unsafe(method(setDelegate:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setDelegate(
            &self,
            delegate: Option<&ProtocolObject<dyn AVSpeechSynthesizerDelegate>>,
        );

        #[unsafe(method(isSpeaking))]
        #[unsafe(method_family = none)]
        pub unsafe fn isSpeaking(&self) -> bool;

        #[unsafe(method(isPaused))]
        #[unsafe(method_family = none)]
        pub unsafe fn isPaused(&self) -> bool;

        #[unsafe(method(speakUtterance:))]
        #[unsafe(method_family = none)]
        pub unsafe fn speakUtterance(&self, utterance: &AVSpeechUtterance);

        #[cfg(all(feature = "AVAudioBuffer", feature = "block2"))]
        /// # Safety
        ///
        /// `buffer_callback` must be a valid pointer.
        #[unsafe(method(writeUtterance:toBufferCallback:))]
        #[unsafe(method_family = none)]
        pub unsafe fn writeUtterance_toBufferCallback(
            &self,
            utterance: &AVSpeechUtterance,
            buffer_callback: AVSpeechSynthesizerBufferCallback,
        );

        #[cfg(all(feature = "AVAudioBuffer", feature = "block2"))]
        /// Use this method to receive audio buffers and associated metadata that can be used to store or further process synthesized speech.
        /// The dictionary provided by -[AVSpeechSynthesisVoice audioFileSettings] can be used to create an AVAudioFile.
        ///
        /// # Safety
        ///
        /// - `buffer_callback` must be a valid pointer.
        /// - `marker_callback` must be a valid pointer.
        #[unsafe(method(writeUtterance:toBufferCallback:toMarkerCallback:))]
        #[unsafe(method_family = none)]
        pub unsafe fn writeUtterance_toBufferCallback_toMarkerCallback(
            &self,
            utterance: &AVSpeechUtterance,
            buffer_callback: AVSpeechSynthesizerBufferCallback,
            marker_callback: AVSpeechSynthesizerMarkerCallback,
        );

        #[unsafe(method(stopSpeakingAtBoundary:))]
        #[unsafe(method_family = none)]
        pub unsafe fn stopSpeakingAtBoundary(&self, boundary: AVSpeechBoundary) -> bool;

        #[unsafe(method(pauseSpeakingAtBoundary:))]
        #[unsafe(method_family = none)]
        pub unsafe fn pauseSpeakingAtBoundary(&self, boundary: AVSpeechBoundary) -> bool;

        #[unsafe(method(continueSpeaking))]
        #[unsafe(method_family = none)]
        pub unsafe fn continueSpeaking(&self) -> bool;

        #[cfg(feature = "AVAudioSessionRoute")]
        #[unsafe(method(outputChannels))]
        #[unsafe(method_family = none)]
        pub unsafe fn outputChannels(
            &self,
        ) -> Option<Retained<NSArray<AVAudioSessionChannelDescription>>>;

        #[cfg(feature = "AVAudioSessionRoute")]
        /// Setter for [`outputChannels`][Self::outputChannels].
        #[unsafe(method(setOutputChannels:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setOutputChannels(
            &self,
            output_channels: Option<&NSArray<AVAudioSessionChannelDescription>>,
        );

        #[unsafe(method(usesApplicationAudioSession))]
        #[unsafe(method_family = none)]
        pub unsafe fn usesApplicationAudioSession(&self) -> bool;

        /// Setter for [`usesApplicationAudioSession`][Self::usesApplicationAudioSession].
        #[unsafe(method(setUsesApplicationAudioSession:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setUsesApplicationAudioSession(&self, uses_application_audio_session: bool);

        #[unsafe(method(mixToTelephonyUplink))]
        #[unsafe(method_family = none)]
        pub unsafe fn mixToTelephonyUplink(&self) -> bool;

        /// Setter for [`mixToTelephonyUplink`][Self::mixToTelephonyUplink].
        #[unsafe(method(setMixToTelephonyUplink:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setMixToTelephonyUplink(&self, mix_to_telephony_uplink: bool);

        #[cfg(feature = "block2")]
        /// Asks the user to allow your app to use personal voices for speech synthesis
        ///
        /// Call this method before performing any other tasks associated with speech synthesis using personal voices. This method executes asynchronously, returning shortly after you call it. At some point later, the system calls the provided handler block with the results.
        ///
        /// When your app's authorization status is PersonalVoiceAuthorizationStatus.notDetermined, this method causes the system to prompt the user to grant or deny permission for your app to use personal voices. The user's response is saved so that future calls to this method do not prompt the user again.
        #[unsafe(method(requestPersonalVoiceAuthorizationWithCompletionHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn requestPersonalVoiceAuthorizationWithCompletionHandler(
            handler: &block2::DynBlock<dyn Fn(AVSpeechSynthesisPersonalVoiceAuthorizationStatus)>,
        );

        /// Returns your app's current authorization to use personal voices.
        ///
        ///
        /// The user can reject your app's request to use personal voices, but your request can also be denied if personal voices are not supported on the device. The app can also change your app's authorization status at any time from the Settings app.
        ///
        ///
        /// Returns: The app's current authorization status value. For a list of values, see AVSpeechSynthesisPersonalVoiceAuthorizationStatus.
        #[unsafe(method(personalVoiceAuthorizationStatus))]
        #[unsafe(method_family = none)]
        pub unsafe fn personalVoiceAuthorizationStatus(
        ) -> AVSpeechSynthesisPersonalVoiceAuthorizationStatus;
    );
}

/// Methods declared on superclass `NSObject`.
impl AVSpeechSynthesizer {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;
    );
}

extern_protocol!(
    /// Defines an interface for delegates of AVSpeechSynthesizer to receive notifications of important speech utterance events.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avspeechsynthesizerdelegate?language=objc)
    pub unsafe trait AVSpeechSynthesizerDelegate: NSObjectProtocol + Send + Sync {
        #[optional]
        #[unsafe(method(speechSynthesizer:didStartSpeechUtterance:))]
        #[unsafe(method_family = none)]
        unsafe fn speechSynthesizer_didStartSpeechUtterance(
            &self,
            synthesizer: &AVSpeechSynthesizer,
            utterance: &AVSpeechUtterance,
        );

        #[optional]
        #[unsafe(method(speechSynthesizer:didFinishSpeechUtterance:))]
        #[unsafe(method_family = none)]
        unsafe fn speechSynthesizer_didFinishSpeechUtterance(
            &self,
            synthesizer: &AVSpeechSynthesizer,
            utterance: &AVSpeechUtterance,
        );

        #[optional]
        #[unsafe(method(speechSynthesizer:didPauseSpeechUtterance:))]
        #[unsafe(method_family = none)]
        unsafe fn speechSynthesizer_didPauseSpeechUtterance(
            &self,
            synthesizer: &AVSpeechSynthesizer,
            utterance: &AVSpeechUtterance,
        );

        #[optional]
        #[unsafe(method(speechSynthesizer:didContinueSpeechUtterance:))]
        #[unsafe(method_family = none)]
        unsafe fn speechSynthesizer_didContinueSpeechUtterance(
            &self,
            synthesizer: &AVSpeechSynthesizer,
            utterance: &AVSpeechUtterance,
        );

        #[optional]
        #[unsafe(method(speechSynthesizer:didCancelSpeechUtterance:))]
        #[unsafe(method_family = none)]
        unsafe fn speechSynthesizer_didCancelSpeechUtterance(
            &self,
            synthesizer: &AVSpeechSynthesizer,
            utterance: &AVSpeechUtterance,
        );

        #[optional]
        #[unsafe(method(speechSynthesizer:willSpeakRangeOfSpeechString:utterance:))]
        #[unsafe(method_family = none)]
        unsafe fn speechSynthesizer_willSpeakRangeOfSpeechString_utterance(
            &self,
            synthesizer: &AVSpeechSynthesizer,
            character_range: NSRange,
            utterance: &AVSpeechUtterance,
        );

        #[optional]
        #[unsafe(method(speechSynthesizer:willSpeakMarker:utterance:))]
        #[unsafe(method_family = none)]
        unsafe fn speechSynthesizer_willSpeakMarker_utterance(
            &self,
            synthesizer: &AVSpeechSynthesizer,
            marker: &AVSpeechSynthesisMarker,
            utterance: &AVSpeechUtterance,
        );
    }
);

extern_class!(
    /// [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avspeechsynthesismarker?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct AVSpeechSynthesisMarker;
);

unsafe impl Send for AVSpeechSynthesisMarker {}

unsafe impl Sync for AVSpeechSynthesisMarker {}

extern_conformance!(
    unsafe impl NSCoding for AVSpeechSynthesisMarker {}
);

extern_conformance!(
    unsafe impl NSCopying for AVSpeechSynthesisMarker {}
);

unsafe impl CopyingHelper for AVSpeechSynthesisMarker {
    type Result = Self;
}

extern_conformance!(
    unsafe impl NSObjectProtocol for AVSpeechSynthesisMarker {}
);

extern_conformance!(
    unsafe impl NSSecureCoding for AVSpeechSynthesisMarker {}
);

impl AVSpeechSynthesisMarker {
    extern_methods!(
        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(mark))]
        #[unsafe(method_family = none)]
        pub unsafe fn mark(&self) -> AVSpeechSynthesisMarkerMark;

        /// Setter for [`mark`][Self::mark].
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(setMark:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setMark(&self, mark: AVSpeechSynthesisMarkerMark);

        /// Byte offset into the associated audio buffer
        ///
        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(byteSampleOffset))]
        #[unsafe(method_family = none)]
        pub unsafe fn byteSampleOffset(&self) -> NSUInteger;

        /// Setter for [`byteSampleOffset`][Self::byteSampleOffset].
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(setByteSampleOffset:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setByteSampleOffset(&self, byte_sample_offset: NSUInteger);

        /// The location and length of the pertaining speech request's SSML text. This marker applies to the range of characters represented by the NSString.
        ///
        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(textRange))]
        #[unsafe(method_family = none)]
        pub unsafe fn textRange(&self) -> NSRange;

        /// Setter for [`textRange`][Self::textRange].
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(setTextRange:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setTextRange(&self, text_range: NSRange);

        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(bookmarkName))]
        #[unsafe(method_family = none)]
        pub unsafe fn bookmarkName(&self) -> Retained<NSString>;

        /// Setter for [`bookmarkName`][Self::bookmarkName].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(setBookmarkName:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setBookmarkName(&self, bookmark_name: &NSString);

        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(phoneme))]
        #[unsafe(method_family = none)]
        pub unsafe fn phoneme(&self) -> Retained<NSString>;

        /// Setter for [`phoneme`][Self::phoneme].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(setPhoneme:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setPhoneme(&self, phoneme: &NSString);

        #[unsafe(method(initWithMarkerType:forTextRange:atByteSampleOffset:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithMarkerType_forTextRange_atByteSampleOffset(
            this: Allocated<Self>,
            r#type: AVSpeechSynthesisMarkerMark,
            range: NSRange,
            byte_sample_offset: NSUInteger,
        ) -> Retained<Self>;

        #[unsafe(method(initWithWordRange:atByteSampleOffset:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithWordRange_atByteSampleOffset(
            this: Allocated<Self>,
            range: NSRange,
            byte_sample_offset: NSInteger,
        ) -> Retained<Self>;

        #[unsafe(method(initWithSentenceRange:atByteSampleOffset:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithSentenceRange_atByteSampleOffset(
            this: Allocated<Self>,
            range: NSRange,
            byte_sample_offset: NSInteger,
        ) -> Retained<Self>;

        #[unsafe(method(initWithParagraphRange:atByteSampleOffset:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithParagraphRange_atByteSampleOffset(
            this: Allocated<Self>,
            range: NSRange,
            byte_sample_offset: NSInteger,
        ) -> Retained<Self>;

        #[unsafe(method(initWithPhonemeString:atByteSampleOffset:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithPhonemeString_atByteSampleOffset(
            this: Allocated<Self>,
            phoneme: &NSString,
            byte_sample_offset: NSInteger,
        ) -> Retained<Self>;

        #[unsafe(method(initWithBookmarkName:atByteSampleOffset:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithBookmarkName_atByteSampleOffset(
            this: Allocated<Self>,
            mark: &NSString,
            byte_sample_offset: NSInteger,
        ) -> Retained<Self>;
    );
}

/// Methods declared on superclass `NSObject`.
impl AVSpeechSynthesisMarker {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;
    );
}