Fix errata
[platform/core/csapi/uix-stt.git] / 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 full or last result is ready
33         /// </summary>
34         /// <since_tizen> 3 </since_tizen>
35         FinalResult = 0,
36         /// <summary>
37         /// Event when the recognition 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 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 type
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     /// Enum for 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 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, 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 client will communicate with it.
317     /// The service has engines and the recorder so 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         /// Event to be invoked when the recognition is done.
368         /// </summary>
369         /// <since_tizen> 3 </since_tizen>
370         public event EventHandler<RecognitionResultEventArgs> RecognitionResult
371         {
372             add
373             {
374                 lock (thisLock)
375                 {
376                     _resultDelegate = (IntPtr handle, ResultEvent e, IntPtr data, int dataCount, IntPtr msg, IntPtr userData) =>
377                 {
378                     Log.Info(LogTag, "Recognition Result Event Triggered");
379                     if (data != null && msg != null)
380                     {
381                         RecognitionResultEventArgs args = new RecognitionResultEventArgs(e, data, dataCount, Marshal.PtrToStringAnsi(msg));
382                         _recognitionResult?.Invoke(this, args);
383                     }
384                     else
385                     {
386                         Log.Info(LogTag, "Recognition Result Event null received");
387                     }
388                 };
389                     SttError error = SttSetRecognitionResultCB(_handle, _resultDelegate, IntPtr.Zero);
390                     if (error != SttError.None)
391                     {
392                         Log.Error(LogTag, "Add RecognitionResult Failed with error " + error);
393                     }
394                     else
395                     {
396                         _recognitionResult += value;
397                     }
398                 }
399             }
400
401             remove
402             {
403                 lock (thisLock)
404                 {
405                     SttError error = SttUnsetRecognitionResultCB(_handle);
406                     if (error != SttError.None)
407                     {
408                         Log.Error(LogTag, "Remove RecognitionResult Failed with error " + error);
409                     }
410
411                     _recognitionResult -= value;
412                 }
413             }
414         }
415
416         /// <summary>
417         /// Event to be invoked when STT state changes.
418         /// </summary>
419         /// <since_tizen> 3 </since_tizen>
420         public event EventHandler<StateChangedEventArgs> StateChanged
421         {
422             add
423             {
424                 lock (thisLock)
425                 {
426                     SttClient obj = this;
427                     _stateDelegate = (IntPtr handle, State previous, State current, IntPtr userData) =>
428                     {
429                         StateChangedEventArgs args = new StateChangedEventArgs(previous, current);
430                         _stateChanged?.Invoke(obj, args);
431                     };
432                     SttError error = SttSetStateChangedCB(_handle, _stateDelegate, IntPtr.Zero);
433                     if (error != SttError.None)
434                     {
435                         Log.Error(LogTag, "Add StateChanged Failed with error " + error);
436                     }
437                     else
438                     {
439                         _stateChanged += value;
440                     }
441
442                 }
443             }
444
445             remove
446             {
447                 lock (thisLock)
448                 {
449                     SttError error = SttUnsetStateChangedCB(_handle);
450                     if (error != SttError.None)
451                     {
452                         Log.Error(LogTag, "Remove StateChanged Failed with error " + error);
453                     }
454
455                     _stateChanged -= value;
456                 }
457             }
458
459         }
460
461         /// <summary>
462         /// Event to be invoked when an error occurs.
463         /// </summary>
464         /// <since_tizen> 3 </since_tizen>
465         public event EventHandler<ErrorOccurredEventArgs> ErrorOccurred
466         {
467             add
468             {
469                 lock (thisLock)
470                 {
471                     _errorDelegate = (IntPtr handle, SttError reason, IntPtr userData) =>
472                 {
473                     ErrorOccurredEventArgs args = new ErrorOccurredEventArgs(handle, reason);
474                     _errorOccurred?.Invoke(this, args);
475                 };
476                     SttError error = SttSetErrorCB(_handle, _errorDelegate, IntPtr.Zero);
477                     if (error != SttError.None)
478                     {
479                         Log.Error(LogTag, "Add ErrorOccurred Failed with error " + error);
480                     }
481
482                     else
483                     {
484                         _errorOccurred += value;
485                     }
486                 }
487
488             }
489
490             remove
491             {
492                 lock (thisLock)
493                 {
494                     SttError error = SttUnsetErrorCB(_handle);
495                     if (error != SttError.None)
496                     {
497                         Log.Error(LogTag, "Remove ErrorOccurred Failed with error " + error);
498                     }
499
500                     _errorOccurred -= value;
501                 }
502             }
503         }
504
505         /// <summary>
506         /// Event to be invoked when default language change.
507         /// </summary>
508         /// <since_tizen> 3 </since_tizen>
509         public event EventHandler<DefaultLanguageChangedEventArgs> DefaultLanguageChanged
510         {
511             add
512             {
513                 lock (thisLock)
514                 {
515                     _languageDelegate = (IntPtr handle, IntPtr previousLanguage, IntPtr currentLanguage, IntPtr userData) =>
516                 {
517                     string previousLanguageString = Marshal.PtrToStringAnsi(previousLanguage);
518                     string currentLanguageString = Marshal.PtrToStringAnsi(currentLanguage);
519                     DefaultLanguageChangedEventArgs args = new DefaultLanguageChangedEventArgs(previousLanguageString, currentLanguageString);
520                     _defaultLanguageChanged?.Invoke(this, args);
521                 };
522                     SttError error = SttSetDefaultLanguageChangedCB(_handle, _languageDelegate, IntPtr.Zero);
523                     if (error != SttError.None)
524                     {
525                         Log.Error(LogTag, "Add DefaultLanguageChanged Failed with error " + error);
526                     }
527
528                     else
529                     {
530                         _defaultLanguageChanged += value;
531                     }
532                 }
533
534             }
535
536             remove
537             {
538                 lock (thisLock)
539                 {
540                     SttError error = SttUnsetDefaultLanguageChangedCB(_handle);
541                     if (error != SttError.None)
542                     {
543                         Log.Error(LogTag, "Remove DefaultLanguageChanged Failed with error " + error);
544                     }
545
546                     _defaultLanguageChanged -= value;
547                 }
548             }
549
550         }
551
552         /// <summary>
553         /// Event to be invoked to detect engine change.
554         /// </summary>
555         /// <since_tizen> 3 </since_tizen>
556         public event EventHandler<EngineChangedEventArgs> EngineChanged
557         {
558             add
559             {
560                 lock (thisLock)
561                 {
562                     _engineDelegate = (IntPtr handle, IntPtr engineId, IntPtr language, bool supportSilence, bool needCredential, IntPtr userData) =>
563                 {
564                     string engineIdString = Marshal.PtrToStringAnsi(engineId);
565                     string languageString = Marshal.PtrToStringAnsi(language);
566                     EngineChangedEventArgs args = new EngineChangedEventArgs(engineIdString, languageString, supportSilence, needCredential);
567                     _engineChanged?.Invoke(this, args);
568                 };
569                     SttError error = SttSetEngineChangedCB(_handle, _engineDelegate, IntPtr.Zero);
570                     if (error != SttError.None)
571                     {
572                         Log.Error(LogTag, "Add EngineChanged Failed with error " + error);
573                     }
574                     else
575                     {
576                         _engineChanged += value;
577                     }
578                 }
579             }
580
581             remove
582             {
583                 lock (thisLock)
584                 {
585                     SttError error = SttUnsetEngineChangedCB(_handle);
586                     if (error != SttError.None)
587                     {
588                         Log.Error(LogTag, "Remove EngineChanged Failed with error " + error);
589                     }
590
591                     _engineChanged -= value;
592                 }
593             }
594         }
595
596         /// <summary>
597         /// Gets the default language set by the user.
598         /// 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.
599         /// For example, "ko_KR" for Korean, "en_US" for American English.
600         /// </summary>
601         /// <since_tizen> 3 </since_tizen>
602         /// <value>
603         /// Default language in STT.
604         /// </value>
605         /// <privilege>
606         /// http://tizen.org/privilege/recorder
607         /// </privilege>
608         /// <returns>
609         /// Default Language string value.
610         /// </returns>
611         public string DefaultLanguage
612         {
613             get
614             {
615                 string language;
616                 lock (thisLock)
617                 {
618                     SttError error = SttGetDefaultLanguage(_handle, out language);
619                     if (error != SttError.None)
620                     {
621                         Log.Error(LogTag, "DefaultLanguage Failed with error " + error);
622                         return "";
623                     }
624                 }
625
626                 return language;
627             }
628         }
629
630         /// <summary>
631         /// Gets the microphone volume during recording.
632         /// </summary>
633         /// <since_tizen> 3 </since_tizen>
634         /// <value>
635         /// Recording volume in STT.
636         /// </value>
637         /// <privilege>
638         /// http://tizen.org/privilege/recorder
639         /// </privilege>
640         /// <pre>
641         /// The State must be Recording.
642         /// </pre>
643         public float RecordingVolume
644         {
645             get
646             {
647                 float volume;
648                 lock (thisLock)
649                 {
650                     SttError error = SttGetRecordingVolume(_handle, out volume);
651                     if (error != SttError.None)
652                     {
653                         Log.Error(LogTag, "GetRecordingVolume Failed with error " + error);
654                         return 0.0f;
655                     }
656
657                 }
658
659                 return volume;
660             }
661
662         }
663
664         /// <summary>
665         /// Gets the current STT state.
666         /// </summary>
667         /// <since_tizen> 3 </since_tizen>
668         /// <value>
669         /// Current state of STT.
670         /// </value>
671         /// <privilege>
672         /// http://tizen.org/privilege/recorder
673         /// </privilege>
674         /// <returns>
675         /// Current STT State value.
676         /// </returns>
677         public State CurrentState
678         {
679             get
680             {
681                 State state;
682                 lock (thisLock)
683                 {
684                     SttError error = SttGetState(_handle, out state);
685                     if (error != SttError.None)
686                     {
687                         Log.Error(LogTag, "GetState Failed with error " + error);
688                         return State.Unavailable;
689                     }
690                 }
691
692                 return state;
693             }
694
695         }
696
697         /// <summary>
698         /// This property can be used to get and set the current engine id.
699         /// </summary>
700         /// <since_tizen> 3 </since_tizen>
701         /// <value>
702         /// Current STT engine id.
703         /// </value>
704         /// <privilege>
705         /// http://tizen.org/privilege/recorder
706         /// </privilege>
707         /// <exception cref="InvalidOperationException">
708         /// This Exception can occur while setting due to the following reasons
709         /// 1. Operation Failed
710         /// 2. Invalid State
711         /// </exception>
712         /// <exception cref="OutOfMemoryException"> This Exception can be due to Out of Memory. </exception>
713         /// <exception cref="NotSupportedException"> This Exception can be due to STT Not Supported. </exception>
714         /// <exception cref="UnauthorizedAccessException"> This Exception can be due to Permission Denied. </exception>
715         /// <exception cref="ArgumentException"> This can happen if Improper EngineId is provided while setting the value. </exception>
716         /// <pre>
717         /// The State must be Created.
718         /// </pre>
719         public string Engine
720         {
721             get
722             {
723                 string engineId;
724                 lock (thisLock)
725                 {
726                     SttError error = SttGetEngine(_handle, out engineId);
727                     if (error != SttError.None)
728                     {
729                         Log.Error(LogTag, "Get EngineId Failed with error " + error);
730                         return "";
731                     }
732                 }
733
734                 return engineId;
735             }
736             set
737             {
738                 lock (thisLock)
739                 {
740                     SttError error = SttSetEngine(_handle, value);
741                     if (error != SttError.None)
742                     {
743                         Log.Error(LogTag, "Set EngineId Failed with error " + error);
744                         throw ExceptionFactory.CreateException(error);
745                     }
746                 }
747
748             }
749         }
750
751         /// <summary>
752         /// Retrieves the time stamp of the current recognition result
753         /// </summary>
754         /// <since_tizen> 3 </since_tizen>
755         /// <returns>
756         /// list of ResultTime
757         /// </returns>
758         /// <privilege>
759         /// http://tizen.org/privilege/recorder
760         /// </privilege>
761         /// <feature>
762         /// http://tizen.org/feature/speech.recognition
763         /// http://tizen.org/feature/microphone
764         /// </feature>
765         /// <remarks>
766         /// This function should only be called in RecognitionResult Event
767         /// </remarks>
768         /// <exception cref="InvalidOperationException"> This Exception can be due to Operation Failed. </exception>
769         /// <exception cref="NotSupportedException"> This Exception can be due to STT Not Supported. </exception>
770         /// <exception cref="UnauthorizedAccessException"> This Exception can be due to Permission Denied. </exception>
771         public IEnumerable<ResultTime> GetDetailedResult()
772         {
773             List<ResultTime> list = new List<ResultTime>();
774             _resultTimeDelegate = (IntPtr handle, int index, TimeEvent e, IntPtr text, IntPtr startTime, IntPtr endTime, IntPtr userData) =>
775             {
776                 _result = new ResultTime(index, e, Marshal.PtrToStringAnsi(text), (long)startTime, (long)endTime);
777                 list.Add(_result);
778                 return true;
779             };
780             SttError error = SttForeachDetailedResult(_handle, _resultTimeDelegate, IntPtr.Zero);
781             if (error != SttError.None)
782             {
783                 Log.Error(LogTag, "GetDetailedResult Failed with error " + error);
784                 throw ExceptionFactory.CreateException(error);
785             }
786             return list;
787         }
788
789
790         /// <summary>
791         /// Gets the private data from stt engine.
792         /// </summary>
793         /// <since_tizen> 3 </since_tizen>
794         /// <param name="key">
795         /// The key string
796         /// </param>
797         /// <returns>
798         /// The Data Corresponding to the Key provided
799         /// </returns>
800         /// <privilege>
801         /// http://tizen.org/privilege/recorder
802         /// </privilege>
803         /// <feature>
804         /// http://tizen.org/feature/speech.recognition
805         /// http://tizen.org/feature/microphone
806         /// </feature>
807         /// <exception cref="InvalidOperationException"> This Exception can be due to Invalid State. </exception>
808         /// <exception cref="NotSupportedException"> This Exception can be due to STT Not Supported. </exception>
809         /// <exception cref="TimeoutException"> This Exception can be due to No Answer from STT Service. </exception>
810         /// <pre>
811         /// The State must be Ready.
812         /// </pre>
813         public string GetPrivateData(string key)
814         {
815             string data;
816             lock (thisLock)
817             {
818                 SttError error = SttGetPrivateData(_handle, key, out data);
819                 if (error != SttError.None)
820                 {
821                     Log.Error(LogTag, "GetPrivateData Failed with error " + error);
822                     throw ExceptionFactory.CreateException(error);
823                 }
824             }
825
826             return data;
827         }
828
829         /// <summary>
830         /// Sets the private data to stt engine.
831         /// </summary>
832         /// <since_tizen> 3 </since_tizen>
833         /// <param name="key">
834         /// The key string
835         /// </param>
836         /// <param name="data">
837         /// The data string
838         /// </param>
839         /// <privilege>
840         /// http://tizen.org/privilege/recorder
841         /// </privilege>
842         /// <feature>
843         /// http://tizen.org/feature/speech.recognition
844         /// http://tizen.org/feature/microphone
845         /// </feature>
846         /// <exception cref="InvalidOperationException"> This Exception can be due to Invalid State. </exception>
847         /// <exception cref="NotSupportedException"> This Exception can be due to STT Not Supported. </exception>
848         /// <exception cref="TimeoutException"> This Exception can be due to No Answer from STT Service. </exception>
849         /// <exception cref="ArgumentException"> This can happen if Improper value is provided while setting the value. </exception>
850         /// <pre>
851         /// The State must be Ready.
852         /// </pre>
853         public void SetPrivateData(string key, string data)
854         {
855             lock (thisLock)
856             {
857                 SttError error = SttSetPrivateData(_handle, key, data);
858                 if (error != SttError.None)
859                 {
860                     Log.Error(LogTag, "SetPrivateData Failed with error " + error);
861                     throw ExceptionFactory.CreateException(error);
862                 }
863             }
864         }
865
866         /// <summary>
867         /// Gets the list of Supported Engine
868         /// </summary>
869         /// <since_tizen> 3 </since_tizen>
870         /// <returns>
871         /// IEnumerable&lt;SupportedEngine&gt; list of supported engines
872         /// </returns>
873         /// <privilege>
874         /// http://tizen.org/privilege/recorder
875         /// </privilege>
876         /// <feature>
877         /// http://tizen.org/feature/speech.recognition
878         /// http://tizen.org/feature/microphone
879         /// </feature>
880         /// <exception cref="InvalidOperationException"> This Exception can be due to Operation Failed. </exception>
881         /// <exception cref="OutOfMemoryException"> This Exception can be due to Out of Memory. </exception>
882         /// <exception cref="NotSupportedException"> This Exception can be due to STT Not Supported. </exception>
883         /// <exception cref="UnauthorizedAccessException"> This Exception can be due to Permission Denied. </exception>
884         public IEnumerable<SupportedEngine> GetSupportedEngines()
885         {
886             List<SupportedEngine> engineList = new List<SupportedEngine>();
887             lock (thisLock)
888             {
889                 SupportedEngineCallback supportedEngineDelegate = (IntPtr handle, IntPtr engineId, IntPtr engineName, IntPtr userData) =>
890             {
891                 string id = Marshal.PtrToStringAnsi(engineId);
892                 string name = Marshal.PtrToStringAnsi(engineName);
893                 SupportedEngine engine = new SupportedEngine(id, name);
894                 engineList.Add(engine);
895                 return true;
896             };
897                 SttError error = SttForeEachSupportedEngines(_handle, supportedEngineDelegate, IntPtr.Zero);
898                 if (error != SttError.None)
899                 {
900                     Log.Error(LogTag, "Create Failed with error " + error);
901                     throw ExceptionFactory.CreateException(error);
902                 }
903             }
904
905             return engineList;
906         }
907
908         /// <summary>
909         /// Sets the app credential
910         /// </summary>
911         /// <since_tizen> 3 </since_tizen>
912         /// <param name="credential">
913         /// The credential string
914         /// </param>
915         /// <privilege>
916         /// http://tizen.org/privilege/recorder
917         /// </privilege>
918         /// <feature>
919         /// http://tizen.org/feature/speech.recognition
920         /// http://tizen.org/feature/microphone
921         /// </feature>
922         /// <exception cref="InvalidOperationException">
923         /// This Exception can be due to the following reasons
924         /// 1. Operation Failed
925         /// 2. Invalid State
926         /// </exception>
927         /// <exception cref="OutOfMemoryException"> This Exception can be due to Out of Memory. </exception>
928         /// <exception cref="NotSupportedException"> This Exception can be due to STT Not Supported. </exception>
929         /// <exception cref="UnauthorizedAccessException"> This Exception can be due to Permission Denied. </exception>
930         /// <exception cref="ArgumentException"> This can happen if Improper value is provided while setting the value. </exception>
931         /// <pre>
932         /// The State must be Created.
933         /// </pre>
934         public void SetCredential(string credential)
935         {
936             lock (thisLock)
937             {
938                 SttError error = SttSetcredential(_handle, credential);
939                 if (error != SttError.None)
940                 {
941                     Log.Error(LogTag, "SetCredential Failed with error " + error);
942                     throw ExceptionFactory.CreateException(error);
943                 }
944             }
945         }
946
947         /// <summary>
948         /// Connects to the STT service asynchronously.
949         /// </summary>
950         /// <since_tizen> 3 </since_tizen>
951         /// <privilege>
952         /// http://tizen.org/privilege/recorder
953         /// </privilege>
954         /// <feature>
955         /// http://tizen.org/feature/speech.recognition
956         /// http://tizen.org/feature/microphone
957         /// </feature>
958         /// <exception cref="InvalidOperationException"> This Exception can be due to Invalid State. </exception>
959         /// <exception cref="NotSupportedException"> This Exception can be due to STT Not Supported. </exception>
960         /// <exception cref="UnauthorizedAccessException"> This Exception can be due to Permission Denied. </exception>
961         /// <pre>
962         /// The State must be Created.
963         /// </pre>
964         /// <post>
965         /// If this function is successful, the STT state will be Ready
966         /// If this function is unsuccessful, ErrorOccurred event will be invoked
967         /// </post>
968         public void Prepare()
969         {
970             lock (thisLock)
971             {
972                 SttError error = SttPrepare(_handle);
973                 if (error != SttError.None)
974                 {
975                     Log.Error(LogTag, "SetEngine Failed with error " + error);
976                     throw ExceptionFactory.CreateException(error);
977                 }
978             }
979         }
980
981         /// <summary>
982         /// Disconnects from the STT service.
983         /// </summary>
984         /// <since_tizen> 3 </since_tizen>
985         /// <privilege>
986         /// http://tizen.org/privilege/recorder
987         /// </privilege>
988         /// <feature>
989         /// http://tizen.org/feature/speech.recognition
990         /// http://tizen.org/feature/microphone
991         /// </feature>
992         /// <exception cref="InvalidOperationException"> This Exception can be due to Invalid State. </exception>
993         /// <exception cref="NotSupportedException"> This Exception can be due to STT Not Supported. </exception>
994         /// <exception cref="UnauthorizedAccessException"> This Exception can be due to Permission Denied. </exception>
995         /// <pre>
996         /// The State must be Ready.
997         /// </pre>
998         /// <post>
999         /// If this function is successful, the STT state will be Created
1000         /// </post>
1001         public void Unprepare()
1002         {
1003             lock (thisLock)
1004             {
1005                 SttError error = SttUnprepare(_handle);
1006                 if (error != SttError.None)
1007                 {
1008                     Log.Error(LogTag, "Unprepare Failed with error " + error);
1009                     throw ExceptionFactory.CreateException(error);
1010                 }
1011             }
1012         }
1013
1014         /// <summary>
1015         /// Retrieves all supported languages of current engine.
1016         /// 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.
1017         /// For example, "ko_KR" for Korean, "en_US" for American English.
1018         /// </summary>
1019         /// <since_tizen> 3 </since_tizen>
1020         /// <privilege>
1021         /// http://tizen.org/privilege/recorder
1022         /// </privilege>
1023         /// <returns>
1024         /// list of strings of supported languages.
1025         /// </returns>
1026         /// <feature>
1027         /// http://tizen.org/feature/speech.recognition
1028         /// http://tizen.org/feature/microphone
1029         /// </feature>
1030         /// <exception cref="InvalidOperationException">
1031         /// This Exception can be due to the following reasons
1032         /// 1. Engine Not Found.
1033         /// 2. Operation Failed.
1034         /// </exception>
1035         /// <exception cref="NotSupportedException"> This Exception can be due to STT Not Supported. </exception>
1036         /// <exception cref="UnauthorizedAccessException"> This Exception can be due to Permission Denied. </exception>
1037         public IEnumerable<string> GetSupportedLanguages()
1038         {
1039             List<string> languageList = new List<string>();
1040             lock (thisLock)
1041             {
1042                 SupportedLanguageCallback supportedLanguageDelegate = (IntPtr handle, IntPtr language, IntPtr userData) =>
1043             {
1044                 string lang = Marshal.PtrToStringAnsi(language);
1045                 languageList.Add(lang);
1046                 return true;
1047             };
1048
1049                 SttError error = SttForeachSupportedLanguages(_handle, supportedLanguageDelegate, IntPtr.Zero);
1050                 if (error != SttError.None)
1051                 {
1052                     Log.Error(LogTag, "GetSupportedLanguages Failed with error " + error);
1053                     throw ExceptionFactory.CreateException(error);
1054                 }
1055             }
1056
1057             return languageList;
1058         }
1059
1060         /// <summary>
1061         /// Checks whether the recognition type is supported.
1062         /// </summary>
1063         /// <since_tizen> 3 </since_tizen>
1064         /// <privilege>
1065         /// http://tizen.org/privilege/recorder
1066         /// </privilege>
1067         /// <param name="type">
1068         /// RecognitionType value.
1069         /// </param>
1070         /// <returns>
1071         /// bool value indicating whether the recognition type is supported.
1072         /// </returns>
1073         /// <feature>
1074         /// http://tizen.org/feature/speech.recognition
1075         /// http://tizen.org/feature/microphone
1076         /// </feature>
1077         /// <exception cref="InvalidOperationException">
1078         /// This Exception can be due to the following reasons
1079         /// 1. Invalid State
1080         /// 2. Engine Not Found.
1081         /// 3. Operation Failed.
1082         /// </exception>
1083         /// <exception cref="NotSupportedException"> This Exception can be due to STT Not Supported. </exception>
1084         /// <pre>
1085         /// The state should be Ready.
1086         /// </pre>
1087         public bool IsRecognitionTypeSupported(RecognitionType type)
1088         {
1089             bool supported;
1090             lock (thisLock)
1091             {
1092                 string recType = "stt.recognition.type.FREE";
1093                 switch (type)
1094                 {
1095                     case RecognitionType.Free:
1096                         {
1097                             recType = "stt.recognition.type.FREE";
1098                             break;
1099                         }
1100
1101                     case RecognitionType.Partial:
1102                         {
1103                             recType = "stt.recognition.type.FREE.PARTIAL";
1104                             break;
1105                         }
1106
1107                     case RecognitionType.Search:
1108                         {
1109                             recType = "stt.recognition.type.SEARCH";
1110                             break;
1111                         }
1112
1113                     case RecognitionType.WebSearch:
1114                         {
1115                             recType = "stt.recognition.type.WEB_SEARCH";
1116                             break;
1117                         }
1118
1119                     case RecognitionType.Map:
1120                         {
1121                             recType = "stt.recognition.type.MAP";
1122                             break;
1123                         }
1124
1125                 }
1126
1127                 SttError error = SttIsRecognitionTypeSupported(_handle, recType, out supported);
1128                 if (error != SttError.None)
1129                 {
1130                     Log.Error(LogTag, "IsRecognitionTypeSupported Failed with error " + error);
1131                     throw ExceptionFactory.CreateException(error);
1132                 }
1133
1134             }
1135
1136             return supported;
1137         }
1138
1139         /// <summary>
1140         /// Sets the silence detection.
1141         /// </summary>
1142         /// <since_tizen> 3 </since_tizen>
1143         /// <privilege>
1144         /// http://tizen.org/privilege/recorder
1145         /// </privilege>
1146         /// <param name="type">
1147         /// SilenceDetection value.
1148         /// </param>
1149         /// <feature>
1150         /// http://tizen.org/feature/speech.recognition
1151         /// http://tizen.org/feature/microphone
1152         /// </feature>
1153         /// <exception cref="InvalidOperationException">
1154         /// This Exception can be due to the following reasons
1155         /// 1. Invalid State
1156         /// 2. Not supported feature of current engine.
1157         /// 3. Operation Failed.
1158         /// </exception>
1159         /// <exception cref="NotSupportedException"> This Exception can be due to STT Not Supported. </exception>
1160         /// <pre>
1161         /// The state should be Ready.
1162         /// </pre>
1163         public void SetSilenceDetection(SilenceDetection type)
1164         {
1165             lock (thisLock)
1166             {
1167                 SttError error = SttSetSilenceDetection(_handle, type);
1168                 if (error != SttError.None)
1169                 {
1170                     Log.Error(LogTag, "SetSilenceDetection Failed with error " + error);
1171                     throw ExceptionFactory.CreateException(error);
1172                 }
1173             }
1174         }
1175
1176         /// <summary>
1177         /// Sets the sound to start recording.
1178         /// Sound file type should be wav type.
1179         /// </summary>
1180         /// <since_tizen> 3 </since_tizen>
1181         /// <privilege>
1182         /// http://tizen.org/privilege/recorder
1183         /// </privilege>
1184         /// <param name="filePath">
1185         /// File Path for the sound.
1186         /// </param>
1187         /// <feature>
1188         /// http://tizen.org/feature/speech.recognition
1189         /// http://tizen.org/feature/microphone
1190         /// </feature>
1191         /// <exception cref="InvalidOperationException">
1192         /// This Exception can be due to the following reasons
1193         /// 1. Invalid State.
1194         /// 2. Operation Failed.
1195         /// </exception>
1196         /// <exception cref="NotSupportedException"> This Exception can be due to STT Not Supported. </exception>
1197         /// <exception cref="UnauthorizedAccessException"> This Exception can be due to Permission Denied. </exception>
1198         /// <exception cref="ArgumentException"> If an Invalid Parameter is provided. </exception>
1199         /// <pre>
1200         /// The state should be Ready.
1201         /// </pre>
1202         public void SetStartSound(string filePath)
1203         {
1204             lock (thisLock)
1205             {
1206                 SttError error = SttSetStartSound(_handle, filePath);
1207                 if (error != SttError.None)
1208                 {
1209                     Log.Error(LogTag, "SetStartSound Failed with error " + error);
1210                     throw ExceptionFactory.CreateException(error);
1211                 }
1212             }
1213         }
1214
1215         /// <summary>
1216         /// Unsets the sound to start recording.
1217         /// </summary>
1218         /// <since_tizen> 3 </since_tizen>
1219         /// <privilege>
1220         /// http://tizen.org/privilege/recorder
1221         /// </privilege>
1222         /// <feature>
1223         /// http://tizen.org/feature/speech.recognition
1224         /// http://tizen.org/feature/microphone
1225         /// </feature>
1226         /// <exception cref="InvalidOperationException">
1227         /// This Exception can be due to the following reasons
1228         /// 1. Invalid State.
1229         /// 2. Operation Failed.
1230         /// </exception>
1231         /// <exception cref="NotSupportedException"> This Exception can be due to STT Not Supported. </exception>
1232         /// <exception cref="UnauthorizedAccessException"> This Exception can be due to Permission Denied. </exception>
1233         /// <pre>
1234         /// The state should be Ready.
1235         /// </pre>
1236         public void UnsetStartSound()
1237         {
1238             lock (thisLock)
1239             {
1240                 SttError error = SttUnsetStartSound(_handle);
1241                 if (error != SttError.None)
1242                 {
1243                     Log.Error(LogTag, "UnsetStartSound Failed with error " + error);
1244                     throw ExceptionFactory.CreateException(error);
1245                 }
1246             }
1247         }
1248
1249         /// <summary>
1250         /// Sets the sound to stop recording.
1251         /// Sound file type should be wav type.
1252         /// </summary>
1253         /// <since_tizen> 3 </since_tizen>
1254         /// <privilege>
1255         /// http://tizen.org/privilege/recorder
1256         /// </privilege>
1257         /// <param name="filePath">
1258         /// File Path for the sound.
1259         /// </param>
1260         /// <feature>
1261         /// http://tizen.org/feature/speech.recognition
1262         /// http://tizen.org/feature/microphone
1263         /// </feature>
1264         /// <exception cref="InvalidOperationException">
1265         /// This Exception can be due to the following reasons
1266         /// 1. Invalid State.
1267         /// 2. Operation Failed.
1268         /// </exception>
1269         /// <exception cref="NotSupportedException"> This Exception can be due to STT Not Supported. </exception>
1270         /// <exception cref="UnauthorizedAccessException"> This Exception can be due to Permission Denied. </exception>
1271         /// <exception cref="ArgumentException"> If an Invalid Parameter is provided. </exception>
1272         /// <pre>
1273         /// The state should be Ready.
1274         /// </pre>
1275         public void SetStopSound(string filePath)
1276         {
1277             lock (thisLock)
1278             {
1279                 SttError error = SttSetStopSound(_handle, filePath);
1280                 if (error != SttError.None)
1281                 {
1282                     Log.Error(LogTag, "SetStopSound Failed with error " + error);
1283                     throw ExceptionFactory.CreateException(error);
1284                 }
1285             }
1286         }
1287
1288         /// <summary>
1289         /// Unsets the sound to stop recording.
1290         /// </summary>
1291         /// <since_tizen> 3 </since_tizen>
1292         /// <privilege>
1293         /// http://tizen.org/privilege/recorder
1294         /// </privilege>
1295         /// <feature>
1296         /// http://tizen.org/feature/speech.recognition
1297         /// http://tizen.org/feature/microphone
1298         /// </feature>
1299         /// <exception cref="InvalidOperationException">
1300         /// This Exception can be due to the following reasons
1301         /// 1. Invalid State.
1302         /// 2. Operation Failed.
1303         /// </exception>
1304         /// <exception cref="NotSupportedException"> This Exception can be due to STT Not Supported. </exception>
1305         /// <exception cref="UnauthorizedAccessException"> This Exception can be due to Permission Denied. </exception>
1306         /// <pre>
1307         /// The state should be Ready.
1308         /// </pre>
1309         public void UnsetStopSound()
1310         {
1311             lock (thisLock)
1312             {
1313                 SttError error = SttUnsetStopSound(_handle);
1314                 if (error != SttError.None)
1315                 {
1316                     Log.Error(LogTag, "UnsetStopSound Failed with error " + error);
1317                     throw ExceptionFactory.CreateException(error);
1318                 }
1319             }
1320         }
1321
1322         /// <summary>
1323         /// Starts recording and recognition asynchronously.
1324         /// This function starts recording in the STT service and sending recording data to engine.
1325         /// This work continues until Stop, Cancel or silence detected by engine
1326         /// </summary>
1327         /// <since_tizen> 3 </since_tizen>
1328         /// <privilege>
1329         /// http://tizen.org/privilege/recorder
1330         /// </privilege>
1331         /// <param name="language">
1332         /// The language selected
1333         /// </param>
1334         /// <param name="type">
1335         /// The type for recognition
1336         /// </param>
1337         /// <feature>
1338         /// http://tizen.org/feature/speech.recognition
1339         /// http://tizen.org/feature/microphone
1340         /// </feature>
1341         /// <exception cref="InvalidOperationException">
1342         /// This Exception can be due to the following reasons
1343         /// 1. Invalid State.
1344         /// 2. Operation Failed.
1345         /// 3. Recorder Busy.
1346         /// 4. Progress to recording is not finished
1347         /// </exception>
1348         /// <exception cref="NotSupportedException"> This Exception can be due to STT Not Supported. </exception>
1349         /// <exception cref="UnauthorizedAccessException"> This Exception can be due to Permission Denied. </exception>
1350         /// <exception cref="ArgumentException"> If an Invalid Language is provided. </exception>
1351         /// <pre>
1352         /// The state should be Ready.
1353         /// </pre>
1354         /// <post>
1355         /// It will invoke StateChanged Event if registered.
1356         /// If this function succeeds, the STT state will be Recording.
1357         /// If you call this function again before state changes, you will receive ErrorINProgressToRecording.
1358         /// </post>
1359         public void Start(string language, RecognitionType type)
1360         {
1361             lock (thisLock)
1362             {
1363                 string recType = "stt.recognition.type.FREE";
1364                 switch (type)
1365                 {
1366                     case RecognitionType.Free:
1367                         {
1368                             recType = "stt.recognition.type.FREE";
1369                             break;
1370                         }
1371
1372                     case RecognitionType.Partial:
1373                         {
1374                             recType = "stt.recognition.type.FREE.PARTIAL";
1375                             break;
1376                         }
1377
1378                     case RecognitionType.Search:
1379                         {
1380                             recType = "stt.recognition.type.SEARCH";
1381                             break;
1382                         }
1383
1384                     case RecognitionType.WebSearch:
1385                         {
1386                             recType = "stt.recognition.type.WEB_SEARCH";
1387                             break;
1388                         }
1389
1390                     case RecognitionType.Map:
1391                         {
1392                             recType = "stt.recognition.type.MAP";
1393                             break;
1394                         }
1395
1396                 }
1397
1398                 SttError error = SttStart(_handle, language, recType);
1399                 if (error != SttError.None)
1400                 {
1401                     Log.Error(LogTag, "Start Failed with error " + error);
1402                     throw ExceptionFactory.CreateException(error);
1403                 }
1404             }
1405         }
1406
1407         /// <summary>
1408         /// Finishes the recording and starts recognition processing in engine asynchronously.
1409         /// </summary>
1410         /// <since_tizen> 3 </since_tizen>
1411         /// <privilege>
1412         /// http://tizen.org/privilege/recorder
1413         /// </privilege>
1414         /// <feature>
1415         /// http://tizen.org/feature/speech.recognition
1416         /// http://tizen.org/feature/microphone
1417         /// </feature>
1418         /// <exception cref="InvalidOperationException">
1419         /// This Exception can be due to the following reasons
1420         /// 1. Invalid State.
1421         /// 2. Operation Failed.
1422         /// 3. Progress to ready is not finished.
1423         /// 4. Progress to recording is not finished.
1424         /// 5. Progress to processing is not finished.
1425         /// </exception>
1426         /// <exception cref="NotSupportedException"> This Exception can be due to STT Not Supported. </exception>
1427         /// <exception cref="UnauthorizedAccessException"> This Exception can be due to Permission Denied. </exception>
1428         /// <pre>
1429         /// The state should be Recording.
1430         /// </pre>
1431         /// <post>
1432         /// It will invoke StateChanged Event if registered.
1433         /// If this function succeeds, the STT state will be Processing.
1434         /// If you call this function again before state changes, you will receive ErrorINProgressToProcessing.
1435         /// After processing of engine, RecognitionResult event is invoked
1436         /// </post>
1437         public void Stop()
1438         {
1439             lock (thisLock)
1440             {
1441                 SttError error = SttStop(_handle);
1442                 if (error != SttError.None)
1443                 {
1444                     Log.Error(LogTag, "Stop Failed with error " + error);
1445                     throw ExceptionFactory.CreateException(error);
1446                 }
1447             }
1448         }
1449
1450         /// <summary>
1451         /// Cancels processing recognition and recording asynchronously.
1452         /// This function cancels recording and engine cancels recognition processing.
1453         /// After successful cancel, StateChanged event is invoked otherwise if error is occurred, ErrorOccurred event is invoked.
1454         /// </summary>
1455         /// <since_tizen> 3 </since_tizen>
1456         /// <privilege>
1457         /// http://tizen.org/privilege/recorder
1458         /// </privilege>
1459         /// <feature>
1460         /// http://tizen.org/feature/speech.recognition
1461         /// http://tizen.org/feature/microphone
1462         /// </feature>
1463         /// <exception cref="InvalidOperationException">
1464         /// This Exception can be due to the following reasons
1465         /// 1. Invalid State.
1466         /// 2. Operation Failed.
1467         /// 3. Progress to ready is not finished.
1468         /// 4. Progress to recording is not finished.
1469         /// 5. Progress to processing is not finished.
1470         /// </exception>
1471         /// <exception cref="NotSupportedException"> This Exception can be due to STT Not Supported. </exception>
1472         /// <exception cref="UnauthorizedAccessException"> This Exception can be due to Permission Denied. </exception>
1473         /// <pre>
1474         /// The state should be Recording or Processing.
1475         /// </pre>
1476         /// <post>
1477         /// It will invoke StateChanged Event if registered.
1478         /// If this function succeeds, the STT state will be Ready.
1479         /// If you call this function again before state changes, you will receive ErrorINProgressToReady.
1480         /// </post>
1481         public void Cancel()
1482         {
1483             lock (thisLock)
1484             {
1485                 SttError error = SttCancel(_handle);
1486                 if (error != SttError.None)
1487                 {
1488                     Log.Error(LogTag, "Cancel Failed with error " + error);
1489                     throw ExceptionFactory.CreateException(error);
1490                 }
1491             }
1492         }
1493
1494         /// <summary>
1495         /// Method to release resources
1496         /// </summary>
1497         public void Dispose()
1498         {
1499             Dispose(true);
1500         }
1501
1502         protected virtual void Dispose(bool disposing)
1503         {
1504             if (!disposedValue)
1505             {
1506                 if (disposing)
1507                 {
1508                     SttError error = SttDestroy(_handle);
1509                     if (error != SttError.None)
1510                     {
1511                         Log.Error(LogTag, "Destroy Failed with error " + error);
1512                     }
1513                 }
1514
1515                 disposedValue = true;
1516             }
1517         }
1518     }
1519 }