[Tizen.Applications.RPCPort] Add RPCPort ParcelHeader internal APIs (#3612)
[platform/core/csapi/tizenfx.git] / src / Tizen.Uix.Stt / Tizen.Uix.Stt / SttClient.cs
1 /*
2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17
18 using System;
19 using System.Collections.Generic;
20 using System.Runtime.InteropServices;
21 using static Interop.Stt;
22
23 namespace Tizen.Uix.Stt
24 {
25     /// <summary>
26     /// The token event.
27     /// </summary>
28     /// <since_tizen> 3 </since_tizen>
29     public enum ResultEvent
30     {
31         /// <summary>
32         /// Event when the recognition for full or last result is ready.
33         /// </summary>
34         /// <since_tizen> 3 </since_tizen>
35         FinalResult = 0,
36         /// <summary>
37         /// Event when the recognition for partial result is ready.
38         /// </summary>
39         /// <since_tizen> 3 </since_tizen>
40         PartialResult,
41         /// <summary>
42         /// Event when the recognition has failed.
43         /// </summary>
44         /// <since_tizen> 3 </since_tizen>
45         Error
46     };
47
48     /// <summary>
49     /// Enumeration for representing the result message.
50     /// </summary>
51     /// <since_tizen> 3 </since_tizen>
52     public enum ResultMessage
53     {
54         /// <summary>
55         /// No Error.
56         /// </summary>
57         /// <since_tizen> 3 </since_tizen>
58         None,
59         /// <summary>
60         /// Recognition failed  because the speech started too soon.
61         /// </summary>
62         /// <since_tizen> 3 </since_tizen>
63         TooSoon,
64         /// <summary>
65         /// Recognition failed  because the speech is too short.
66         /// </summary>
67         /// <since_tizen> 3 </since_tizen>
68         TooShort,
69         /// <summary>
70         /// Recognition failed  because the speech is too long.
71         /// </summary>
72         /// <since_tizen> 3 </since_tizen>
73         TooLong,
74         /// <summary>
75         /// Recognition failed  because the speech is too quiet to listen.
76         /// </summary>
77         /// <since_tizen> 3 </since_tizen>
78         TooQuiet,
79         /// <summary>
80         /// Recognition failed  because the speech is too loud to listen.
81         /// </summary>
82         /// <since_tizen> 3 </since_tizen>
83         TooLoud,
84         /// <summary>
85         /// Recognition failed  because the speech is too fast to listen.
86         /// </summary>
87         /// <since_tizen> 3 </since_tizen>
88         TooFast
89     };
90
91     /// <summary>
92     /// Enumeration for the token types.
93     /// </summary>
94     /// <since_tizen> 3 </since_tizen>
95     public enum TimeEvent
96     {
97         /// <summary>
98         /// Event when the token is beginning type.
99         /// </summary>
100         /// <since_tizen> 3 </since_tizen>
101         Beginning = 0,
102         /// <summary>
103         /// Event when the token is middle type.
104         /// </summary>
105         /// <since_tizen> 3 </since_tizen>
106         Middle = 1,
107         /// <summary>
108         /// Event when the token is end type.
109         /// </summary>
110         /// <since_tizen> 3 </since_tizen>
111         End = 2
112     };
113
114     /// <summary>
115     /// Enumeration for the error values that can occur.
116     /// </summary>
117     /// <since_tizen> 3 </since_tizen>
118     public enum Error
119     {
120         /// <summary>
121         /// Successful, No error.
122         /// </summary>
123         /// <since_tizen> 3 </since_tizen>
124         None,
125         /// <summary>
126         /// Out of Memory.
127         /// </summary>
128         /// <since_tizen> 3 </since_tizen>.
129         OutOfMemory,
130         /// <summary>
131         /// I/O error.
132         /// </summary>
133         /// <since_tizen> 3 </since_tizen>.
134         IoError,
135         /// <summary>
136         /// Invalid parameter.
137         /// </summary>
138         /// <since_tizen> 3 </since_tizen>
139         InvalidParameter,
140         /// <summary>
141         /// No answer from the STT service.
142         /// </summary>
143         /// <since_tizen> 3 </since_tizen>
144         TimedOut,
145         /// <summary>
146         /// Device or resource busy.
147         /// </summary>
148         /// <since_tizen> 3 </since_tizen>
149         RecorderBusy,
150         /// <summary>
151         /// Network is down.
152         /// </summary>
153         /// <since_tizen> 3 </since_tizen>
154         OutOfNetwork,
155         /// <summary>
156         /// Permission denied.
157         /// </summary>
158         /// <since_tizen> 3 </since_tizen>
159         PermissionDenied,
160         /// <summary>
161         /// STT NOT supported.
162         /// </summary>
163         /// <since_tizen> 3 </since_tizen>
164         NotSupported,
165         /// <summary>
166         /// Invalid state.
167         /// </summary>
168         /// <since_tizen> 3 </since_tizen>
169         InvalidState,
170         /// <summary>
171         /// Invalid language.
172         /// </summary>
173         /// <since_tizen> 3 </since_tizen>
174         InvalidLanguage,
175         /// <summary>
176         /// No available engine.
177         /// </summary>
178         /// <since_tizen> 3 </since_tizen>
179         EngineNotFound,
180         /// <summary>
181         /// Operation failed.
182         /// </summary>
183         /// <since_tizen> 3 </since_tizen>
184         OperationFailed,
185         /// <summary>
186         /// Not supported feature of current engine.
187         /// </summary>
188         /// <since_tizen> 3 </since_tizen>
189         NotSupportedFeature,
190         /// <summary>
191         /// Recording timed out.
192         /// </summary>
193         /// <since_tizen> 3 </since_tizen>
194         RecordingTimedOut,
195         /// <summary>
196         /// No speech while recording.
197         /// </summary>
198         /// <since_tizen> 3 </since_tizen>
199         NoSpeech,
200         /// <summary>
201         /// Progress to ready is not finished.
202         /// </summary>
203         /// <since_tizen> 3 </since_tizen>
204         InProgressToReady,
205         /// <summary>
206         /// Progress to recording is not finished.
207         /// </summary>
208         /// <since_tizen> 3 </since_tizen>
209         InProgressToRecording,
210         /// <summary>
211         /// Progress to processing is not finished.
212         /// </summary>
213         /// <since_tizen> 3 </since_tizen>
214         InProgressToProcessing,
215         /// <summary>
216         /// Service reset.
217         /// </summary>
218         /// <since_tizen> 3 </since_tizen>
219         ServiceReset
220     };
221
222     /// <summary>
223     /// Enumeration for the recognition types.
224     /// </summary>
225     /// <since_tizen> 3 </since_tizen>
226     public enum RecognitionType
227     {
228         /// <summary>
229         /// Free form dictation.
230         /// </summary>
231         /// <since_tizen> 3 </since_tizen>
232         Free,
233         /// <summary>
234         /// Continuous free dictation.
235         /// </summary>
236         /// <since_tizen> 3 </since_tizen>
237         Partial,
238         /// <summary>
239         /// Search.
240         /// </summary>
241         /// <since_tizen> 3 </since_tizen>
242         Search,
243         /// <summary>
244         /// Web search.
245         /// </summary>
246         /// <since_tizen> 3 </since_tizen>
247         WebSearch,
248         /// <summary>
249         /// Map.
250         /// </summary>
251         /// <since_tizen> 3 </since_tizen>
252         Map
253     };
254
255     /// <summary>
256     /// Enumeration for the state types.
257     /// </summary>
258     /// <since_tizen> 3 </since_tizen>
259     public enum State
260     {
261         /// <summary>
262         /// Created state.
263         /// </summary>
264         /// <since_tizen> 3 </since_tizen>
265         Created = 0,
266         /// <summary>
267         /// Ready state.
268         /// </summary>
269         /// <since_tizen> 3 </since_tizen>
270         Ready = 1,
271         /// <summary>
272         /// Recording state.
273         /// </summary>
274         /// <since_tizen> 3 </since_tizen>
275         Recording = 2,
276         /// <summary>
277         /// Processing state.
278         /// </summary>
279         /// <since_tizen> 3 </since_tizen>
280         Processing = 3,
281         /// <summary>
282         /// Unavailable.
283         /// </summary>
284         /// <since_tizen> 3 </since_tizen>
285         Unavailable
286     };
287
288     /// <summary>
289     /// Enumeration for the silence detection types.
290     /// </summary>
291     /// <since_tizen> 3 </since_tizen>
292     public enum SilenceDetection
293     {
294         /// <summary>
295         /// Silence detection type - False.
296         /// </summary>
297         /// <since_tizen> 3 </since_tizen>
298         False = 0,
299         /// <summary>
300         /// Silence detection type - True.
301         /// </summary>
302         /// <since_tizen> 3 </since_tizen>
303         True = 1,
304         /// <summary>
305         /// Silence detection type - Auto.
306         /// </summary>
307         /// <since_tizen> 3 </since_tizen>
308         Auto = 2
309     };
310
311     /// <summary>
312     /// A main function of Speech-To-Text (below STT) API recognizes sound data recorded by users.
313     /// After choosing a language, the applications will start recording and recognizing.
314     /// After recording, the applications will receive the recognized result.
315     /// The STT has a client-server for the service of multi-applications.
316     /// The STT service always works in the background as a server. If the service is not working, client library will invoke it and the client will communicate with it.
317     /// The service has engines and a recorder, so that the client does not have the recorder itself. Only the client request commands to the STT service for using STT.
318     /// </summary>
319     /// <since_tizen> 3 </since_tizen>
320     public class SttClient : IDisposable
321     {
322         private IntPtr _handle;
323         private Object thisLock = new Object();
324         private event EventHandler<RecognitionResultEventArgs> _recognitionResult;
325         private event EventHandler<StateChangedEventArgs> _stateChanged;
326         private event EventHandler<ErrorOccurredEventArgs> _errorOccurred;
327         private event EventHandler<DefaultLanguageChangedEventArgs> _defaultLanguageChanged;
328         private event EventHandler<EngineChangedEventArgs> _engineChanged;
329         private bool disposedValue = false;
330         private Interop.Stt.RecognitionResultCallback _resultDelegate;
331         private Interop.Stt.StateChangedCallback _stateDelegate;
332         private Interop.Stt.ErrorCallback _errorDelegate;
333         private Interop.Stt.DefaultLanguageChangedCallback _languageDelegate;
334         private Interop.Stt.EngineChangedCallback _engineDelegate;
335         private ResultTime _result;
336         private ResultTimeCallback _resultTimeDelegate;
337
338         /// <summary>
339         /// Constructor to create a STT instance.
340         /// </summary>
341         /// <since_tizen> 3 </since_tizen>
342         /// <privilege>
343         /// http://tizen.org/privilege/recorder
344         /// </privilege>
345         /// <feature>
346         /// http://tizen.org/feature/speech.recognition
347         /// http://tizen.org/feature/microphone
348         /// </feature>
349         /// <exception cref="InvalidOperationException">This exception can be due to operation failed.</exception>
350         /// <exception cref="OutOfMemoryException">This exception can be due to out of memory.</exception>
351         /// <exception cref="NotSupportedException">This exception can be due to STT not supported.</exception>
352         /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception>
353         public SttClient()
354         {
355             IntPtr handle;
356             SttError error = SttCreate(out handle);
357             if (error != SttError.None)
358             {
359                 Log.Error(LogTag, "Create Failed with error " + error);
360                 throw ExceptionFactory.CreateException(error);
361             }
362
363             _handle = handle;
364         }
365
366         /// <summary>
367         /// Destructor to destroy a STT instance.
368         /// </summary>
369         ~SttClient()
370         {
371             Dispose(false);
372         }
373
374         /// <summary>
375         /// Event to be invoked when the recognition is done.
376         /// </summary>
377         /// <since_tizen> 3 </since_tizen>
378         public event EventHandler<RecognitionResultEventArgs> RecognitionResult
379         {
380             add
381             {
382                 lock (thisLock)
383                 {
384                     if (_recognitionResult == null)
385                     {
386                         _resultDelegate = (IntPtr handle, ResultEvent e, IntPtr data, int dataCount, IntPtr msg, IntPtr userData) =>
387                         {
388                             Log.Info(LogTag, "Recognition Result Event Triggered");
389                             if (data != null && msg != null)
390                             {
391                                 RecognitionResultEventArgs args = new RecognitionResultEventArgs(e, data, dataCount, Marshal.PtrToStringAnsi(msg));
392                                 _recognitionResult?.Invoke(this, args);
393                             }
394                             else
395                             {
396                                 Log.Info(LogTag, "Recognition Result Event null received");
397                             }
398                         };
399
400                         SttError error = SttSetRecognitionResultCB(_handle, _resultDelegate, IntPtr.Zero);
401                         if (error != SttError.None)
402                         {
403                             Log.Error(LogTag, "Add RecognitionResult Failed with error " + error);
404                         }
405                     }
406                     _recognitionResult += value;
407                 }
408             }
409
410             remove
411             {
412                 lock (thisLock)
413                 {
414                     _recognitionResult -= value;
415                     if (_recognitionResult == null)
416                     {
417                         SttError error = SttUnsetRecognitionResultCB(_handle);
418                         if (error != SttError.None)
419                         {
420                             Log.Error(LogTag, "Remove RecognitionResult Failed with error " + error);
421                         }
422                     }
423                 }
424             }
425         }
426
427         /// <summary>
428         /// Event to be invoked when the STT state changes.
429         /// </summary>
430         /// <since_tizen> 3 </since_tizen>
431         public event EventHandler<StateChangedEventArgs> StateChanged
432         {
433             add
434             {
435                 lock (thisLock)
436                 {
437                     if (_stateChanged == null)
438                     {
439                         SttClient obj = this;
440                         _stateDelegate = (IntPtr handle, State previous, State current, IntPtr userData) =>
441                         {
442                             StateChangedEventArgs args = new StateChangedEventArgs(previous, current);
443                             _stateChanged?.Invoke(obj, args);
444                         };
445
446                         SttError error = SttSetStateChangedCB(_handle, _stateDelegate, IntPtr.Zero);
447                         if (error != SttError.None)
448                         {
449                             Log.Error(LogTag, "Add StateChanged Failed with error " + error);
450                         }
451                     }
452                     _stateChanged += value;
453                 }
454             }
455
456             remove
457             {
458                 lock (thisLock)
459                 {
460                     _stateChanged -= value;
461                     if (_stateChanged == null)
462                     {
463                         SttError error = SttUnsetStateChangedCB(_handle);
464                         if (error != SttError.None)
465                         {
466                             Log.Error(LogTag, "Remove StateChanged Failed with error " + error);
467                         }
468                     }
469                 }
470             }
471
472         }
473
474         /// <summary>
475         /// Event to be invoked when an error occurs.
476         /// </summary>
477         /// <since_tizen> 4 </since_tizen>
478         public event EventHandler<ErrorOccurredEventArgs> ErrorOccurred
479         {
480             add
481             {
482                 lock (thisLock)
483                 {
484                     if (_errorOccurred == null)
485                     {
486                         _errorDelegate = (IntPtr handle, SttError reason, IntPtr userData) =>
487                         {
488                             ErrorOccurredEventArgs args = new ErrorOccurredEventArgs(handle, reason);
489                             _errorOccurred?.Invoke(this, args);
490                         };
491
492                         SttError error = SttSetErrorCB(_handle, _errorDelegate, IntPtr.Zero);
493                         if (error != SttError.None)
494                         {
495                             Log.Error(LogTag, "Add ErrorOccurred Failed with error " + error);
496                         }
497                     }
498                     _errorOccurred += value;
499                 }
500             }
501
502             remove
503             {
504                 lock (thisLock)
505                 {
506                     _errorOccurred -= value;
507                     if (_errorOccurred == null)
508                     {
509                         SttError error = SttUnsetErrorCB(_handle);
510                         if (error != SttError.None)
511                         {
512                             Log.Error(LogTag, "Remove ErrorOccurred Failed with error " + error);
513                         }
514                     }
515                 }
516             }
517         }
518
519         /// <summary>
520         /// Event to be invoked when the default language changes.
521         /// </summary>
522         /// <since_tizen> 3 </since_tizen>
523         public event EventHandler<DefaultLanguageChangedEventArgs> DefaultLanguageChanged
524         {
525             add
526             {
527                 lock (thisLock)
528                 {
529                     if (_defaultLanguageChanged == null)
530                     {
531                         _languageDelegate = (IntPtr handle, IntPtr previousLanguage, IntPtr currentLanguage, IntPtr userData) =>
532                         {
533                             string previousLanguageString = Marshal.PtrToStringAnsi(previousLanguage);
534                             string currentLanguageString = Marshal.PtrToStringAnsi(currentLanguage);
535                             DefaultLanguageChangedEventArgs args = new DefaultLanguageChangedEventArgs(previousLanguageString, currentLanguageString);
536                             _defaultLanguageChanged?.Invoke(this, args);
537                         };
538
539                         SttError error = SttSetDefaultLanguageChangedCB(_handle, _languageDelegate, IntPtr.Zero);
540                         if (error != SttError.None)
541                         {
542                             Log.Error(LogTag, "Add DefaultLanguageChanged Failed with error " + error);
543                         }
544                     }
545                     _defaultLanguageChanged += value;
546                 }
547             }
548
549             remove
550             {
551                 lock (thisLock)
552                 {
553                     _defaultLanguageChanged -= value;
554                     if (_defaultLanguageChanged == null)
555                     {
556                         SttError error = SttUnsetDefaultLanguageChangedCB(_handle);
557                         if (error != SttError.None)
558                         {
559                             Log.Error(LogTag, "Remove DefaultLanguageChanged Failed with error " + error);
560                         }
561                     }
562                 }
563             }
564
565         }
566
567         /// <summary>
568         /// Event to be invoked to detect the engine change.
569         /// </summary>
570         /// <since_tizen> 3 </since_tizen>
571         public event EventHandler<EngineChangedEventArgs> EngineChanged
572         {
573             add
574             {
575                 lock (thisLock)
576                 {
577                     if (_engineChanged == null)
578                     {
579                         _engineDelegate = (IntPtr handle, IntPtr engineId, IntPtr language, bool supportSilence, bool needCredential, IntPtr userData) =>
580                         {
581                             string engineIdString = Marshal.PtrToStringAnsi(engineId);
582                             string languageString = Marshal.PtrToStringAnsi(language);
583                             EngineChangedEventArgs args = new EngineChangedEventArgs(engineIdString, languageString, supportSilence, needCredential);
584                             _engineChanged?.Invoke(this, args);
585                         };
586
587                         SttError error = SttSetEngineChangedCB(_handle, _engineDelegate, IntPtr.Zero);
588                         if (error != SttError.None)
589                         {
590                             Log.Error(LogTag, "Add EngineChanged Failed with error " + error);
591                         }
592                     }
593                     _engineChanged += value;
594                 }
595             }
596
597             remove
598             {
599                 lock (thisLock)
600                 {
601                     _engineChanged -= value;
602                     if (_engineChanged == null)
603                     {
604                         SttError error = SttUnsetEngineChangedCB(_handle);
605                         if (error != SttError.None)
606                         {
607                             Log.Error(LogTag, "Remove EngineChanged Failed with error " + error);
608                         }
609                     }
610                 }
611             }
612         }
613
614         /// <summary>
615         /// Gets the default language set by the user.
616         /// The language is specified as an ISO 3166 alpha-2 two letter country-code followed by ISO 639-1 for the two-letter language code.
617         /// For example, "ko_KR" for Korean, "en_US" for American English.
618         /// </summary>
619         /// <since_tizen> 3 </since_tizen>
620         /// <value>
621         /// Default language in STT.
622         /// </value>
623         /// <privilege>
624         /// http://tizen.org/privilege/recorder
625         /// </privilege>
626         /// <returns>
627         /// Default Language string value.
628         /// </returns>
629         public string DefaultLanguage
630         {
631             get
632             {
633                 string language;
634                 lock (thisLock)
635                 {
636                     SttError error = SttGetDefaultLanguage(_handle, out language);
637                     if (error != SttError.None)
638                     {
639                         Log.Error(LogTag, "DefaultLanguage Failed with error " + error);
640                         return "";
641                     }
642                 }
643
644                 return language;
645             }
646         }
647
648         /// <summary>
649         /// Gets the microphone volume during recording.
650         /// </summary>
651         /// <since_tizen> 3 </since_tizen>
652         /// <value>
653         /// Recording volume in STT.
654         /// </value>
655         /// <privilege>
656         /// http://tizen.org/privilege/recorder
657         /// </privilege>
658         /// <pre>
659         /// The state must be recording.
660         /// </pre>
661         public float RecordingVolume
662         {
663             get
664             {
665                 float volume;
666                 lock (thisLock)
667                 {
668                     SttError error = SttGetRecordingVolume(_handle, out volume);
669                     if (error != SttError.None)
670                     {
671                         Log.Error(LogTag, "GetRecordingVolume Failed with error " + error);
672                         return 0.0f;
673                     }
674                 }
675
676                 return volume;
677             }
678
679         }
680
681         /// <summary>
682         /// Gets the current STT state.
683         /// </summary>
684         /// <since_tizen> 3 </since_tizen>
685         /// <value>
686         /// Current state of STT.
687         /// </value>
688         /// <privilege>
689         /// http://tizen.org/privilege/recorder
690         /// </privilege>
691         /// <returns>
692         /// Current STT state value.
693         /// </returns>
694         public State CurrentState
695         {
696             get
697             {
698                 State state;
699                 lock (thisLock)
700                 {
701                     SttError error = SttGetState(_handle, out state);
702                     if (error != SttError.None)
703                     {
704                         Log.Error(LogTag, "GetState Failed with error " + error);
705                         return State.Unavailable;
706                     }
707                 }
708
709                 return state;
710             }
711
712         }
713
714         /// <summary>
715         /// This property can be used to get and set the current engine id.
716         /// </summary>
717         /// <since_tizen> 3 </since_tizen>
718         /// <value>
719         /// Current STT engine id.
720         /// </value>
721         /// <privilege>
722         /// http://tizen.org/privilege/recorder
723         /// </privilege>
724         /// <exception cref="InvalidOperationException">
725         /// This exceptioncan occur while setting due to the following reasons:
726         /// 1. Operation Failed
727         /// 2. Invalid State
728         /// </exception>
729         /// <exception cref="OutOfMemoryException">This exception can be due to out of memory.</exception>
730         /// <exception cref="NotSupportedException">This exception can be due to STT not supported.</exception>
731         /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception>
732         /// <exception cref="ArgumentException">This can happen if improper EngineId is provided while setting the value.</exception>
733         /// <pre>
734         /// The state must be created.
735         /// </pre>
736         public string Engine
737         {
738             get
739             {
740                 string engineId;
741                 lock (thisLock)
742                 {
743                     SttError error = SttGetEngine(_handle, out engineId);
744                     if (error != SttError.None)
745                     {
746                         Log.Error(LogTag, "Get EngineId Failed with error " + error);
747                         return "";
748                     }
749                 }
750
751                 return engineId;
752             }
753             set
754             {
755                 lock (thisLock)
756                 {
757                     SttError error = SttSetEngine(_handle, value);
758                     if (error != SttError.None)
759                     {
760                         Log.Error(LogTag, "Set EngineId Failed with error " + error);
761                         throw ExceptionFactory.CreateException(error);
762                     }
763                 }
764
765             }
766         }
767
768         /// <summary>
769         /// Retrieves the time stamp of the current recognition result.
770         /// </summary>
771         /// <since_tizen> 3 </since_tizen>
772         /// <returns>
773         /// List of ResultTime.
774         /// </returns>
775         /// <privilege>
776         /// http://tizen.org/privilege/recorder
777         /// </privilege>
778         /// <feature>
779         /// http://tizen.org/feature/speech.recognition
780         /// http://tizen.org/feature/microphone
781         /// </feature>
782         /// <remarks>
783         /// This function should only be called in the RecognitionResult event.
784         /// </remarks>
785         /// <exception cref="InvalidOperationException">This exception can be due to operation failed.</exception>
786         /// <exception cref="NotSupportedException">This exception can be due to STT not supported.</exception>
787         /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception>
788         public IEnumerable<ResultTime> GetDetailedResult()
789         {
790             List<ResultTime> list = new List<ResultTime>();
791             lock (thisLock)
792             {
793                 _resultTimeDelegate = (IntPtr handle, int index, TimeEvent e, IntPtr text, IntPtr startTime, IntPtr endTime, IntPtr userData) =>
794                 {
795                     _result = new ResultTime(index, e, Marshal.PtrToStringAnsi(text), (long)startTime, (long)endTime);
796                     list.Add(_result);
797                     return true;
798                 };
799                 SttError error = SttForeachDetailedResult(_handle, _resultTimeDelegate, IntPtr.Zero);
800                 if (error != SttError.None)
801                 {
802                     Log.Error(LogTag, "GetDetailedResult Failed with error " + error);
803                     throw ExceptionFactory.CreateException(error);
804                 }
805             }
806             return list;
807         }
808
809
810         /// <summary>
811         /// Gets the private data from the STT engine.
812         /// </summary>
813         /// <since_tizen> 3 </since_tizen>
814         /// <param name="key">
815         /// The key string.
816         /// </param>
817         /// <returns>
818         /// The data corresponding to the key is provided.
819         /// </returns>
820         /// <privilege>
821         /// http://tizen.org/privilege/recorder
822         /// </privilege>
823         /// <feature>
824         /// http://tizen.org/feature/speech.recognition
825         /// http://tizen.org/feature/microphone
826         /// </feature>
827         /// <exception cref="InvalidOperationException">This exception can be due to invalid state.</exception>
828         /// <exception cref="NotSupportedException">This exception can be due to STT not supported.</exception>
829         /// <exception cref="TimeoutException">This exception can be due to No Answer from STT Service.</exception>
830         /// <pre>
831         /// The state must be ready.
832         /// </pre>
833         public string GetPrivateData(string key)
834         {
835             string data;
836             lock (thisLock)
837             {
838                 SttError error = SttGetPrivateData(_handle, key, out data);
839                 if (error != SttError.None)
840                 {
841                     Log.Error(LogTag, "GetPrivateData Failed with error " + error);
842                     throw ExceptionFactory.CreateException(error);
843                 }
844             }
845
846             return data;
847         }
848
849         /// <summary>
850         /// Sets the private data to the STT engine.
851         /// </summary>
852         /// <since_tizen> 3 </since_tizen>
853         /// <param name="key">
854         /// The key string.
855         /// </param>
856         /// <param name="data">
857         /// The data string.
858         /// </param>
859         /// <privilege>
860         /// http://tizen.org/privilege/recorder
861         /// </privilege>
862         /// <feature>
863         /// http://tizen.org/feature/speech.recognition
864         /// http://tizen.org/feature/microphone
865         /// </feature>
866         /// <exception cref="InvalidOperationException">This exception can be due to invalid state.</exception>
867         /// <exception cref="NotSupportedException">This exception can be due to STT not supported.</exception>
868         /// <exception cref="TimeoutException">This exception can be due to No Answer from STT Service.</exception>
869         /// <exception cref="ArgumentException"> This can happen if Improper value is provided while setting the value. </exception>
870         /// <pre>
871         /// The state must be ready.
872         /// </pre>
873         public void SetPrivateData(string key, string data)
874         {
875             lock (thisLock)
876             {
877                 SttError error = SttSetPrivateData(_handle, key, data);
878                 if (error != SttError.None)
879                 {
880                     Log.Error(LogTag, "SetPrivateData Failed with error " + error);
881                     throw ExceptionFactory.CreateException(error);
882                 }
883             }
884         }
885
886         /// <summary>
887         /// Gets the list of supported engines.
888         /// </summary>
889         /// <since_tizen> 3 </since_tizen>
890         /// <returns>
891         /// IEnumerable&lt;SupportedEngine&gt; list of supported engines.
892         /// </returns>
893         /// <privilege>
894         /// http://tizen.org/privilege/recorder
895         /// </privilege>
896         /// <feature>
897         /// http://tizen.org/feature/speech.recognition
898         /// http://tizen.org/feature/microphone
899         /// </feature>
900         /// <exception cref="InvalidOperationException">This exception can be due to operation failed.</exception>
901         /// <exception cref="OutOfMemoryException">This exception can be due to out of memory.</exception>
902         /// <exception cref="NotSupportedException">This exception can be due to STT not supported.</exception>
903         /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception>
904         public IEnumerable<SupportedEngine> GetSupportedEngines()
905         {
906             List<SupportedEngine> engineList = new List<SupportedEngine>();
907             lock (thisLock)
908             {
909                 SupportedEngineCallback supportedEngineDelegate = (IntPtr handle, IntPtr engineId, IntPtr engineName, IntPtr userData) =>
910                 {
911                     string id = Marshal.PtrToStringAnsi(engineId);
912                     string name = Marshal.PtrToStringAnsi(engineName);
913                     SupportedEngine engine = new SupportedEngine(id, name);
914                     engineList.Add(engine);
915                     return true;
916                 };
917                 SttError error = SttForeEachSupportedEngines(_handle, supportedEngineDelegate, IntPtr.Zero);
918                 if (error != SttError.None)
919                 {
920                     Log.Error(LogTag, "Create Failed with error " + error);
921                     throw ExceptionFactory.CreateException(error);
922                 }
923             }
924
925             return engineList;
926         }
927
928         /// <summary>
929         /// Sets the application credential.
930         /// </summary>
931         /// <since_tizen> 3 </since_tizen>
932         /// <param name="credential">
933         /// The credential string.
934         /// </param>
935         /// <privilege>
936         /// http://tizen.org/privilege/recorder
937         /// </privilege>
938         /// <feature>
939         /// http://tizen.org/feature/speech.recognition
940         /// http://tizen.org/feature/microphone
941         /// </feature>
942         /// <exception cref="InvalidOperationException">
943         /// This exceptioncan be due to the following reasons:
944         /// 1. Operation Failed
945         /// 2. Invalid State
946         /// </exception>
947         /// <exception cref="OutOfMemoryException">This exception can be due to out of memory.</exception>
948         /// <exception cref="NotSupportedException">This exception can be due to STT not supported.</exception>
949         /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception>
950         /// <exception cref="ArgumentException"> This can happen if Improper value is provided while setting the value. </exception>
951         /// <pre>
952         /// The state must be created.
953         /// </pre>
954         public void SetCredential(string credential)
955         {
956             lock (thisLock)
957             {
958                 SttError error = SttSetcredential(_handle, credential);
959                 if (error != SttError.None)
960                 {
961                     Log.Error(LogTag, "SetCredential Failed with error " + error);
962                     throw ExceptionFactory.CreateException(error);
963                 }
964             }
965         }
966
967         /// <summary>
968         /// Connects to the STT service asynchronously.
969         /// </summary>
970         /// <since_tizen> 3 </since_tizen>
971         /// <privilege>
972         /// http://tizen.org/privilege/recorder
973         /// </privilege>
974         /// <feature>
975         /// http://tizen.org/feature/speech.recognition
976         /// http://tizen.org/feature/microphone
977         /// </feature>
978         /// <exception cref="InvalidOperationException">This exception can be due to invalid state.</exception>
979         /// <exception cref="NotSupportedException">This exception can be due to STT not supported.</exception>
980         /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception>
981         /// <pre>
982         /// The state must be created.
983         /// </pre>
984         /// <post>
985         /// If this function is successful, the STT state will be ready.
986         /// If this function is unsuccessful, ErrorOccurred event will be invoked.
987         /// </post>
988         public void Prepare()
989         {
990             lock (thisLock)
991             {
992                 SttError error = SttPrepare(_handle);
993                 if (error != SttError.None)
994                 {
995                     Log.Error(LogTag, "SetEngine Failed with error " + error);
996                     throw ExceptionFactory.CreateException(error);
997                 }
998             }
999         }
1000
1001         /// <summary>
1002         /// Disconnects from the STT service.
1003         /// </summary>
1004         /// <since_tizen> 3 </since_tizen>
1005         /// <privilege>
1006         /// http://tizen.org/privilege/recorder
1007         /// </privilege>
1008         /// <feature>
1009         /// http://tizen.org/feature/speech.recognition
1010         /// http://tizen.org/feature/microphone
1011         /// </feature>
1012         /// <exception cref="InvalidOperationException">This exception can be due to invalid state.</exception>
1013         /// <exception cref="NotSupportedException">This exception can be due to STT not supported.</exception>
1014         /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception>
1015         /// <pre>
1016         /// The state must be ready.
1017         /// </pre>
1018         /// <post>
1019         /// If this function is successful, the STT state will be Created.
1020         /// </post>
1021         public void Unprepare()
1022         {
1023             lock (thisLock)
1024             {
1025                 SttError error = SttUnprepare(_handle);
1026                 if (error != SttError.None)
1027                 {
1028                     Log.Error(LogTag, "Unprepare Failed with error " + error);
1029                     throw ExceptionFactory.CreateException(error);
1030                 }
1031             }
1032         }
1033
1034         /// <summary>
1035         /// Retrieves all the supported languages of the current engine.
1036         /// The language is specified as an ISO 3166 alpha-2 two letter country-code followed by ISO 639-1 for the two-letter language code.
1037         /// For example, "ko_KR" for Korean, "en_US" for American English.
1038         /// </summary>
1039         /// <since_tizen> 4 </since_tizen>
1040         /// <privilege>
1041         /// http://tizen.org/privilege/recorder
1042         /// </privilege>
1043         /// <returns>
1044         /// List of strings for supported languages.
1045         /// </returns>
1046         /// <feature>
1047         /// http://tizen.org/feature/speech.recognition
1048         /// http://tizen.org/feature/microphone
1049         /// </feature>
1050         /// <exception cref="InvalidOperationException">
1051         /// This exception can be due to the following reasons:
1052         /// 1. Engine Not Found.
1053         /// 2. Operation Failed.
1054         /// </exception>
1055         /// <exception cref="NotSupportedException">This exception can be due to STT not supported.</exception>
1056         /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception>
1057         public IEnumerable<string> GetSupportedLanguages()
1058         {
1059             List<string> languageList = new List<string>();
1060             lock (thisLock)
1061             {
1062                 SupportedLanguageCallback supportedLanguageDelegate = (IntPtr handle, IntPtr language, IntPtr userData) =>
1063                 {
1064                     string lang = Marshal.PtrToStringAnsi(language);
1065                     languageList.Add(lang);
1066                     return true;
1067                 };
1068
1069                 SttError error = SttForeachSupportedLanguages(_handle, supportedLanguageDelegate, IntPtr.Zero);
1070                 if (error != SttError.None)
1071                 {
1072                     Log.Error(LogTag, "GetSupportedLanguages Failed with error " + error);
1073                     throw ExceptionFactory.CreateException(error);
1074                 }
1075             }
1076
1077             return languageList;
1078         }
1079
1080         /// <summary>
1081         /// Checks whether the recognition type is supported.
1082         /// </summary>
1083         /// <since_tizen> 3 </since_tizen>
1084         /// <privilege>
1085         /// http://tizen.org/privilege/recorder
1086         /// </privilege>
1087         /// <param name="type">
1088         /// RecognitionType value.
1089         /// </param>
1090         /// <returns>
1091         /// Bool value indicating whether the recognition type is supported.
1092         /// </returns>
1093         /// <feature>
1094         /// http://tizen.org/feature/speech.recognition
1095         /// http://tizen.org/feature/microphone
1096         /// </feature>
1097         /// <exception cref="InvalidOperationException">
1098         /// This exception can be due to the following reasons:
1099         /// 1. Invalid State
1100         /// 2. Engine Not Found
1101         /// 3. Operation Failed
1102         /// </exception>
1103         /// <exception cref="NotSupportedException">This exception can be due to STT not supported.</exception>
1104         /// <pre>
1105         /// The state should be ready.
1106         /// </pre>
1107         public bool IsRecognitionTypeSupported(RecognitionType type)
1108         {
1109             bool supported;
1110             lock (thisLock)
1111             {
1112                 string recType = "stt.recognition.type.FREE";
1113                 switch (type)
1114                 {
1115                     case RecognitionType.Free:
1116                         {
1117                             recType = "stt.recognition.type.FREE";
1118                             break;
1119                         }
1120
1121                     case RecognitionType.Partial:
1122                         {
1123                             recType = "stt.recognition.type.FREE.PARTIAL";
1124                             break;
1125                         }
1126
1127                     case RecognitionType.Search:
1128                         {
1129                             recType = "stt.recognition.type.SEARCH";
1130                             break;
1131                         }
1132
1133                     case RecognitionType.WebSearch:
1134                         {
1135                             recType = "stt.recognition.type.WEB_SEARCH";
1136                             break;
1137                         }
1138
1139                     case RecognitionType.Map:
1140                         {
1141                             recType = "stt.recognition.type.MAP";
1142                             break;
1143                         }
1144                 }
1145
1146                 SttError error = SttIsRecognitionTypeSupported(_handle, recType, out supported);
1147                 if (error != SttError.None)
1148                 {
1149                     Log.Error(LogTag, "IsRecognitionTypeSupported Failed with error " + error);
1150                     throw ExceptionFactory.CreateException(error);
1151                 }
1152             }
1153
1154             return supported;
1155         }
1156
1157         /// <summary>
1158         /// Sets the silence detection.
1159         /// </summary>
1160         /// <since_tizen> 3 </since_tizen>
1161         /// <privilege>
1162         /// http://tizen.org/privilege/recorder
1163         /// </privilege>
1164         /// <param name="type">
1165         /// SilenceDetection value.
1166         /// </param>
1167         /// <feature>
1168         /// http://tizen.org/feature/speech.recognition
1169         /// http://tizen.org/feature/microphone
1170         /// </feature>
1171         /// <exception cref="InvalidOperationException">
1172         /// This exception can be due to the following reasons:
1173         /// 1. Invalid State
1174         /// 2. Not supported feature of current engine
1175         /// 3. Operation Failed
1176         /// </exception>
1177         /// <exception cref="NotSupportedException">This exception can be due to STT not supported.</exception>
1178         /// <pre>
1179         /// The state should be ready.
1180         /// </pre>
1181         public void SetSilenceDetection(SilenceDetection type)
1182         {
1183             lock (thisLock)
1184             {
1185                 SttError error = SttSetSilenceDetection(_handle, type);
1186                 if (error != SttError.None)
1187                 {
1188                     Log.Error(LogTag, "SetSilenceDetection Failed with error " + error);
1189                     throw ExceptionFactory.CreateException(error);
1190                 }
1191             }
1192         }
1193
1194         /// <summary>
1195         /// Sets the sound to start recording.
1196         /// Sound file type should be .wav type.
1197         /// </summary>
1198         /// <since_tizen> 3 </since_tizen>
1199         /// <privilege>
1200         /// http://tizen.org/privilege/recorder
1201         /// </privilege>
1202         /// <param name="filePath">
1203         /// File path for the sound.
1204         /// </param>
1205         /// <feature>
1206         /// http://tizen.org/feature/speech.recognition
1207         /// http://tizen.org/feature/microphone
1208         /// </feature>
1209         /// <exception cref="InvalidOperationException">
1210         /// This exception can be due to the following reasons:
1211         /// 1. Invalid State
1212         /// 2. Operation Failed
1213         /// </exception>
1214         /// <exception cref="NotSupportedException">This exception can be due to STT not supported.</exception>
1215         /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception>
1216         /// <exception cref="ArgumentException"> If an Invalid Parameter is provided. </exception>
1217         /// <pre>
1218         /// The state should be ready.
1219         /// </pre>
1220         public void SetStartSound(string filePath)
1221         {
1222             lock (thisLock)
1223             {
1224                 SttError error = SttSetStartSound(_handle, filePath);
1225                 if (error != SttError.None)
1226                 {
1227                     Log.Error(LogTag, "SetStartSound Failed with error " + error);
1228                     throw ExceptionFactory.CreateException(error);
1229                 }
1230             }
1231         }
1232
1233         /// <summary>
1234         /// Unsets the sound to start recording.
1235         /// </summary>
1236         /// <since_tizen> 3 </since_tizen>
1237         /// <privilege>
1238         /// http://tizen.org/privilege/recorder
1239         /// </privilege>
1240         /// <feature>
1241         /// http://tizen.org/feature/speech.recognition
1242         /// http://tizen.org/feature/microphone
1243         /// </feature>
1244         /// <exception cref="InvalidOperationException">
1245         /// This exception can be due to the following reasons:
1246         /// 1. Invalid State
1247         /// 2. Operation Failed
1248         /// </exception>
1249         /// <exception cref="NotSupportedException">This exception can be due to STT not supported.</exception>
1250         /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception>
1251         /// <pre>
1252         /// The state should be ready.
1253         /// </pre>
1254         public void UnsetStartSound()
1255         {
1256             lock (thisLock)
1257             {
1258                 SttError error = SttUnsetStartSound(_handle);
1259                 if (error != SttError.None)
1260                 {
1261                     Log.Error(LogTag, "UnsetStartSound Failed with error " + error);
1262                     throw ExceptionFactory.CreateException(error);
1263                 }
1264             }
1265         }
1266
1267         /// <summary>
1268         /// Sets the sound to stop recording.
1269         /// Sound file type should be .wav type.
1270         /// </summary>
1271         /// <since_tizen> 3 </since_tizen>
1272         /// <privilege>
1273         /// http://tizen.org/privilege/recorder
1274         /// </privilege>
1275         /// <param name="filePath">
1276         /// File Path for the sound.
1277         /// </param>
1278         /// <feature>
1279         /// http://tizen.org/feature/speech.recognition
1280         /// http://tizen.org/feature/microphone
1281         /// </feature>
1282         /// <exception cref="InvalidOperationException">
1283         /// This exception can be due to the following reasons:
1284         /// 1. Invalid State
1285         /// 2. Operation Failed
1286         /// </exception>
1287         /// <exception cref="NotSupportedException">This exception can be due to STT not supported.</exception>
1288         /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception>
1289         /// <exception cref="ArgumentException">This exception can be due to Invalid Parameter.</exception>
1290         /// <pre>
1291         /// The state should be ready.
1292         /// </pre>
1293         public void SetStopSound(string filePath)
1294         {
1295             lock (thisLock)
1296             {
1297                 SttError error = SttSetStopSound(_handle, filePath);
1298                 if (error != SttError.None)
1299                 {
1300                     Log.Error(LogTag, "SetStopSound Failed with error " + error);
1301                     throw ExceptionFactory.CreateException(error);
1302                 }
1303             }
1304         }
1305
1306         /// <summary>
1307         /// Unsets the sound to stop recording.
1308         /// </summary>
1309         /// <since_tizen> 3 </since_tizen>
1310         /// <privilege>
1311         /// http://tizen.org/privilege/recorder
1312         /// </privilege>
1313         /// <feature>
1314         /// http://tizen.org/feature/speech.recognition
1315         /// http://tizen.org/feature/microphone
1316         /// </feature>
1317         /// <exception cref="InvalidOperationException">
1318         /// This exception can be due to the following reasons:
1319         /// 1. Invalid State
1320         /// 2. Operation Failed
1321         /// </exception>
1322         /// <exception cref="NotSupportedException">This exception can be due to STT not supported.</exception>
1323         /// <exception cref="UnauthorizedAccessException"> his exception can be due to permission denied.</exception>
1324         /// <pre>
1325         /// The state should be ready.
1326         /// </pre>
1327         public void UnsetStopSound()
1328         {
1329             lock (thisLock)
1330             {
1331                 SttError error = SttUnsetStopSound(_handle);
1332                 if (error != SttError.None)
1333                 {
1334                     Log.Error(LogTag, "UnsetStopSound Failed with error " + error);
1335                     throw ExceptionFactory.CreateException(error);
1336                 }
1337             }
1338         }
1339
1340         /// <summary>
1341         /// Starts the recording and recognition asynchronously.
1342         /// This function starts recording in the STT service and sends the recording data to the engine.
1343         /// This work continues until stop, cancel, or silence is detected by engine.
1344         /// </summary>
1345         /// <since_tizen> 3 </since_tizen>
1346         /// <privilege>
1347         /// http://tizen.org/privilege/recorder
1348         /// </privilege>
1349         /// <param name="language">
1350         /// The language selected.
1351         /// </param>
1352         /// <param name="type">
1353         /// The type for recognition.
1354         /// </param>
1355         /// <feature>
1356         /// http://tizen.org/feature/speech.recognition
1357         /// http://tizen.org/feature/microphone
1358         /// </feature>
1359         /// <exception cref="InvalidOperationException">
1360         /// This exception can be due to the following reasons:
1361         /// 1. Invalid State
1362         /// 2. Operation Failed
1363         /// 3. Recorder Busy
1364         /// 4. Progress to recording is not finished
1365         /// </exception>
1366         /// <exception cref="NotSupportedException">This exception can be due to STT not supported.</exception>
1367         /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception>
1368         /// <exception cref="ArgumentException">This exception can be due to an invalid language.</exception>
1369         /// <pre>
1370         /// The state should be ready.
1371         /// </pre>
1372         /// <post>
1373         /// It will invoke the StateChanged event, if registered.
1374         /// If this function succeeds, the STT state will be recording.
1375         /// If you call this function again before the state changes, you will receive ErrorINProgressToRecording.
1376         /// </post>
1377         public void Start(string language, RecognitionType type)
1378         {
1379             lock (thisLock)
1380             {
1381                 string recType = "stt.recognition.type.FREE";
1382                 switch (type)
1383                 {
1384                     case RecognitionType.Free:
1385                         {
1386                             recType = "stt.recognition.type.FREE";
1387                             break;
1388                         }
1389
1390                     case RecognitionType.Partial:
1391                         {
1392                             recType = "stt.recognition.type.FREE.PARTIAL";
1393                             break;
1394                         }
1395
1396                     case RecognitionType.Search:
1397                         {
1398                             recType = "stt.recognition.type.SEARCH";
1399                             break;
1400                         }
1401
1402                     case RecognitionType.WebSearch:
1403                         {
1404                             recType = "stt.recognition.type.WEB_SEARCH";
1405                             break;
1406                         }
1407
1408                     case RecognitionType.Map:
1409                         {
1410                             recType = "stt.recognition.type.MAP";
1411                             break;
1412                         }
1413                 }
1414
1415                 SttError error = SttStart(_handle, language, recType);
1416                 if (error != SttError.None)
1417                 {
1418                     Log.Error(LogTag, "Start Failed with error " + error);
1419                     throw ExceptionFactory.CreateException(error);
1420                 }
1421             }
1422         }
1423
1424         /// <summary>
1425         /// Finishes the recording and starts recognition processing in the engine asynchronously.
1426         /// </summary>
1427         /// <since_tizen> 3 </since_tizen>
1428         /// <privilege>
1429         /// http://tizen.org/privilege/recorder
1430         /// </privilege>
1431         /// <feature>
1432         /// http://tizen.org/feature/speech.recognition
1433         /// http://tizen.org/feature/microphone
1434         /// </feature>
1435         /// <exception cref="InvalidOperationException">
1436         /// This exception can be due to the following reasons:
1437         /// 1. Invalid State
1438         /// 2. Operation Failed
1439         /// 3. Progress to ready is not finished
1440         /// 4. Progress to recording is not finished
1441         /// 5. Progress to processing is not finished
1442         /// </exception>
1443         /// <exception cref="NotSupportedException">This exception can be due to STT not supported.</exception>
1444         /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception>
1445         /// <pre>
1446         /// The state should be Recording.
1447         /// </pre>
1448         /// <post>
1449         /// It will invoke the StateChanged Event, if registered.
1450         /// If this function succeeds, the STT state will be processing.
1451         /// If you call this function again before the state changes, you will receive ErrorINProgressToProcessing.
1452         /// After processing of engine, the RecognitionResult event is invoked.
1453         /// </post>
1454         public void Stop()
1455         {
1456             lock (thisLock)
1457             {
1458                 SttError error = SttStop(_handle);
1459                 if (error != SttError.None)
1460                 {
1461                     Log.Error(LogTag, "Stop Failed with error " + error);
1462                     throw ExceptionFactory.CreateException(error);
1463                 }
1464             }
1465         }
1466
1467         /// <summary>
1468         /// Cancels processing the recognition and recording asynchronously.
1469         /// This function cancels recording and the engine cancels recognition processing.
1470         /// After successful cancellation, the StateChanged event is invoked, otherwise if an error is occurs, the ErrorOccurred event is invoked.
1471         /// </summary>
1472         /// <since_tizen> 3 </since_tizen>
1473         /// <privilege>
1474         /// http://tizen.org/privilege/recorder
1475         /// </privilege>
1476         /// <feature>
1477         /// http://tizen.org/feature/speech.recognition
1478         /// http://tizen.org/feature/microphone
1479         /// </feature>
1480         /// <exception cref="InvalidOperationException">
1481         /// This exception can be due to the following reasons:
1482         /// 1. Invalid State
1483         /// 2. Operation Failed
1484         /// 3. Progress to ready is not finished
1485         /// 4. Progress to recording is not finished
1486         /// 5. Progress to processing is not finished
1487         /// </exception>
1488         /// <exception cref="NotSupportedException">This exception can be due to STT not supported.</exception>
1489         /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception>
1490         /// <pre>
1491         /// The state should be Recording or Processing.
1492         /// </pre>
1493         /// <post>
1494         /// It will invoke the StateChanged event, if registered.
1495         /// If this function succeeds, the STT state will be ready.
1496         /// If you call this function again before the state changes, you will receive ErrorINProgressToReady.
1497         /// </post>
1498         public void Cancel()
1499         {
1500             lock (thisLock)
1501             {
1502                 SttError error = SttCancel(_handle);
1503                 if (error != SttError.None)
1504                 {
1505                     Log.Error(LogTag, "Cancel Failed with error " + error);
1506                     throw ExceptionFactory.CreateException(error);
1507                 }
1508             }
1509         }
1510
1511         /// <summary>
1512         /// Method to release resources.
1513         /// </summary>
1514         /// <since_tizen> 3 </since_tizen>
1515         public void Dispose()
1516         {
1517             Dispose(true);
1518             GC.SuppressFinalize(this);
1519         }
1520
1521         /// <summary>
1522         /// Method to release resources.
1523         /// </summary>
1524         /// <since_tizen> 3 </since_tizen>
1525         /// <param name="disposing">
1526         /// The boolean value for destoying stt handle.
1527         /// </param>
1528         protected virtual void Dispose(bool disposing)
1529         {
1530             if (!disposedValue)
1531             {
1532                                 lock (thisLock)
1533                                 {
1534                                         if (_handle != IntPtr.Zero)
1535                                         {
1536                                                 SttError error = SttDestroy(_handle);
1537                                                 if (error != SttError.None)
1538                                                 {
1539                                                         Log.Error(LogTag, "Destroy Failed with error " + error);
1540                                                 }
1541                                                 _handle = IntPtr.Zero;
1542                                         }
1543                                 }
1544
1545                                 disposedValue = true;
1546             }
1547         }
1548     }
1549 }