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
//! 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::*;
/// The state of the task associated with the recognition request.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/speech/sfspeechrecognitiontaskstate?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct SFSpeechRecognitionTaskState(pub NSInteger);
impl SFSpeechRecognitionTaskState {
/// Speech recognition (potentially including audio recording) has not yet started.
#[doc(alias = "SFSpeechRecognitionTaskStateStarting")]
pub const Starting: Self = Self(0);
/// Speech recognition (potentially including audio recording) is in progress.
#[doc(alias = "SFSpeechRecognitionTaskStateRunning")]
pub const Running: Self = Self(1);
/// Audio recording has stopped, but delivery of recognition results may continue.
#[doc(alias = "SFSpeechRecognitionTaskStateFinishing")]
pub const Finishing: Self = Self(2);
/// Delivery of recognition results has finished, but audio recording may be ongoing.
#[doc(alias = "SFSpeechRecognitionTaskStateCanceling")]
pub const Canceling: Self = Self(3);
/// Delivery of recognition requests has finished and audio recording has stopped.
#[doc(alias = "SFSpeechRecognitionTaskStateCompleted")]
pub const Completed: Self = Self(4);
}
unsafe impl Encode for SFSpeechRecognitionTaskState {
const ENCODING: Encoding = NSInteger::ENCODING;
}
unsafe impl RefEncode for SFSpeechRecognitionTaskState {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
extern_class!(
/// A task object for monitoring the speech recognition progress.
///
/// 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.
///
/// 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.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/speech/sfspeechrecognitiontask?language=objc)
#[unsafe(super(NSObject))]
#[derive(Debug, PartialEq, Eq, Hash)]
pub struct SFSpeechRecognitionTask;
);
extern_conformance!(
unsafe impl NSObjectProtocol for SFSpeechRecognitionTask {}
);
impl SFSpeechRecognitionTask {
extern_methods!(
/// The current state of the speech recognition task.
///
/// Check the value of this property to get the state of the in-progress speech recognition session. For valid values, see ``SFSpeechRecognitionTaskState``.
#[unsafe(method(state))]
#[unsafe(method_family = none)]
pub unsafe fn state(&self) -> SFSpeechRecognitionTaskState;
/// A Boolean value that indicates whether audio input has stopped.
///
/// By default, the value of this property is `false`.
#[unsafe(method(isFinishing))]
#[unsafe(method_family = none)]
pub unsafe fn isFinishing(&self) -> bool;
/// Stops accepting new audio and finishes processing on the audio input that has already been accepted.
///
/// 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.
#[unsafe(method(finish))]
#[unsafe(method_family = none)]
pub unsafe fn finish(&self);
/// A Boolean value that indicates whether the speech recognition task was canceled.
///
/// By default, the value of this property is `false`.
#[unsafe(method(isCancelled))]
#[unsafe(method_family = none)]
pub unsafe fn isCancelled(&self) -> bool;
/// Cancels the current speech recognition task.
///
/// 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.
///
/// 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.
#[unsafe(method(cancel))]
#[unsafe(method_family = none)]
pub unsafe fn cancel(&self);
/// An error object that specifies the error that occurred during a speech recognition task.
///
/// The system may return one of the errors listed in the table below.
///
/// | Error Code | Error Domain | Description |
/// |---|---|---|
/// | `102` | `kLSRErrorDomain` | Assets are not installed. |
/// | `201` | `kLSRErrorDomain` | Siri or Dictation is disabled. |
/// | `300` | `kLSRErrorDomain` | Failed to initialize recognizer. |
/// | `301` | `kLSRErrorDomain` | Request was canceled. |
/// | `203` | `kAFAssistantErrorDomain` | Failure occurred during speech recognition. |
/// | `1100` | `kAFAssistantErrorDomain` | Trying to start recognition while an earlier instance is still active. |
/// | `1101` | `kAFAssistantErrorDomain` | Connection to speech process was invalidated. |
/// | `1107` | `kAFAssistantErrorDomain` | Connection to speech process was interrupted. |
/// | `1110` | `kAFAssistantErrorDomain` | Failed to recognize any speech. |
/// | `1700` | `kAFAssistantErrorDomain` | Request is not authorized. |
#[unsafe(method(error))]
#[unsafe(method_family = none)]
pub unsafe fn error(&self) -> Option<Retained<NSError>>;
);
}
/// Methods declared on superclass `NSObject`.
impl SFSpeechRecognitionTask {
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!(
/// A protocol with methods for managing multi-utterance speech recognition requests.
///
/// 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:
///
/// - When the first utterances of speech occur in the audio.
/// - When the speech recognizer stops accepting audio.
/// - When the speech recognition process finishes or is canceled.
/// - When the speech recognizer generates a potential transcription.
///
/// 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.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/speech/sfspeechrecognitiontaskdelegate?language=objc)
pub unsafe trait SFSpeechRecognitionTaskDelegate: NSObjectProtocol {
/// Tells the delegate when the task first detects speech in the source audio.
///
/// - Parameters:
/// - task: The speech recognition task (an ``SFSpeechRecognitionTask`` object) that represents the request.
#[optional]
#[unsafe(method(speechRecognitionDidDetectSpeech:))]
#[unsafe(method_family = none)]
unsafe fn speechRecognitionDidDetectSpeech(&self, task: &SFSpeechRecognitionTask);
#[cfg(feature = "SFTranscription")]
/// Tells the delegate that a hypothesized transcription is available.
///
/// This method is called for all recognitions, including partial recognitions.
///
/// - Parameters:
/// - task: The speech recognition task (an ``SFSpeechRecognitionTask`` object) that represents the request.
/// - transcription: The hypothesized transcription in an ``SFTranscription`` object.
#[optional]
#[unsafe(method(speechRecognitionTask:didHypothesizeTranscription:))]
#[unsafe(method_family = none)]
unsafe fn speechRecognitionTask_didHypothesizeTranscription(
&self,
task: &SFSpeechRecognitionTask,
transcription: &SFTranscription,
);
#[cfg(feature = "SFSpeechRecognitionResult")]
/// Tells the delegate when the final utterance is recognized.
///
/// When this method is called, the delegate should expect no further information about the utterance to be reported.
///
/// - Parameters:
/// - task: The speech recognition task (an ``SFSpeechRecognitionTask`` object) that represents the request.
/// - recognitionResult: A recognized utterance that contains one or more transcription hypotheses in an ``SFSpeechRecognitionResult`` object.
#[optional]
#[unsafe(method(speechRecognitionTask:didFinishRecognition:))]
#[unsafe(method_family = none)]
unsafe fn speechRecognitionTask_didFinishRecognition(
&self,
task: &SFSpeechRecognitionTask,
recognition_result: &SFSpeechRecognitionResult,
);
/// Tells the delegate when the task is no longer accepting new audio input, even if final processing is in progress.
///
/// - Parameters:
/// - task: The speech recognition task (an ``SFSpeechRecognitionTask`` object) that represents the request.
#[optional]
#[unsafe(method(speechRecognitionTaskFinishedReadingAudio:))]
#[unsafe(method_family = none)]
unsafe fn speechRecognitionTaskFinishedReadingAudio(&self, task: &SFSpeechRecognitionTask);
/// Tells the delegate that the task has been canceled.
///
/// A speech recognition task can be canceled by the user, by your app, or by the system.
///
/// - Parameters:
/// - task: The speech recognition task (an ``SFSpeechRecognitionTask`` object) that represents the request.
#[optional]
#[unsafe(method(speechRecognitionTaskWasCancelled:))]
#[unsafe(method_family = none)]
unsafe fn speechRecognitionTaskWasCancelled(&self, task: &SFSpeechRecognitionTask);
/// Tells the delegate when the recognition of all requested utterances is finished.
///
/// - Parameters:
/// - task: The speech recognition task (an ``SFSpeechRecognitionTask`` object) that represents the request.
/// - 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.
#[optional]
#[unsafe(method(speechRecognitionTask:didFinishSuccessfully:))]
#[unsafe(method_family = none)]
unsafe fn speechRecognitionTask_didFinishSuccessfully(
&self,
task: &SFSpeechRecognitionTask,
successfully: bool,
);
/// Tells the delegate how much audio has been processed by the task.
///
/// - Parameters:
/// - task: The speech recognition task (an ``SFSpeechRecognitionTask`` object) that represents the request.
/// - duration: The seconds of audio input that the recognizer has processed.
#[optional]
#[unsafe(method(speechRecognitionTask:didProcessAudioDuration:))]
#[unsafe(method_family = none)]
unsafe fn speechRecognitionTask_didProcessAudioDuration(
&self,
task: &SFSpeechRecognitionTask,
duration: NSTimeInterval,
);
}
);