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
//! 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::*;
#[cfg(feature = "objc2-audio-toolbox")]
#[cfg(not(target_os = "watchos"))]
use objc2_audio_toolbox::*;
use objc2_foundation::*;

use crate::*;

extern_class!(
    /// The representation of a provided voice that is available for speech synthesis.
    ///
    /// `AVSpeechSynthesisProviderVoice`is distinct from
    /// `AVSpeechSynthesisVoice,`in that it is a voice provided to the system by an
    /// `AVSpeechSynthesisProviderAudioUnit.`An
    /// `AVSpeechSynthesisProviderVoice`will surface as an
    /// `AVSpeechSynthesisVoice`when using
    /// `AVSpeechSynthesisVoice.speechVoices().`The quality will always be listed as
    /// `.enhanced`
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avspeechsynthesisprovidervoice?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct AVSpeechSynthesisProviderVoice;
);

unsafe impl Send for AVSpeechSynthesisProviderVoice {}

unsafe impl Sync for AVSpeechSynthesisProviderVoice {}

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

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

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

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

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

impl AVSpeechSynthesisProviderVoice {
    extern_methods!(
        /// The localized name of the voice
        ///
        /// 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>;

        /// A unique identifier for the voice
        ///
        /// The recommended format is reverse domain notation.
        /// Behavior is undefined if identifiers are not unique for all voices within a given extension.
        ///
        /// 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>;

        /// A set of BCP 47 codes identifying the languages this synthesizer is primarily used for.
        ///
        /// These languages are what a user would expect a synthesizer to fully support and be primarily used for.
        ///
        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(primaryLanguages))]
        #[unsafe(method_family = none)]
        pub unsafe fn primaryLanguages(&self) -> Retained<NSArray<NSString>>;

        /// A superset of BCP 47 codes identifying the voice’s supported languages.
        ///
        /// These languages are what a user would expect a voice to be able to speak such that if the voice is given a multi-lingual phrase, it would be able to speak the entire phrase without a need to to switch voices. For example, a zh-CN voice could have
        /// `["zh-CN"]`as its
        /// `primaryLanguages,`but in
        /// `supportedLanguages`have
        /// `["zh-CN","en-US"]`indicating if it received "你好 means Hello", it would be able to speak the entire phrase.
        ///
        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(supportedLanguages))]
        #[unsafe(method_family = none)]
        pub unsafe fn supportedLanguages(&self) -> Retained<NSArray<NSString>>;

        /// The size of the voice (optional)
        ///
        /// This reported size of the voice package on disk, in bytes. Defaults to 0.
        ///
        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(voiceSize))]
        #[unsafe(method_family = none)]
        pub unsafe fn voiceSize(&self) -> i64;

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

        /// The voice version (optional)
        ///
        /// This is an optional property for bookkeeping. This value does not affect system behavior.
        ///
        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(version))]
        #[unsafe(method_family = none)]
        pub unsafe fn version(&self) -> Retained<NSString>;

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

        #[cfg(feature = "AVSpeechSynthesis")]
        /// The gender of the voice (optional)
        ///
        /// 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;

        #[cfg(feature = "AVSpeechSynthesis")]
        /// Setter for [`gender`][Self::gender].
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(setGender:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setGender(&self, gender: AVSpeechSynthesisVoiceGender);

        /// The age of the voice in years (optional)
        ///
        /// This is an optional property that indicates the age of this voice, to be treated as a personality trait. Defaults to 0.
        ///
        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(age))]
        #[unsafe(method_family = none)]
        pub unsafe fn age(&self) -> NSInteger;

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

        #[unsafe(method(initWithName:identifier:primaryLanguages:supportedLanguages:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithName_identifier_primaryLanguages_supportedLanguages(
            this: Allocated<Self>,
            name: &NSString,
            identifier: &NSString,
            primary_languages: &NSArray<NSString>,
            supported_languages: &NSArray<NSString>,
        ) -> Retained<Self>;

        #[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>;

        /// A call that indicates that a new voice or set of voices is available, or no longer available, for system use.
        ///
        /// Call this method to indicate to the system that there has been change in the availability of the voices your application is providing to the system.
        #[unsafe(method(updateSpeechVoices))]
        #[unsafe(method_family = none)]
        pub unsafe fn updateSpeechVoices();
    );
}

