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 public enum ResultEvent
31 /// Event when the recognition full or last result is ready
35 /// Event when the recognition partial result is ready
39 /// Event when the recognition has failed
45 /// Enumeration representing the result message
47 public enum ResultMessage
54 /// Recognition failed because the speech started too soon.
58 /// Recognition failed because the speech is too short.
62 /// Recognition failed because the speech is too long.
66 /// Recognition failed because the speech is too quiet to listen.
70 /// Recognition failed because the speech is too loud to listen.
74 /// Recognition failed because the speech is too fast to listen.
80 /// Enumeration for the Token type
85 /// Event when the token is beginning type
89 /// Event when the token is middle type
93 /// Event when the token is end type
99 /// Enum for Error values that can occur
104 /// Successful, No error
116 /// Invalid parameter
120 /// No answer from the STT service
124 /// Device or resource busy
132 /// Permission denied
136 /// STT NOT supported
148 /// No available engine
156 /// Not supported feature of current engine
160 /// Recording timed out
164 /// No speech while recording
168 /// Progress to ready is not finished
172 /// Progress to recording is not finished
174 InProgressToRecording,
176 /// Progress to processing is not finished
178 InProgressToProcessing,
186 /// Enumeration for Recognition Types
188 public enum RecognitionType
191 /// Free form dictation
195 /// Continuous free dictation.
213 /// Enumeration for the State types
240 /// Enumeration for the Silence Detection types
242 public enum SilenceDetection
245 /// Silence detection type - False
249 /// Silence detection type - True
253 /// Silence detection type - Auto
259 /// A main function of Speech-To-Text (below STT) API recognizes sound data recorded by users.
260 /// After choosing a language, applications will start recording and recognizing.
261 /// After recording, the applications will receive the recognized result.
262 /// The STT has a client-server for the service of multi-applications.
263 /// 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.
264 /// 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.
266 public class SttClient : IDisposable
268 private IntPtr _handle;
269 private Object thisLock = new Object();
270 private event EventHandler<RecognitionResultEventArgs> _recognitionResult;
271 private event EventHandler<StateChangedEventArgs> _stateChanged;
272 private event EventHandler<ErrorOccuredEventArgs> _errorOccured;
273 private event EventHandler<DefaultLanguageChangedEventArgs> _defaultLanguageChanged;
274 private event EventHandler<EngineChangedEventArgs> _engineChanged;
275 private bool disposedValue = false;
276 private Interop.Stt.RecognitionResultCallback _resultDelegate;
277 private Interop.Stt.StateChangedCallback _stateDelegate;
278 private Interop.Stt.ErrorCallback _errorDelegate;
279 private Interop.Stt.DefaultLanguageChangedCallback _languageDelegate;
280 private Interop.Stt.EngineChangedCallback _engineDelegate;
281 private ResultTime _result;
282 private ResultTimeCallback _resultTimeDelegate;
285 /// Constructor to create a STT instance.
288 /// http://tizen.org/privilege/recorder
291 /// http://tizen.org/feature/speech.recognition
292 /// http://tizen.org/feature/microphone
294 /// <exception cref="InvalidOperationException">
295 /// This Exception can be due to the following reaons
297 /// 2. Operation Failed
298 /// 3. STT Not Supported
299 /// 4. Permission Denied
304 SttError error = SttCreate(out handle);
305 if (error != SttError.None)
307 Log.Error(LogTag, "Create Failed with error " + error);
308 throw ExceptionFactory.CreateException(error);
315 /// Event to be invoked when the recognition is done.
317 public event EventHandler<RecognitionResultEventArgs> RecognitionResult
323 _resultDelegate = (IntPtr handle, ResultEvent e, IntPtr data, int dataCount, IntPtr msg, IntPtr userData) =>
325 Log.Info(LogTag, "Recognition Result Event Triggered");
326 if (data != null && msg != null)
328 RecognitionResultEventArgs args = new RecognitionResultEventArgs(e, data, dataCount, Marshal.PtrToStringAnsi(msg));
329 _recognitionResult?.Invoke(this, args);
333 Log.Info(LogTag, "Recognition Result Event null received");
336 SttError error = SttSetRecognitionResultCB(_handle, _resultDelegate, IntPtr.Zero);
337 if (error != SttError.None)
339 Log.Error(LogTag, "Add RecognitionResult Failed with error " + error);
343 _recognitionResult += value;
352 SttError error = SttUnsetRecognitionResultCB(_handle);
353 if (error != SttError.None)
355 Log.Error(LogTag, "Remove RecognitionResult Failed with error " + error);
358 _recognitionResult -= value;
364 /// Event to be invoked when STT state changes.
366 public event EventHandler<StateChangedEventArgs> StateChanged
372 SttClient obj = this;
373 _stateDelegate = (IntPtr handle, State previous, State current, IntPtr userData) =>
375 StateChangedEventArgs args = new StateChangedEventArgs(previous, current);
376 _stateChanged?.Invoke(obj, args);
378 SttError error = SttSetStateChangedCB(_handle, _stateDelegate, IntPtr.Zero);
379 if (error != SttError.None)
381 Log.Error(LogTag, "Add StateChanged Failed with error " + error);
385 _stateChanged += value;
395 SttError error = SttUnsetStateChangedCB(_handle);
396 if (error != SttError.None)
398 Log.Error(LogTag, "Remove StateChanged Failed with error " + error);
401 _stateChanged -= value;
408 /// Event to be invoked when an error occurs.
410 public event EventHandler<ErrorOccuredEventArgs> ErrorOccured
416 _errorDelegate = (IntPtr handle, SttError reason, IntPtr userData) =>
418 ErrorOccuredEventArgs args = new ErrorOccuredEventArgs(handle, reason);
419 _errorOccured?.Invoke(this, args);
421 SttError error = SttSetErrorCB(_handle, _errorDelegate, IntPtr.Zero);
422 if (error != SttError.None)
424 Log.Error(LogTag, "Add ErrorOccured Failed with error " + error);
429 _errorOccured += value;
439 SttError error = SttUnsetErrorCB(_handle);
440 if (error != SttError.None)
442 Log.Error(LogTag, "Remove ErrorOccured Failed with error " + error);
445 _errorOccured -= value;
451 /// Event to be invoked when default laungage change.
453 public event EventHandler<DefaultLanguageChangedEventArgs> DefaultLanguageChanged
459 _languageDelegate = (IntPtr handle, IntPtr previousLanguage, IntPtr currentLanguage, IntPtr userData) =>
461 string previousLanguageString = Marshal.PtrToStringAnsi(previousLanguage);
462 string currentLanguageString = Marshal.PtrToStringAnsi(currentLanguage);
463 DefaultLanguageChangedEventArgs args = new DefaultLanguageChangedEventArgs(previousLanguageString, currentLanguageString);
464 _defaultLanguageChanged?.Invoke(this, args);
466 SttError error = SttSetDefaultLanguageChangedCB(_handle, _languageDelegate, IntPtr.Zero);
467 if (error != SttError.None)
469 Log.Error(LogTag, "Add DefaultLanguageChanged Failed with error " + error);
474 _defaultLanguageChanged += value;
484 SttError error = SttUnsetDefaultLanguageChangedCB(_handle);
485 if (error != SttError.None)
487 Log.Error(LogTag, "Remove DefaultLanguageChanged Failed with error " + error);
490 _defaultLanguageChanged -= value;
497 /// Event to be invoked to detect engine change.
499 public event EventHandler<EngineChangedEventArgs> EngineChanged
505 _engineDelegate = (IntPtr handle, IntPtr engineId, IntPtr language, bool supportSilence, bool needCredential, IntPtr userData) =>
507 string engineIdString = Marshal.PtrToStringAnsi(engineId);
508 string languageString = Marshal.PtrToStringAnsi(language);
509 EngineChangedEventArgs args = new EngineChangedEventArgs(engineIdString, languageString, supportSilence, needCredential);
510 _engineChanged?.Invoke(this, args);
512 SttError error = SttSetEngineChangedCB(_handle, _engineDelegate, IntPtr.Zero);
513 if (error != SttError.None)
515 Log.Error(LogTag, "Add EngineChanged Failed with error " + error);
519 _engineChanged += value;
528 SttError error = SttUnsetEngineChangedCB(_handle);
529 if (error != SttError.None)
531 Log.Error(LogTag, "Remove EngineChanged Failed with error " + error);
534 _engineChanged -= value;
540 /// Gets the default language set by the user.
541 /// 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.
542 /// For example, "ko_KR" for Korean, "en_US" for American English.
545 /// Default language in STT.
548 /// http://tizen.org/privilege/recorder
551 /// Default Lanaguage string value.
553 public string GetDefaultLanguage
560 SttError error = SttGetDefaultLanguage(_handle, out language);
561 if (error != SttError.None)
563 Log.Error(LogTag, "DefaultLanaguage Failed with error " + error);
573 /// Gets the microphone volume during recording.
576 /// Recording volume in STT.
579 /// http://tizen.org/privilege/recorder
582 /// The State must be Recording.
584 public float GetRecordingVolume
591 SttError error = SttGetRecordingVolume(_handle, out volume);
592 if (error != SttError.None)
594 Log.Error(LogTag, "GetRecordingVolume Failed with error " + error);
606 /// Gets the current STT state.
609 /// Current state of STT.
612 /// http://tizen.org/privilege/recorder
615 /// Current STT State value.
617 public State GetState
624 SttError error = SttGetState(_handle, out state);
625 if (error != SttError.None)
627 Log.Error(LogTag, "GetState Failed with error " + error);
628 return State.Unavailable;
638 /// This property can be used to get and set the current engine id.
641 /// Current STT engine id.
644 /// http://tizen.org/privilege/recorder
646 /// <exception cref="InvalidOperationException">
647 /// This Exception can occur while setting due to the following reaons
649 /// 2. Operation Failed
650 /// 3. STT Not Supported
651 /// 4. Permission Denied
654 /// <exception cref="ArgumentException">
655 /// This can happen if Improper EngineId is provided while setting the value.
658 /// The State must be Created.
667 SttError error = SttGetEngine(_handle, out engineId);
668 if (error != SttError.None)
670 Log.Error(LogTag, "Get EngineId Failed with error " + error);
681 SttError error = SttSetEngine(_handle, value);
682 if (error != SttError.None)
684 Log.Error(LogTag, "Set EngineId Failed with error " + error);
685 throw ExceptionFactory.CreateException(error);
693 /// Retrieves the time stamp of the current recognition result
696 /// list of ResultTime
699 /// http://tizen.org/privilege/recorder
702 /// http://tizen.org/feature/speech.recognition
703 /// http://tizen.org/feature/microphone
706 /// This function should only be called in RecognitionResult Event
708 /// <exception cref="InvalidOperationException">
709 /// This Exception can be due to the following reaons
710 /// 1. Opearation Failed.
711 /// 2. STT Not Supported
712 /// 3. Permission Denied.
714 public IEnumerable<ResultTime> GetDetailedResult()
716 List<ResultTime> list = new List<ResultTime>();
717 _resultTimeDelegate = (IntPtr handle, int index, TimeEvent e, IntPtr text, IntPtr startTime, IntPtr endTime, IntPtr userData) =>
719 _result = new ResultTime(index, e, Marshal.PtrToStringAnsi(text), (long)startTime, (long)endTime);
723 SttError error = SttForeachDetailedResult(_handle, _resultTimeDelegate, IntPtr.Zero);
724 if (error != SttError.None)
726 Log.Error(LogTag, "GetDetailedResult Failed with error " + error);
727 throw ExceptionFactory.CreateException(error);
734 /// Gets the private data from stt engine.
736 /// <param name="key">
740 /// The Data Corresponding to the Key provided
743 /// http://tizen.org/privilege/recorder
746 /// http://tizen.org/feature/speech.recognition
747 /// http://tizen.org/feature/microphone
749 /// <exception cref="InvalidOperationException">
750 /// This Exception can be due to the following reaons
751 /// 1. No Answer from STT Service
752 /// 2. STT Not Supported
756 /// The State must be Ready.
758 public string GetPrivateData(string key)
763 SttError error = SttGetPrivateData(_handle, key, out data);
764 if (error != SttError.None)
766 Log.Error(LogTag, "GetPrivateData Failed with error " + error);
767 throw ExceptionFactory.CreateException(error);
775 /// Sets the private data to stt engine.
777 /// <param name="key">
780 /// <param name="data">
784 /// http://tizen.org/privilege/recorder
787 /// http://tizen.org/feature/speech.recognition
788 /// http://tizen.org/feature/microphone
790 /// <exception cref="InvalidOperationException">
791 /// This Exception can be due to the following reaons
792 /// 1. No Answer from STT Service
793 /// 2. STT Not Supported
796 /// <exception cref="ArgumentException">
797 /// This can happen if Improper value is provided while setting the value.
800 /// The State must be Ready.
802 public void SetPrivateData(string key, string data)
806 SttError error = SttSetPrivateData(_handle, key, data);
807 if (error != SttError.None)
809 Log.Error(LogTag, "SetPrivateData Failed with error " + error);
810 throw ExceptionFactory.CreateException(error);
816 /// Gets the list of Supported Engine
819 /// IEnumerable<SupportedEngine> list of supported engines
822 /// http://tizen.org/privilege/recorder
825 /// http://tizen.org/feature/speech.recognition
826 /// http://tizen.org/feature/microphone
828 /// <exception cref="InvalidOperationException">
829 /// This Exception can be due to the following reaons
831 /// 2. Operation Failed
832 /// 3. STT Not Supported
833 /// 4. Permission Denied
835 public IEnumerable<SupportedEngine> GetSupportedEngines()
837 List<SupportedEngine> engineList = new List<SupportedEngine>();
840 SupportedEngineCallback supportedEngineDelegate = (IntPtr handle, IntPtr engineId, IntPtr engineName, IntPtr userData) =>
842 string id = Marshal.PtrToStringAnsi(engineId);
843 string name = Marshal.PtrToStringAnsi(engineName);
844 SupportedEngine engine = new SupportedEngine(id, name);
845 engineList.Add(engine);
848 SttError error = SttForeEachSupportedEngines(_handle, supportedEngineDelegate, IntPtr.Zero);
849 if (error != SttError.None)
851 Log.Error(LogTag, "Create Failed with error " + error);
852 throw ExceptionFactory.CreateException(error);
860 /// Sets the app credential
862 /// <param name="credential">
863 /// The credential string
866 /// http://tizen.org/privilege/recorder
869 /// http://tizen.org/feature/speech.recognition
870 /// http://tizen.org/feature/microphone
872 /// <exception cref="InvalidOperationException">
873 /// This Exception can be due to the following reaons
875 /// 2. Operation Failed
876 /// 3. STT Not Supported
877 /// 4. Permission Denied
880 /// <exception cref="ArgumentException">
881 /// This can happen if Improper value is provided while setting the value.
884 /// The State must be Created.
886 public void SetCredential(string credential)
890 SttError error = SttSetcredential(_handle, credential);
891 if (error != SttError.None)
893 Log.Error(LogTag, "SetCredential Failed with error " + error);
894 throw ExceptionFactory.CreateException(error);
900 /// Connects to the STT service asynchronously.
903 /// http://tizen.org/privilege/recorder
906 /// http://tizen.org/feature/speech.recognition
907 /// http://tizen.org/feature/microphone
909 /// <exception cref="InvalidOperationException">
910 /// This Exception can be due to the following reasons
911 /// 1. STT Not Supported
912 /// 2. Permission Denied
916 /// The State must be Created.
919 /// If this function is successful, the STT state will be Ready
920 /// If this function is unsuccessful, ErrorOccured event will be invoked
922 public void Prepare()
926 SttError error = SttPrepare(_handle);
927 if (error != SttError.None)
929 Log.Error(LogTag, "SetEngine Failed with error " + error);
930 throw ExceptionFactory.CreateException(error);
936 /// Disconnects from the STT service.
939 /// http://tizen.org/privilege/recorder
942 /// http://tizen.org/feature/speech.recognition
943 /// http://tizen.org/feature/microphone
945 /// <exception cref="InvalidOperationException">
946 /// This Exception can be due to the following reasons
947 /// 1. STT Not Supported
948 /// 2. Permission Denied
952 /// The State must be Ready.
955 /// If this function is successful, the STT state will be Created
957 public void Unprepare()
961 SttError error = SttUnprepare(_handle);
962 if (error != SttError.None)
964 Log.Error(LogTag, "Unprepare Failed with error " + error);
965 throw ExceptionFactory.CreateException(error);
971 /// Retrieves all supported languages of current engine.
972 /// 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.
973 /// For example, "ko_KR" for Korean, "en_US" for American English.
976 /// http://tizen.org/privilege/recorder
979 /// list of strings of supported languages.
982 /// http://tizen.org/feature/speech.recognition
983 /// http://tizen.org/feature/microphone
985 /// <exception cref="InvalidOperationException">
986 /// This Exception can be due to the following reasons
987 /// 1. STT Not Supported
988 /// 2. Permission Denied
989 /// 3. Engine Not Found.
990 /// 4. Operation Failed.
992 public IEnumerable<string> GetSupportedLangauages()
994 List<string> languageList = new List<string>();
997 SupportedLanguageCallback supportedLanguageDelegate = (IntPtr handle, IntPtr language, IntPtr userData) =>
999 string lang = Marshal.PtrToStringAnsi(language);
1000 languageList.Add(lang);
1004 SttError error = SttForeachSupportedLanguages(_handle, supportedLanguageDelegate, IntPtr.Zero);
1005 if (error != SttError.None)
1007 Log.Error(LogTag, "GetSupportedLangauages Failed with error " + error);
1008 throw ExceptionFactory.CreateException(error);
1012 return languageList;
1016 /// Checks whether the recognition type is supported.
1019 /// http://tizen.org/privilege/recorder
1021 /// <param name="type">
1022 /// RecognitionType value.
1025 /// bool value indicating whether the recognition type is supported.
1028 /// http://tizen.org/feature/speech.recognition
1029 /// http://tizen.org/feature/microphone
1031 /// <exception cref="InvalidOperationException">
1032 /// This Exception can be due to the following reasons
1033 /// 1. STT Not Supported
1034 /// 2. Invalid State
1035 /// 3. Engine Not Found.
1036 /// 4. Operation Failed.
1039 /// The state should be Ready.
1041 public bool IsRecognitionTypeSupported(RecognitionType type)
1046 string recType = "stt.recognition.type.FREE";
1049 case RecognitionType.Free:
1051 recType = "stt.recognition.type.FREE";
1055 case RecognitionType.Partial:
1057 recType = "stt.recognition.type.FREE.PARTIAL";
1061 case RecognitionType.Search:
1063 recType = "stt.recognition.type.SEARCH";
1067 case RecognitionType.WebSearch:
1069 recType = "stt.recognition.type.WEB_SEARCH";
1073 case RecognitionType.Map:
1075 recType = "stt.recognition.type.MAP";
1081 SttError error = SttIsRecognitionTypeSupported(_handle, recType, out supported);
1082 if (error != SttError.None)
1084 Log.Error(LogTag, "IsRecognitionTypeSupported Failed with error " + error);
1085 throw ExceptionFactory.CreateException(error);
1094 /// Sets the silence detection.
1097 /// http://tizen.org/privilege/recorder
1099 /// <param name="type">
1100 /// SilenceDetection value.
1103 /// http://tizen.org/feature/speech.recognition
1104 /// http://tizen.org/feature/microphone
1106 /// <exception cref="InvalidOperationException">
1107 /// This Exception can be due to the following reasons
1108 /// 1. STT Not Supported
1109 /// 2. Invalid State
1110 /// 3. Not supported feature of current engine.
1111 /// 4. Operation Failed.
1114 /// The state should be Ready.
1116 public void SetSilenceDetection(SilenceDetection type)
1120 SttError error = SttSetSilenceDetection(_handle, type);
1121 if (error != SttError.None)
1123 Log.Error(LogTag, "SetSilenceDetection Failed with error " + error);
1124 throw ExceptionFactory.CreateException(error);
1130 /// Sets the sound to start recording.
1131 /// Sound file type should be wav type.
1134 /// http://tizen.org/privilege/recorder
1136 /// <param name="filePath">
1137 /// File Path for the sound.
1140 /// http://tizen.org/feature/speech.recognition
1141 /// http://tizen.org/feature/microphone
1143 /// <exception cref="InvalidOperationException">
1144 /// This Exception can be due to the following reasons
1145 /// 1. STT Not Supported.
1146 /// 2. Permission Denied.
1147 /// 3. Invalid State.
1148 /// 4. Operation Failed.
1150 /// <exception cref="ArgumentException">
1151 /// If an Invalid Parameter is provided.
1154 /// The state should be Ready.
1156 public void SetStartSound(string filePath)
1160 SttError error = SttSetStartSound(_handle, filePath);
1161 if (error != SttError.None)
1163 Log.Error(LogTag, "SetStartSound Failed with error " + error);
1164 throw ExceptionFactory.CreateException(error);
1170 /// Unsets the sound to start recording.
1173 /// http://tizen.org/privilege/recorder
1176 /// http://tizen.org/feature/speech.recognition
1177 /// http://tizen.org/feature/microphone
1179 /// <exception cref="InvalidOperationException">
1180 /// This Exception can be due to the following reasons
1181 /// 1. STT Not Supported.
1182 /// 2. Permission Denied.
1183 /// 3. Invalid State.
1184 /// 4. Operation Failed.
1187 /// The state should be Ready.
1189 public void UnsetStartSound()
1193 SttError error = SttUnsetStartSound(_handle);
1194 if (error != SttError.None)
1196 Log.Error(LogTag, "UnsetStartSound Failed with error " + error);
1197 throw ExceptionFactory.CreateException(error);
1203 /// Sets the sound to stop recording.
1204 /// Sound file type should be wav type.
1207 /// http://tizen.org/privilege/recorder
1209 /// <param name="filePath">
1210 /// File Path for the sound.
1213 /// http://tizen.org/feature/speech.recognition
1214 /// http://tizen.org/feature/microphone
1216 /// <exception cref="InvalidOperationException">
1217 /// This Exception can be due to the following reasons
1218 /// 1. STT Not Supported.
1219 /// 2. Permission Denied.
1220 /// 3. Invalid State.
1221 /// 4. Operation Failed.
1223 /// <exception cref="ArgumentException">
1224 /// If an Invalid Parameter is provided.
1227 /// The state should be Ready.
1229 public void SetStopSound(string filePath)
1233 SttError error = SttSetStopSound(_handle, filePath);
1234 if (error != SttError.None)
1236 Log.Error(LogTag, "SetStopSound Failed with error " + error);
1237 throw ExceptionFactory.CreateException(error);
1243 /// Unsets the sound to stop recording.
1246 /// http://tizen.org/privilege/recorder
1249 /// http://tizen.org/feature/speech.recognition
1250 /// http://tizen.org/feature/microphone
1252 /// <exception cref="InvalidOperationException">
1253 /// This Exception can be due to the following reasons
1254 /// 1. STT Not Supported.
1255 /// 2. Permission Denied.
1256 /// 3. Invalid State.
1257 /// 4. Operation Failed.
1260 /// The state should be Ready.
1262 public void UnsetStopSound()
1266 SttError error = SttUnsetStopSound(_handle);
1267 if (error != SttError.None)
1269 Log.Error(LogTag, "UnsetStopSound Failed with error " + error);
1270 throw ExceptionFactory.CreateException(error);
1276 /// Starts recording and recognition asynchronously.
1277 /// This function starts recording in the STT service and sending recording data to engine.
1278 /// This work continues until Stop, Cancel or silence detected by engine
1281 /// http://tizen.org/privilege/recorder
1283 /// <param name="language">
1284 /// The language selected
1286 /// <param name="type">
1287 /// The type for recognition
1290 /// http://tizen.org/feature/speech.recognition
1291 /// http://tizen.org/feature/microphone
1293 /// <exception cref="InvalidOperationException">
1294 /// This Exception can be due to the following reasons
1295 /// 1. STT Not Supported.
1296 /// 2. Permission Denied.
1297 /// 3. Invalid State.
1298 /// 4. Operation Failed.
1299 /// 5. Recorder Busy.
1300 /// 6. Progress to recording is not finished
1302 /// <exception cref="ArgumentException">
1303 /// If an Invalid Language is provided
1306 /// The state should be Ready.
1309 /// It will invoke StateChanged Event if registerd.
1310 /// If this function succeeds, the STT state will be Recording.
1311 /// If you call this function again before state changes, you will receive ErrorINProgressToRecording.
1313 public void Start(string language, RecognitionType type)
1317 string recType = "stt.recognition.type.FREE";
1320 case RecognitionType.Free:
1322 recType = "stt.recognition.type.FREE";
1326 case RecognitionType.Partial:
1328 recType = "stt.recognition.type.FREE.PARTIAL";
1332 case RecognitionType.Search:
1334 recType = "stt.recognition.type.SEARCH";
1338 case RecognitionType.WebSearch:
1340 recType = "stt.recognition.type.WEB_SEARCH";
1344 case RecognitionType.Map:
1346 recType = "stt.recognition.type.MAP";
1352 SttError error = SttStart(_handle, language, recType);
1353 if (error != SttError.None)
1355 Log.Error(LogTag, "Start Failed with error " + error);
1356 throw ExceptionFactory.CreateException(error);
1362 /// Finishes the recording and starts recognition processing in engine asynchronously.
1365 /// http://tizen.org/privilege/recorder
1368 /// http://tizen.org/feature/speech.recognition
1369 /// http://tizen.org/feature/microphone
1371 /// <exception cref="InvalidOperationException">
1372 /// This Exception can be due to the following reasons
1373 /// 1. STT Not Supported.
1374 /// 2. Permission Denied.
1375 /// 3. Invalid State.
1376 /// 4. Operation Failed.
1377 /// 5. Progress to ready is not finished.
1378 /// 6. Progress to recording is not finished.
1379 /// 7. Progress to processing is not finished.
1382 /// The state should be Recording.
1385 /// It will invoke StateChanged Event if registerd.
1386 /// If this function succeeds, the STT state will be Processing.
1387 /// If you call this function again before state changes, you will receive ErrorINProgressToProcessing.
1388 /// After processing of engine, RecognitionResult event is invoked
1394 SttError error = SttStop(_handle);
1395 if (error != SttError.None)
1397 Log.Error(LogTag, "Stop Failed with error " + error);
1398 throw ExceptionFactory.CreateException(error);
1404 /// Cancels processing recognition and recording asynchronously.
1405 /// This function cancels recording and engine cancels recognition processing.
1406 /// After successful cancel, StateChanged event is invoked otherwise if error is occurred, ErrorOccured event is invoked.
1409 /// http://tizen.org/privilege/recorder
1412 /// http://tizen.org/feature/speech.recognition
1413 /// http://tizen.org/feature/microphone
1415 /// <exception cref="InvalidOperationException">
1416 /// This Exception can be due to the following reasons
1417 /// 1. STT Not Supported.
1418 /// 2. Permission Denied.
1419 /// 3. Invalid State.
1420 /// 4. Operation Failed.
1421 /// 5. Progress to ready is not finished.
1422 /// 6. Progress to recording is not finished.
1423 /// 7. Progress to processing is not finished.
1426 /// The state should be Recording or Processing.
1429 /// It will invoke StateChanged Event if registerd.
1430 /// If this function succeeds, the STT state will be Ready.
1431 /// If you call this function again before state changes, you will receive ErrorINProgressToReady.
1433 public void Cancel()
1437 SttError error = SttCancel(_handle);
1438 if (error != SttError.None)
1440 Log.Error(LogTag, "Cancel Failed with error " + error);
1441 throw ExceptionFactory.CreateException(error);
1447 /// Method to release resources
1449 public void Dispose()
1454 protected virtual void Dispose(bool disposing)
1460 SttError error = SttDestroy(_handle);
1461 if (error != SttError.None)
1463 Log.Error(LogTag, "Destroy Failed with error " + error);
1467 disposedValue = true;