2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 using System.Collections.Generic;
20 using System.Runtime.InteropServices;
21 using static Interop.Stt;
23 namespace Tizen.Uix.Stt
28 /// <since_tizen> 3 </since_tizen>
29 public enum ResultEvent
32 /// Event when the recognition full or last result is ready
34 /// <since_tizen> 3 </since_tizen>
37 /// Event when the recognition partial result is ready
39 /// <since_tizen> 3 </since_tizen>
42 /// Event when the recognition has failed
44 /// <since_tizen> 3 </since_tizen>
49 /// Enumeration representing the result message
51 /// <since_tizen> 3 </since_tizen>
52 public enum ResultMessage
57 /// <since_tizen> 3 </since_tizen>
60 /// Recognition failed because the speech started too soon.
62 /// <since_tizen> 3 </since_tizen>
65 /// Recognition failed because the speech is too short.
67 /// <since_tizen> 3 </since_tizen>
70 /// Recognition failed because the speech is too long.
72 /// <since_tizen> 3 </since_tizen>
75 /// Recognition failed because the speech is too quiet to listen.
77 /// <since_tizen> 3 </since_tizen>
80 /// Recognition failed because the speech is too loud to listen.
82 /// <since_tizen> 3 </since_tizen>
85 /// Recognition failed because the speech is too fast to listen.
87 /// <since_tizen> 3 </since_tizen>
92 /// Enumeration for the Token type
94 /// <since_tizen> 3 </since_tizen>
98 /// Event when the token is beginning type
100 /// <since_tizen> 3 </since_tizen>
103 /// Event when the token is middle type
105 /// <since_tizen> 3 </since_tizen>
108 /// Event when the token is end type
110 /// <since_tizen> 3 </since_tizen>
115 /// Enum for Error values that can occur
117 /// <since_tizen> 3 </since_tizen>
121 /// Successful, No error
123 /// <since_tizen> 3 </since_tizen>
128 /// <since_tizen> 3 </since_tizen>
133 /// <since_tizen> 3 </since_tizen>
136 /// Invalid parameter
138 /// <since_tizen> 3 </since_tizen>
141 /// No answer from the STT service
143 /// <since_tizen> 3 </since_tizen>
146 /// Device or resource busy
148 /// <since_tizen> 3 </since_tizen>
153 /// <since_tizen> 3 </since_tizen>
156 /// Permission denied
158 /// <since_tizen> 3 </since_tizen>
161 /// STT NOT supported
163 /// <since_tizen> 3 </since_tizen>
168 /// <since_tizen> 3 </since_tizen>
173 /// <since_tizen> 3 </since_tizen>
176 /// No available engine
178 /// <since_tizen> 3 </since_tizen>
183 /// <since_tizen> 3 </since_tizen>
186 /// Not supported feature of current engine
188 /// <since_tizen> 3 </since_tizen>
191 /// Recording timed out
193 /// <since_tizen> 3 </since_tizen>
196 /// No speech while recording
198 /// <since_tizen> 3 </since_tizen>
201 /// Progress to ready is not finished
203 /// <since_tizen> 3 </since_tizen>
206 /// Progress to recording is not finished
208 /// <since_tizen> 3 </since_tizen>
209 InProgressToRecording,
211 /// Progress to processing is not finished
213 /// <since_tizen> 3 </since_tizen>
214 InProgressToProcessing,
218 /// <since_tizen> 3 </since_tizen>
223 /// Enumeration for Recognition Types
225 /// <since_tizen> 3 </since_tizen>
226 public enum RecognitionType
229 /// Free form dictation
231 /// <since_tizen> 3 </since_tizen>
234 /// Continuous free dictation.
236 /// <since_tizen> 3 </since_tizen>
241 /// <since_tizen> 3 </since_tizen>
246 /// <since_tizen> 3 </since_tizen>
251 /// <since_tizen> 3 </since_tizen>
256 /// Enumeration for the State types
258 /// <since_tizen> 3 </since_tizen>
264 /// <since_tizen> 3 </since_tizen>
269 /// <since_tizen> 3 </since_tizen>
274 /// <since_tizen> 3 </since_tizen>
279 /// <since_tizen> 3 </since_tizen>
284 /// <since_tizen> 3 </since_tizen>
289 /// Enumeration for the Silence Detection types
291 /// <since_tizen> 3 </since_tizen>
292 public enum SilenceDetection
295 /// Silence detection type - False
297 /// <since_tizen> 3 </since_tizen>
300 /// Silence detection type - True
302 /// <since_tizen> 3 </since_tizen>
305 /// Silence detection type - Auto
307 /// <since_tizen> 3 </since_tizen>
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.
319 /// <since_tizen> 3 </since_tizen>
320 public class SttClient : IDisposable
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<ErrorOccuredEventArgs> _errorOccured;
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;
339 /// Constructor to create a STT instance.
341 /// <since_tizen> 3 </since_tizen>
343 /// http://tizen.org/privilege/recorder
346 /// http://tizen.org/feature/speech.recognition
347 /// http://tizen.org/feature/microphone
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>
356 SttError error = SttCreate(out handle);
357 if (error != SttError.None)
359 Log.Error(LogTag, "Create Failed with error " + error);
360 throw ExceptionFactory.CreateException(error);
367 /// Event to be invoked when the recognition is done.
369 /// <since_tizen> 3 </since_tizen>
370 public event EventHandler<RecognitionResultEventArgs> RecognitionResult
376 _resultDelegate = (IntPtr handle, ResultEvent e, IntPtr data, int dataCount, IntPtr msg, IntPtr userData) =>
378 Log.Info(LogTag, "Recognition Result Event Triggered");
379 if (data != null && msg != null)
381 RecognitionResultEventArgs args = new RecognitionResultEventArgs(e, data, dataCount, Marshal.PtrToStringAnsi(msg));
382 _recognitionResult?.Invoke(this, args);
386 Log.Info(LogTag, "Recognition Result Event null received");
389 SttError error = SttSetRecognitionResultCB(_handle, _resultDelegate, IntPtr.Zero);
390 if (error != SttError.None)
392 Log.Error(LogTag, "Add RecognitionResult Failed with error " + error);
396 _recognitionResult += value;
405 SttError error = SttUnsetRecognitionResultCB(_handle);
406 if (error != SttError.None)
408 Log.Error(LogTag, "Remove RecognitionResult Failed with error " + error);
411 _recognitionResult -= value;
417 /// Event to be invoked when STT state changes.
419 /// <since_tizen> 3 </since_tizen>
420 public event EventHandler<StateChangedEventArgs> StateChanged
426 SttClient obj = this;
427 _stateDelegate = (IntPtr handle, State previous, State current, IntPtr userData) =>
429 StateChangedEventArgs args = new StateChangedEventArgs(previous, current);
430 _stateChanged?.Invoke(obj, args);
432 SttError error = SttSetStateChangedCB(_handle, _stateDelegate, IntPtr.Zero);
433 if (error != SttError.None)
435 Log.Error(LogTag, "Add StateChanged Failed with error " + error);
439 _stateChanged += value;
449 SttError error = SttUnsetStateChangedCB(_handle);
450 if (error != SttError.None)
452 Log.Error(LogTag, "Remove StateChanged Failed with error " + error);
455 _stateChanged -= value;
462 /// Event to be invoked when an error occurs.
464 /// <since_tizen> 3 </since_tizen>
465 public event EventHandler<ErrorOccuredEventArgs> ErrorOccured
471 _errorDelegate = (IntPtr handle, SttError reason, IntPtr userData) =>
473 ErrorOccuredEventArgs args = new ErrorOccuredEventArgs(handle, reason);
474 _errorOccured?.Invoke(this, args);
476 SttError error = SttSetErrorCB(_handle, _errorDelegate, IntPtr.Zero);
477 if (error != SttError.None)
479 Log.Error(LogTag, "Add ErrorOccured Failed with error " + error);
484 _errorOccured += value;
494 SttError error = SttUnsetErrorCB(_handle);
495 if (error != SttError.None)
497 Log.Error(LogTag, "Remove ErrorOccured Failed with error " + error);
500 _errorOccured -= value;
506 /// Event to be invoked when default laungage change.
508 /// <since_tizen> 3 </since_tizen>
509 public event EventHandler<DefaultLanguageChangedEventArgs> DefaultLanguageChanged
515 _languageDelegate = (IntPtr handle, IntPtr previousLanguage, IntPtr currentLanguage, IntPtr userData) =>
517 string previousLanguageString = Marshal.PtrToStringAnsi(previousLanguage);
518 string currentLanguageString = Marshal.PtrToStringAnsi(currentLanguage);
519 DefaultLanguageChangedEventArgs args = new DefaultLanguageChangedEventArgs(previousLanguageString, currentLanguageString);
520 _defaultLanguageChanged?.Invoke(this, args);
522 SttError error = SttSetDefaultLanguageChangedCB(_handle, _languageDelegate, IntPtr.Zero);
523 if (error != SttError.None)
525 Log.Error(LogTag, "Add DefaultLanguageChanged Failed with error " + error);
530 _defaultLanguageChanged += value;
540 SttError error = SttUnsetDefaultLanguageChangedCB(_handle);
541 if (error != SttError.None)
543 Log.Error(LogTag, "Remove DefaultLanguageChanged Failed with error " + error);
546 _defaultLanguageChanged -= value;
553 /// Event to be invoked to detect engine change.
555 /// <since_tizen> 3 </since_tizen>
556 public event EventHandler<EngineChangedEventArgs> EngineChanged
562 _engineDelegate = (IntPtr handle, IntPtr engineId, IntPtr language, bool supportSilence, bool needCredential, IntPtr userData) =>
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);
569 SttError error = SttSetEngineChangedCB(_handle, _engineDelegate, IntPtr.Zero);
570 if (error != SttError.None)
572 Log.Error(LogTag, "Add EngineChanged Failed with error " + error);
576 _engineChanged += value;
585 SttError error = SttUnsetEngineChangedCB(_handle);
586 if (error != SttError.None)
588 Log.Error(LogTag, "Remove EngineChanged Failed with error " + error);
591 _engineChanged -= value;
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.
601 /// <since_tizen> 3 </since_tizen>
603 /// Default language in STT.
606 /// http://tizen.org/privilege/recorder
609 /// Default Lanaguage string value.
611 public string DefaultLanguage
618 SttError error = SttGetDefaultLanguage(_handle, out language);
619 if (error != SttError.None)
621 Log.Error(LogTag, "DefaultLanaguage Failed with error " + error);
631 /// Gets the microphone volume during recording.
633 /// <since_tizen> 3 </since_tizen>
635 /// Recording volume in STT.
638 /// http://tizen.org/privilege/recorder
641 /// The State must be Recording.
643 public float RecordingVolume
650 SttError error = SttGetRecordingVolume(_handle, out volume);
651 if (error != SttError.None)
653 Log.Error(LogTag, "GetRecordingVolume Failed with error " + error);
665 /// Gets the current STT state.
667 /// <since_tizen> 3 </since_tizen>
669 /// Current state of STT.
672 /// http://tizen.org/privilege/recorder
675 /// Current STT State value.
677 public State CurrentState
684 SttError error = SttGetState(_handle, out state);
685 if (error != SttError.None)
687 Log.Error(LogTag, "GetState Failed with error " + error);
688 return State.Unavailable;
698 /// This property can be used to get and set the current engine id.
700 /// <since_tizen> 3 </since_tizen>
702 /// Current STT engine id.
705 /// http://tizen.org/privilege/recorder
707 /// <exception cref="InvalidOperationException">
708 /// This Exception can occur while setting due to the following reaons
709 /// 1. Operation Failed
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>
717 /// The State must be Created.
726 SttError error = SttGetEngine(_handle, out engineId);
727 if (error != SttError.None)
729 Log.Error(LogTag, "Get EngineId Failed with error " + error);
740 SttError error = SttSetEngine(_handle, value);
741 if (error != SttError.None)
743 Log.Error(LogTag, "Set EngineId Failed with error " + error);
744 throw ExceptionFactory.CreateException(error);
752 /// Retrieves the time stamp of the current recognition result
754 /// <since_tizen> 3 </since_tizen>
756 /// list of ResultTime
759 /// http://tizen.org/privilege/recorder
762 /// http://tizen.org/feature/speech.recognition
763 /// http://tizen.org/feature/microphone
766 /// This function should only be called in RecognitionResult Event
768 /// <exception cref="InvalidOperationException"> This Exception can be due to Opearation 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()
773 List<ResultTime> list = new List<ResultTime>();
774 _resultTimeDelegate = (IntPtr handle, int index, TimeEvent e, IntPtr text, IntPtr startTime, IntPtr endTime, IntPtr userData) =>
776 _result = new ResultTime(index, e, Marshal.PtrToStringAnsi(text), (long)startTime, (long)endTime);
780 SttError error = SttForeachDetailedResult(_handle, _resultTimeDelegate, IntPtr.Zero);
781 if (error != SttError.None)
783 Log.Error(LogTag, "GetDetailedResult Failed with error " + error);
784 throw ExceptionFactory.CreateException(error);
791 /// Gets the private data from stt engine.
793 /// <since_tizen> 3 </since_tizen>
794 /// <param name="key">
798 /// The Data Corresponding to the Key provided
801 /// http://tizen.org/privilege/recorder
804 /// http://tizen.org/feature/speech.recognition
805 /// http://tizen.org/feature/microphone
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>
811 /// The State must be Ready.
813 public string GetPrivateData(string key)
818 SttError error = SttGetPrivateData(_handle, key, out data);
819 if (error != SttError.None)
821 Log.Error(LogTag, "GetPrivateData Failed with error " + error);
822 throw ExceptionFactory.CreateException(error);
830 /// Sets the private data to stt engine.
832 /// <since_tizen> 3 </since_tizen>
833 /// <param name="key">
836 /// <param name="data">
840 /// http://tizen.org/privilege/recorder
843 /// http://tizen.org/feature/speech.recognition
844 /// http://tizen.org/feature/microphone
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>
851 /// The State must be Ready.
853 public void SetPrivateData(string key, string data)
857 SttError error = SttSetPrivateData(_handle, key, data);
858 if (error != SttError.None)
860 Log.Error(LogTag, "SetPrivateData Failed with error " + error);
861 throw ExceptionFactory.CreateException(error);
867 /// Gets the list of Supported Engine
869 /// <since_tizen> 3 </since_tizen>
871 /// IEnumerable<SupportedEngine> list of supported engines
874 /// http://tizen.org/privilege/recorder
877 /// http://tizen.org/feature/speech.recognition
878 /// http://tizen.org/feature/microphone
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()
886 List<SupportedEngine> engineList = new List<SupportedEngine>();
889 SupportedEngineCallback supportedEngineDelegate = (IntPtr handle, IntPtr engineId, IntPtr engineName, IntPtr userData) =>
891 string id = Marshal.PtrToStringAnsi(engineId);
892 string name = Marshal.PtrToStringAnsi(engineName);
893 SupportedEngine engine = new SupportedEngine(id, name);
894 engineList.Add(engine);
897 SttError error = SttForeEachSupportedEngines(_handle, supportedEngineDelegate, IntPtr.Zero);
898 if (error != SttError.None)
900 Log.Error(LogTag, "Create Failed with error " + error);
901 throw ExceptionFactory.CreateException(error);
909 /// Sets the app credential
911 /// <since_tizen> 3 </since_tizen>
912 /// <param name="credential">
913 /// The credential string
916 /// http://tizen.org/privilege/recorder
919 /// http://tizen.org/feature/speech.recognition
920 /// http://tizen.org/feature/microphone
922 /// <exception cref="InvalidOperationException">
923 /// This Exception can be due to the following reaons
924 /// 1. Operation Failed
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>
932 /// The State must be Created.
934 public void SetCredential(string credential)
938 SttError error = SttSetcredential(_handle, credential);
939 if (error != SttError.None)
941 Log.Error(LogTag, "SetCredential Failed with error " + error);
942 throw ExceptionFactory.CreateException(error);
948 /// Connects to the STT service asynchronously.
950 /// <since_tizen> 3 </since_tizen>
952 /// http://tizen.org/privilege/recorder
955 /// http://tizen.org/feature/speech.recognition
956 /// http://tizen.org/feature/microphone
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>
962 /// The State must be Created.
965 /// If this function is successful, the STT state will be Ready
966 /// If this function is unsuccessful, ErrorOccured event will be invoked
968 public void Prepare()
972 SttError error = SttPrepare(_handle);
973 if (error != SttError.None)
975 Log.Error(LogTag, "SetEngine Failed with error " + error);
976 throw ExceptionFactory.CreateException(error);
982 /// Disconnects from the STT service.
984 /// <since_tizen> 3 </since_tizen>
986 /// http://tizen.org/privilege/recorder
989 /// http://tizen.org/feature/speech.recognition
990 /// http://tizen.org/feature/microphone
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>
996 /// The State must be Ready.
999 /// If this function is successful, the STT state will be Created
1001 public void Unprepare()
1005 SttError error = SttUnprepare(_handle);
1006 if (error != SttError.None)
1008 Log.Error(LogTag, "Unprepare Failed with error " + error);
1009 throw ExceptionFactory.CreateException(error);
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.
1019 /// <since_tizen> 3 </since_tizen>
1021 /// http://tizen.org/privilege/recorder
1024 /// list of strings of supported languages.
1027 /// http://tizen.org/feature/speech.recognition
1028 /// http://tizen.org/feature/microphone
1030 /// <exception cref="InvalidOperationException">
1031 /// This Exception can be due to the following reasons
1032 /// 1. Engine Not Found.
1033 /// 2. Operation Failed.
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> GetSupportedLangauages()
1039 List<string> languageList = new List<string>();
1042 SupportedLanguageCallback supportedLanguageDelegate = (IntPtr handle, IntPtr language, IntPtr userData) =>
1044 string lang = Marshal.PtrToStringAnsi(language);
1045 languageList.Add(lang);
1049 SttError error = SttForeachSupportedLanguages(_handle, supportedLanguageDelegate, IntPtr.Zero);
1050 if (error != SttError.None)
1052 Log.Error(LogTag, "GetSupportedLangauages Failed with error " + error);
1053 throw ExceptionFactory.CreateException(error);
1057 return languageList;
1061 /// Checks whether the recognition type is supported.
1063 /// <since_tizen> 3 </since_tizen>
1065 /// http://tizen.org/privilege/recorder
1067 /// <param name="type">
1068 /// RecognitionType value.
1071 /// bool value indicating whether the recognition type is supported.
1074 /// http://tizen.org/feature/speech.recognition
1075 /// http://tizen.org/feature/microphone
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.
1083 /// <exception cref="NotSupportedException"> This Exception can be due to STT Not Supported. </exception>
1085 /// The state should be Ready.
1087 public bool IsRecognitionTypeSupported(RecognitionType type)
1092 string recType = "stt.recognition.type.FREE";
1095 case RecognitionType.Free:
1097 recType = "stt.recognition.type.FREE";
1101 case RecognitionType.Partial:
1103 recType = "stt.recognition.type.FREE.PARTIAL";
1107 case RecognitionType.Search:
1109 recType = "stt.recognition.type.SEARCH";
1113 case RecognitionType.WebSearch:
1115 recType = "stt.recognition.type.WEB_SEARCH";
1119 case RecognitionType.Map:
1121 recType = "stt.recognition.type.MAP";
1127 SttError error = SttIsRecognitionTypeSupported(_handle, recType, out supported);
1128 if (error != SttError.None)
1130 Log.Error(LogTag, "IsRecognitionTypeSupported Failed with error " + error);
1131 throw ExceptionFactory.CreateException(error);
1140 /// Sets the silence detection.
1142 /// <since_tizen> 3 </since_tizen>
1144 /// http://tizen.org/privilege/recorder
1146 /// <param name="type">
1147 /// SilenceDetection value.
1150 /// http://tizen.org/feature/speech.recognition
1151 /// http://tizen.org/feature/microphone
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.
1159 /// <exception cref="NotSupportedException"> This Exception can be due to STT Not Supported. </exception>
1161 /// The state should be Ready.
1163 public void SetSilenceDetection(SilenceDetection type)
1167 SttError error = SttSetSilenceDetection(_handle, type);
1168 if (error != SttError.None)
1170 Log.Error(LogTag, "SetSilenceDetection Failed with error " + error);
1171 throw ExceptionFactory.CreateException(error);
1177 /// Sets the sound to start recording.
1178 /// Sound file type should be wav type.
1180 /// <since_tizen> 3 </since_tizen>
1182 /// http://tizen.org/privilege/recorder
1184 /// <param name="filePath">
1185 /// File Path for the sound.
1188 /// http://tizen.org/feature/speech.recognition
1189 /// http://tizen.org/feature/microphone
1191 /// <exception cref="InvalidOperationException">
1192 /// This Exception can be due to the following reasons
1193 /// 1. Invalid State.
1194 /// 2. Operation Failed.
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>
1200 /// The state should be Ready.
1202 public void SetStartSound(string filePath)
1206 SttError error = SttSetStartSound(_handle, filePath);
1207 if (error != SttError.None)
1209 Log.Error(LogTag, "SetStartSound Failed with error " + error);
1210 throw ExceptionFactory.CreateException(error);
1216 /// Unsets the sound to start recording.
1218 /// <since_tizen> 3 </since_tizen>
1220 /// http://tizen.org/privilege/recorder
1223 /// http://tizen.org/feature/speech.recognition
1224 /// http://tizen.org/feature/microphone
1226 /// <exception cref="InvalidOperationException">
1227 /// This Exception can be due to the following reasons
1228 /// 1. Invalid State.
1229 /// 2. Operation Failed.
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>
1234 /// The state should be Ready.
1236 public void UnsetStartSound()
1240 SttError error = SttUnsetStartSound(_handle);
1241 if (error != SttError.None)
1243 Log.Error(LogTag, "UnsetStartSound Failed with error " + error);
1244 throw ExceptionFactory.CreateException(error);
1250 /// Sets the sound to stop recording.
1251 /// Sound file type should be wav type.
1253 /// <since_tizen> 3 </since_tizen>
1255 /// http://tizen.org/privilege/recorder
1257 /// <param name="filePath">
1258 /// File Path for the sound.
1261 /// http://tizen.org/feature/speech.recognition
1262 /// http://tizen.org/feature/microphone
1264 /// <exception cref="InvalidOperationException">
1265 /// This Exception can be due to the following reasons
1266 /// 1. Invalid State.
1267 /// 2. Operation Failed.
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>
1273 /// The state should be Ready.
1275 public void SetStopSound(string filePath)
1279 SttError error = SttSetStopSound(_handle, filePath);
1280 if (error != SttError.None)
1282 Log.Error(LogTag, "SetStopSound Failed with error " + error);
1283 throw ExceptionFactory.CreateException(error);
1289 /// Unsets the sound to stop recording.
1291 /// <since_tizen> 3 </since_tizen>
1293 /// http://tizen.org/privilege/recorder
1296 /// http://tizen.org/feature/speech.recognition
1297 /// http://tizen.org/feature/microphone
1299 /// <exception cref="InvalidOperationException">
1300 /// This Exception can be due to the following reasons
1301 /// 1. Invalid State.
1302 /// 2. Operation Failed.
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>
1307 /// The state should be Ready.
1309 public void UnsetStopSound()
1313 SttError error = SttUnsetStopSound(_handle);
1314 if (error != SttError.None)
1316 Log.Error(LogTag, "UnsetStopSound Failed with error " + error);
1317 throw ExceptionFactory.CreateException(error);
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
1327 /// <since_tizen> 3 </since_tizen>
1329 /// http://tizen.org/privilege/recorder
1331 /// <param name="language">
1332 /// The language selected
1334 /// <param name="type">
1335 /// The type for recognition
1338 /// http://tizen.org/feature/speech.recognition
1339 /// http://tizen.org/feature/microphone
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
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>
1352 /// The state should be Ready.
1355 /// It will invoke StateChanged Event if registerd.
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.
1359 public void Start(string language, RecognitionType type)
1363 string recType = "stt.recognition.type.FREE";
1366 case RecognitionType.Free:
1368 recType = "stt.recognition.type.FREE";
1372 case RecognitionType.Partial:
1374 recType = "stt.recognition.type.FREE.PARTIAL";
1378 case RecognitionType.Search:
1380 recType = "stt.recognition.type.SEARCH";
1384 case RecognitionType.WebSearch:
1386 recType = "stt.recognition.type.WEB_SEARCH";
1390 case RecognitionType.Map:
1392 recType = "stt.recognition.type.MAP";
1398 SttError error = SttStart(_handle, language, recType);
1399 if (error != SttError.None)
1401 Log.Error(LogTag, "Start Failed with error " + error);
1402 throw ExceptionFactory.CreateException(error);
1408 /// Finishes the recording and starts recognition processing in engine asynchronously.
1410 /// <since_tizen> 3 </since_tizen>
1412 /// http://tizen.org/privilege/recorder
1415 /// http://tizen.org/feature/speech.recognition
1416 /// http://tizen.org/feature/microphone
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.
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>
1429 /// The state should be Recording.
1432 /// It will invoke StateChanged Event if registerd.
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
1441 SttError error = SttStop(_handle);
1442 if (error != SttError.None)
1444 Log.Error(LogTag, "Stop Failed with error " + error);
1445 throw ExceptionFactory.CreateException(error);
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, ErrorOccured event is invoked.
1455 /// <since_tizen> 3 </since_tizen>
1457 /// http://tizen.org/privilege/recorder
1460 /// http://tizen.org/feature/speech.recognition
1461 /// http://tizen.org/feature/microphone
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.
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>
1474 /// The state should be Recording or Processing.
1477 /// It will invoke StateChanged Event if registerd.
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.
1481 public void Cancel()
1485 SttError error = SttCancel(_handle);
1486 if (error != SttError.None)
1488 Log.Error(LogTag, "Cancel Failed with error " + error);
1489 throw ExceptionFactory.CreateException(error);
1495 /// Method to release resources
1497 public void Dispose()
1502 protected virtual void Dispose(bool disposing)
1508 SttError error = SttDestroy(_handle);
1509 if (error != SttError.None)
1511 Log.Error(LogTag, "Destroy Failed with error " + error);
1515 disposedValue = true;