extern_class!(
    /// An
    /// `AVSpeechSynthesisProviderRequest`gets delivered to an
    /// `AVSpeechSynthesisProviderAudioUnit`in order to synthesize audio.
    /// This is distinct from an
    /// `AVSpeechUtterance,`which is a generic utterance to be spoken.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avspeechsynthesisproviderrequest?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct AVSpeechSynthesisProviderRequest;
);

unsafe impl Send for AVSpeechSynthesisProviderRequest {}

unsafe impl Sync for AVSpeechSynthesisProviderRequest {}

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

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

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

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

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

impl AVSpeechSynthesisProviderRequest {
    extern_methods!(
        /// The SSML representation of the text to be synthesized with the corresponding speech synthesis attributes for customization of pitch, rate, intonation, and more.
        ///
        /// See: https://www.w3.org/TR/speech-synthesis11/
        ///
        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(ssmlRepresentation))]
        #[unsafe(method_family = none)]
        pub unsafe fn ssmlRepresentation(&self) -> Retained<NSString>;

        /// The voice to be used in this speech request
        ///
        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(voice))]
        #[unsafe(method_family = none)]
        pub unsafe fn voice(&self) -> Retained<AVSpeechSynthesisProviderVoice>;

        #[unsafe(method(initWithSSMLRepresentation:voice:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithSSMLRepresentation_voice(
            this: Allocated<Self>,
            text: &NSString,
            voice: &AVSpeechSynthesisProviderVoice,
        ) -> Retained<Self>;

        #[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>;
    );
}

/// A block of information that is relevant to the generation of speech synthesis.
///
/// Parameter `metadata`: An array of speech synthesis metadata
///
/// Parameter `speechRequest`: The speech request associated with the metadata
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avspeechsynthesisprovideroutputblock?language=objc)
#[cfg(all(feature = "AVSpeechSynthesis", feature = "block2"))]
pub type AVSpeechSynthesisProviderOutputBlock = *mut block2::DynBlock<
    dyn Fn(NonNull<NSArray<AVSpeechSynthesisMarker>>, NonNull<AVSpeechSynthesisProviderRequest>),
>;

extern_class!(
    /// [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avspeechsynthesisprovideraudiounit?language=objc)
    #[unsafe(super(AUAudioUnit, NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    #[cfg(feature = "objc2-audio-toolbox")]
    #[cfg(not(target_os = "watchos"))]
    pub struct AVSpeechSynthesisProviderAudioUnit;
);

#[cfg(feature = "objc2-audio-toolbox")]
#[cfg(not(target_os = "watchos"))]
extern_conformance!(
    unsafe impl NSObjectProtocol for AVSpeechSynthesisProviderAudioUnit {}
);

#[cfg(feature = "objc2-audio-toolbox")]
#[cfg(not(target_os = "watchos"))]
impl AVSpeechSynthesisProviderAudioUnit {
    extern_methods!(
        /// Returns the voices this audio unit has available and ready for synthesis.
        ///
        /// This method should fetch and return the voices ready to synthesize that a user can select from (usually through Settings).
        /// Required for speech synthesizer audio unit extensions. An audio unit with a dynamic list of voices can override this property's getter to perform a more complex fetch.
        #[unsafe(method(speechVoices))]
        #[unsafe(method_family = none)]
        pub unsafe fn speechVoices(&self) -> Retained<NSArray<AVSpeechSynthesisProviderVoice>>;

        /// Setter for [`speechVoices`][Self::speechVoices].
        #[unsafe(method(setSpeechVoices:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setSpeechVoices(
            &self,
            speech_voices: &NSArray<AVSpeechSynthesisProviderVoice>,
        );

