objc2_speech/generated/
SFSpeechRecognitionTask.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6use objc2_foundation::*;
7
8use crate::*;
9
10/// The state of the task associated with the recognition request.
11///
12/// See also [Apple's documentation](https://developer.apple.com/documentation/speech/sfspeechrecognitiontaskstate?language=objc)
13// NS_ENUM
14#[repr(transparent)]
15#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
16pub struct SFSpeechRecognitionTaskState(pub NSInteger);
17impl SFSpeechRecognitionTaskState {
18    /// Speech recognition (potentially including audio recording) has not yet started.
19    #[doc(alias = "SFSpeechRecognitionTaskStateStarting")]
20    pub const Starting: Self = Self(0);
21    /// Speech recognition (potentially including audio recording) is in progress.
22    #[doc(alias = "SFSpeechRecognitionTaskStateRunning")]
23    pub const Running: Self = Self(1);
24    /// Audio recording has stopped, but delivery of recognition results may continue.
25    #[doc(alias = "SFSpeechRecognitionTaskStateFinishing")]
26    pub const Finishing: Self = Self(2);
27    /// Delivery of recognition results has finished, but audio recording may be ongoing.
28    #[doc(alias = "SFSpeechRecognitionTaskStateCanceling")]
29    pub const Canceling: Self = Self(3);
30    /// Delivery of recognition requests has finished and audio recording has stopped.
31    #[doc(alias = "SFSpeechRecognitionTaskStateCompleted")]
32    pub const Completed: Self = Self(4);
33}
34
35unsafe impl Encode for SFSpeechRecognitionTaskState {
36    const ENCODING: Encoding = NSInteger::ENCODING;
37}
38
39unsafe impl RefEncode for SFSpeechRecognitionTaskState {
40    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
41}
42
43extern_class!(
44    /// A task object for monitoring the speech recognition progress.
45    ///
46    /// Use an `SFSpeechRecognitionTask` object to determine the state of a speech recognition task, to cancel an ongoing task, or to signal the end of the task.
47    ///
48    /// You don't create speech recognition task objects directly. Instead, you receive one of these objects after calling ``SFSpeechRecognizer/recognitionTask(with:resultHandler:)`` or ``SFSpeechRecognizer/recognitionTask(with:delegate:)`` on your ``SFSpeechRecognizer`` object.
49    ///
50    /// See also [Apple's documentation](https://developer.apple.com/documentation/speech/sfspeechrecognitiontask?language=objc)
51    #[unsafe(super(NSObject))]
52    #[derive(Debug, PartialEq, Eq, Hash)]
53    pub struct SFSpeechRecognitionTask;
54);
55
56extern_conformance!(
57    unsafe impl NSObjectProtocol for SFSpeechRecognitionTask {}
58);
59
60impl SFSpeechRecognitionTask {
61    extern_methods!(
62        /// The current state of the speech recognition task.
63        ///
64        /// Check the value of this property to get the state of the in-progress speech recognition session. For valid values, see ``SFSpeechRecognitionTaskState``.
65        #[unsafe(method(state))]
66        #[unsafe(method_family = none)]
67        pub unsafe fn state(&self) -> SFSpeechRecognitionTaskState;
68
69        /// A Boolean value that indicates whether audio input has stopped.
70        ///
71        /// By default, the value of this property is `false`.
72        #[unsafe(method(isFinishing))]
73        #[unsafe(method_family = none)]
74        pub unsafe fn isFinishing(&self) -> bool;
75
76        /// Stops accepting new audio and finishes processing on the audio input that has already been accepted.
77        ///
78        /// For audio buffer–based recognition, recognition does not finish until this method is called, so be sure to call it when the audio source is exhausted.
79        #[unsafe(method(finish))]
80        #[unsafe(method_family = none)]
81        pub unsafe fn finish(&self);
82
83        /// A Boolean value that indicates whether the speech recognition task was canceled.
84        ///
85        /// By default, the value of this property is `false`.
86        #[unsafe(method(isCancelled))]
87        #[unsafe(method_family = none)]
88        pub unsafe fn isCancelled(&self) -> bool;
89
90        /// Cancels the current speech recognition task.
91        ///
92        /// You can cancel recognition tasks for both prerecorded and live audio input. For example, you might cancel a task in response to a user action or because the recording was interrupted.
93        ///
94        /// When canceling a task, be sure to release any resources associated with the task, such as the audio input resources you are using to capture audio samples.
95        #[unsafe(method(cancel))]
96        #[unsafe(method_family = none)]
97        pub unsafe fn cancel(&self);
98
99        /// An error object that specifies the error that occurred during a speech recognition task.
100        ///
101        /// The system may return one of the errors listed in the table below.
102        ///
103        /// | Error Code | Error Domain | Description |
104        /// |---|---|---|
105        /// | `102` | `kLSRErrorDomain` | Assets are not installed. |
106        /// | `201` | `kLSRErrorDomain` | Siri or Dictation is disabled. |
107        /// | `300` | `kLSRErrorDomain` | Failed to initialize recognizer. |
108        /// | `301` | `kLSRErrorDomain` | Request was canceled. |
109        /// | `203` | `kAFAssistantErrorDomain` | Failure occurred during speech recognition. |
110        /// | `1100` | `kAFAssistantErrorDomain` | Trying to start recognition while an earlier instance is still active. |
111        /// | `1101` | `kAFAssistantErrorDomain` | Connection to speech process was invalidated. |
112        /// | `1107` | `kAFAssistantErrorDomain` | Connection to speech process was interrupted. |
113        /// | `1110` | `kAFAssistantErrorDomain` | Failed to recognize any speech. |
114        /// | `1700` | `kAFAssistantErrorDomain` | Request is not authorized. |
115        #[unsafe(method(error))]
116        #[unsafe(method_family = none)]
117        pub unsafe fn error(&self) -> Option<Retained<NSError>>;
118    );
119}
120
121/// Methods declared on superclass `NSObject`.
122impl SFSpeechRecognitionTask {
123    extern_methods!(
124        #[unsafe(method(init))]
125        #[unsafe(method_family = init)]
126        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
127
128        #[unsafe(method(new))]
129        #[unsafe(method_family = new)]
130        pub unsafe fn new() -> Retained<Self>;
131    );
132}
133
134extern_protocol!(
135    /// A protocol with methods for managing multi-utterance speech recognition requests.
136    ///
137    /// The methods of this protocol give you fine-grained control over the speech recognition process. Specifically, you use this protocol when you want to know the following:
138    ///
139    /// - When the first utterances of speech occur in the audio.
140    /// - When the speech recognizer stops accepting audio.
141    /// - When the speech recognition process finishes or is canceled.
142    /// - When the speech recognizer generates a potential transcription.
143    ///
144    /// Adopt the methods of this protocol in an object and pass that object in to the `delegate` parameter of ``SFSpeechRecognizer/recognitionTask(with:delegate:)`` when starting your speech recognition task.
145    ///
146    /// See also [Apple's documentation](https://developer.apple.com/documentation/speech/sfspeechrecognitiontaskdelegate?language=objc)
147    pub unsafe trait SFSpeechRecognitionTaskDelegate: NSObjectProtocol {
148        /// Tells the delegate when the task first detects speech in the source audio.
149        ///
150        /// - Parameters:
151        /// - task: The speech recognition task (an ``SFSpeechRecognitionTask`` object) that represents the request.
152        #[optional]
153        #[unsafe(method(speechRecognitionDidDetectSpeech:))]
154        #[unsafe(method_family = none)]
155        unsafe fn speechRecognitionDidDetectSpeech(&self, task: &SFSpeechRecognitionTask);
156
157        #[cfg(feature = "SFTranscription")]
158        /// Tells the delegate that a hypothesized transcription is available.
159        ///
160        /// This method is called for all recognitions, including partial recognitions.
161        ///
162        /// - Parameters:
163        /// - task: The speech recognition task (an ``SFSpeechRecognitionTask`` object) that represents the request.
164        /// - transcription: The hypothesized transcription in an ``SFTranscription`` object.
165        #[optional]
166        #[unsafe(method(speechRecognitionTask:didHypothesizeTranscription:))]
167        #[unsafe(method_family = none)]
168        unsafe fn speechRecognitionTask_didHypothesizeTranscription(
169            &self,
170            task: &SFSpeechRecognitionTask,
171            transcription: &SFTranscription,
172        );
173
174        #[cfg(feature = "SFSpeechRecognitionResult")]
175        /// Tells the delegate when the final utterance is recognized.
176        ///
177        /// When this method is called, the delegate should expect no further information about the utterance to be reported.
178        ///
179        /// - Parameters:
180        /// - task: The speech recognition task (an ``SFSpeechRecognitionTask`` object) that represents the request.
181        /// - recognitionResult: A recognized utterance that contains one or more transcription hypotheses in an ``SFSpeechRecognitionResult`` object.
182        #[optional]
183        #[unsafe(method(speechRecognitionTask:didFinishRecognition:))]
184        #[unsafe(method_family = none)]
185        unsafe fn speechRecognitionTask_didFinishRecognition(
186            &self,
187            task: &SFSpeechRecognitionTask,
188            recognition_result: &SFSpeechRecognitionResult,
189        );
190
191        /// Tells the delegate when the task is no longer accepting new audio input, even if final processing is in progress.
192        ///
193        /// - Parameters:
194        /// - task: The speech recognition task (an ``SFSpeechRecognitionTask`` object) that represents the request.
195        #[optional]
196        #[unsafe(method(speechRecognitionTaskFinishedReadingAudio:))]
197        #[unsafe(method_family = none)]
198        unsafe fn speechRecognitionTaskFinishedReadingAudio(&self, task: &SFSpeechRecognitionTask);
199
200        /// Tells the delegate that the task has been canceled.
201        ///
202        /// A speech recognition task can be canceled by the user, by your app, or by the system.
203        ///
204        /// - Parameters:
205        /// - task: The speech recognition task (an ``SFSpeechRecognitionTask`` object) that represents the request.
206        #[optional]
207        #[unsafe(method(speechRecognitionTaskWasCancelled:))]
208        #[unsafe(method_family = none)]
209        unsafe fn speechRecognitionTaskWasCancelled(&self, task: &SFSpeechRecognitionTask);
210
211        /// Tells the delegate when the recognition of all requested utterances is finished.
212        ///
213        /// - Parameters:
214        /// - task: The speech recognition task (an ``SFSpeechRecognitionTask`` object) that represents the request.
215        /// - successfully: A Boolean value that indicates whether the task was successful. When this parameter is `false`, use the ``SFSpeechRecognitionTask/error`` property of the task to get information about why the task was unsuccessful.
216        #[optional]
217        #[unsafe(method(speechRecognitionTask:didFinishSuccessfully:))]
218        #[unsafe(method_family = none)]
219        unsafe fn speechRecognitionTask_didFinishSuccessfully(
220            &self,
221            task: &SFSpeechRecognitionTask,
222            successfully: bool,
223        );
224
225        /// Tells the delegate how much audio has been processed by the task.
226        ///
227        /// - Parameters:
228        /// - task: The speech recognition task (an ``SFSpeechRecognitionTask`` object) that represents the request.
229        /// - duration: The seconds of audio input that the recognizer has processed.
230        #[optional]
231        #[unsafe(method(speechRecognitionTask:didProcessAudioDuration:))]
232        #[unsafe(method_family = none)]
233        unsafe fn speechRecognitionTask_didProcessAudioDuration(
234            &self,
235            task: &SFSpeechRecognitionTask,
236            duration: NSTimeInterval,
237        );
238    }
239);