        #[cfg(all(feature = "AVSpeechSynthesis", feature = "block2"))]
        /// A property set by the host that is called by the audio unit to supply metadata for a speech request.
        ///
        /// A synthesizer should call this method when it has produced relevant data to the audio buffers it is sending back to the host. In some cases speech output may be delayed until these markers are delivered. For example, word highlighting depends on marker data from synthesizers in order to properly time which words are highlighted. Many speech synthesizers generate this information on the fly, while synthesizing the audio. The array of markers can reference future audio buffers that have yet to be delivered.
        ///
        /// There may be cases in which marker data is not fully known until further audio processing is done. In these cases, and other casers where marker data has changed, calling this block with marker data that contains perviously delivered audio buffer ranges will replace that audio buffer range's marker data, as it will be considered stale.
        ///
        /// # Safety
        ///
        /// - The returned block's argument 1 must be a valid pointer.
        /// - The returned block's argument 2 must be a valid pointer.
        #[unsafe(method(speechSynthesisOutputMetadataBlock))]
        #[unsafe(method_family = none)]
        pub unsafe fn speechSynthesisOutputMetadataBlock(
            &self,
        ) -> AVSpeechSynthesisProviderOutputBlock;

        #[cfg(all(feature = "AVSpeechSynthesis", feature = "block2"))]
        /// Setter for [`speechSynthesisOutputMetadataBlock`][Self::speechSynthesisOutputMetadataBlock].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        ///
        /// # Safety
        ///
        /// `speech_synthesis_output_metadata_block` must be a valid pointer or null.
        #[unsafe(method(setSpeechSynthesisOutputMetadataBlock:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setSpeechSynthesisOutputMetadataBlock(
            &self,
            speech_synthesis_output_metadata_block: AVSpeechSynthesisProviderOutputBlock,
        );

        /// Sends a new speech request to be synthesized
        ///
        /// Sends a new speech request to the synthesizer to render. When the synthesizer audio unit is finished generating audio buffers for the speech request, it should indicate this within its internal render block,
        /// `AUInternalRenderBlock,`specifically through the
        /// `AudioUnitRenderActionFlags`flag
        /// `kAudioOfflineUnitRenderAction_Complete.`
        #[unsafe(method(synthesizeSpeechRequest:))]
        #[unsafe(method_family = none)]
        pub unsafe fn synthesizeSpeechRequest(
            &self,
            speech_request: &AVSpeechSynthesisProviderRequest,
        );

        /// Informs the audio unit that the speech request job should be discarded.
        #[unsafe(method(cancelSpeechRequest))]
        #[unsafe(method_family = none)]
        pub unsafe fn cancelSpeechRequest(&self);
    );
}

/// Methods declared on superclass `AUAudioUnit`.
#[cfg(feature = "objc2-audio-toolbox")]
#[cfg(not(target_os = "watchos"))]
impl AVSpeechSynthesisProviderAudioUnit {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        /// Designated initializer.
        ///
        /// Parameter `componentDescription`: A single AUAudioUnit subclass may implement multiple audio units, for example, an effect
        /// that can also function as a generator, or a cluster of related effects. The component
        /// description specifies the component which was instantiated.
        ///
        /// Parameter `options`: Options for loading the unit in-process or out-of-process.
        ///
        /// Parameter `outError`: Returned in the event of failure.
        #[unsafe(method(initWithComponentDescription:options:error:_))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithComponentDescription_options_error(
            this: Allocated<Self>,
            component_description: AudioComponentDescription,
            options: AudioComponentInstantiationOptions,
        ) -> Result<Retained<Self>, Retained<NSError>>;

        /// Convenience initializer (omits options).
        #[unsafe(method(initWithComponentDescription:error:_))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithComponentDescription_error(
            this: Allocated<Self>,
            component_description: AudioComponentDescription,
        ) -> Result<Retained<Self>, Retained<NSError>>;
    );
}

/// Methods declared on superclass `NSObject`.
#[cfg(feature = "objc2-audio-toolbox")]
#[cfg(not(target_os = "watchos"))]
impl AVSpeechSynthesisProviderAudioUnit {
    extern_methods!(
        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;
    );
}