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 for full or last result is ready.
34 /// <since_tizen> 3 </since_tizen>
37 /// Event when the recognition for 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 for 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 types.
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 /// Enumeration for the 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>
171 /// Invalid language.
173 /// <since_tizen> 3 </since_tizen>
176 /// No available engine.
178 /// <since_tizen> 3 </since_tizen>
181 /// Operation failed.
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 the 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>
277 /// Processing state.
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, the applications will start recording and recognizing.
314 /// After recording, the applications will receive the recognized result.
315 /// The STT has a client-server for the service of multi-applications.
316 /// The STT service always works in the background as a server. If the service is not working, client library will invoke it and the client will communicate with it.
317 /// The service has engines and a recorder, so that the client does not have the recorder itself. Only the client request commands to the STT service for using STT.
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<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;
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 /// Destructor to destroy a STT instance.
375 /// Event to be invoked when the recognition is done.
377 /// <since_tizen> 3 </since_tizen>
378 public event EventHandler<RecognitionResultEventArgs> RecognitionResult
384 if (_recognitionResult == null)
386 _resultDelegate = (IntPtr handle, ResultEvent e, IntPtr data, int dataCount, IntPtr msg, IntPtr userData) =>
388 Log.Info(LogTag, "Recognition Result Event Triggered");
389 if (data != null && msg != null)
391 RecognitionResultEventArgs args = new RecognitionResultEventArgs(e, data, dataCount, Marshal.PtrToStringAnsi(msg));
392 _recognitionResult?.Invoke(this, args);
396 Log.Info(LogTag, "Recognition Result Event null received");
400 SttError error = SttSetRecognitionResultCB(_handle, _resultDelegate, IntPtr.Zero);
401 if (error != SttError.None)
403 Log.Error(LogTag, "Add RecognitionResult Failed with error " + error);
406 _recognitionResult += value;
414 _recognitionResult -= value;
415 if (_recognitionResult == null)
417 SttError error = SttUnsetRecognitionResultCB(_handle);
418 if (error != SttError.None)
420 Log.Error(LogTag, "Remove RecognitionResult Failed with error " + error);
428 /// Event to be invoked when the STT state changes.
430 /// <since_tizen> 3 </since_tizen>
431 public event EventHandler<StateChangedEventArgs> StateChanged
437 if (_stateChanged == null)
439 SttClient obj = this;
440 _stateDelegate = (IntPtr handle, State previous, State current, IntPtr userData) =>
442 StateChangedEventArgs args = new StateChangedEventArgs(previous, current);
443 _stateChanged?.Invoke(obj, args);
446 SttError error = SttSetStateChangedCB(_handle, _stateDelegate, IntPtr.Zero);
447 if (error != SttError.None)
449 Log.Error(LogTag, "Add StateChanged Failed with error " + error);
452 _stateChanged += value;
460 _stateChanged -= value;
461 if (_stateChanged == null)
463 SttError error = SttUnsetStateChangedCB(_handle);
464 if (error != SttError.None)
466 Log.Error(LogTag, "Remove StateChanged Failed with error " + error);
475 /// Event to be invoked when an error occurs.
477 /// <since_tizen> 4 </since_tizen>
478 public event EventHandler<ErrorOccurredEventArgs> ErrorOccurred
484 if (_errorOccurred == null)
486 _errorDelegate = (IntPtr handle, SttError reason, IntPtr userData) =>
488 ErrorOccurredEventArgs args = new ErrorOccurredEventArgs(handle, reason);
489 _errorOccurred?.Invoke(this, args);
492 SttError error = SttSetErrorCB(_handle, _errorDelegate, IntPtr.Zero);
493 if (error != SttError.None)
495 Log.Error(LogTag, "Add ErrorOccurred Failed with error " + error);
498 _errorOccurred += value;
506 _errorOccurred -= value;
507 if (_errorOccurred == null)
509 SttError error = SttUnsetErrorCB(_handle);
510 if (error != SttError.None)
512 Log.Error(LogTag, "Remove ErrorOccurred Failed with error " + error);
520 /// Event to be invoked when the default language changes.
522 /// <since_tizen> 3 </since_tizen>
523 public event EventHandler<DefaultLanguageChangedEventArgs> DefaultLanguageChanged
529 if (_defaultLanguageChanged == null)
531 _languageDelegate = (IntPtr handle, IntPtr previousLanguage, IntPtr currentLanguage, IntPtr userData) =>
533 string previousLanguageString = Marshal.PtrToStringAnsi(previousLanguage);
534 string currentLanguageString = Marshal.PtrToStringAnsi(currentLanguage);
535 DefaultLanguageChangedEventArgs args = new DefaultLanguageChangedEventArgs(previousLanguageString, currentLanguageString);
536 _defaultLanguageChanged?.Invoke(this, args);
539 SttError error = SttSetDefaultLanguageChangedCB(_handle, _languageDelegate, IntPtr.Zero);
540 if (error != SttError.None)
542 Log.Error(LogTag, "Add DefaultLanguageChanged Failed with error " + error);
545 _defaultLanguageChanged += value;
553 _defaultLanguageChanged -= value;
554 if (_defaultLanguageChanged == null)
556 SttError error = SttUnsetDefaultLanguageChangedCB(_handle);
557 if (error != SttError.None)
559 Log.Error(LogTag, "Remove DefaultLanguageChanged Failed with error " + error);
568 /// Event to be invoked to detect the engine change.
570 /// <since_tizen> 3 </since_tizen>
571 public event EventHandler<EngineChangedEventArgs> EngineChanged
577 if (_engineChanged == null)
579 _engineDelegate = (IntPtr handle, IntPtr engineId, IntPtr language, bool supportSilence, bool needCredential, IntPtr userData) =>
581 string engineIdString = Marshal.PtrToStringAnsi(engineId);
582 string languageString = Marshal.PtrToStringAnsi(language);
583 EngineChangedEventArgs args = new EngineChangedEventArgs(engineIdString, languageString, supportSilence, needCredential);
584 _engineChanged?.Invoke(this, args);
587 SttError error = SttSetEngineChangedCB(_handle, _engineDelegate, IntPtr.Zero);
588 if (error != SttError.None)
590 Log.Error(LogTag, "Add EngineChanged Failed with error " + error);
593 _engineChanged += value;
601 _engineChanged -= value;
602 if (_engineChanged == null)
604 SttError error = SttUnsetEngineChangedCB(_handle);
605 if (error != SttError.None)
607 Log.Error(LogTag, "Remove EngineChanged Failed with error " + error);
615 /// Gets the default language set by the user.
616 /// The language is specified as an ISO 3166 alpha-2 two letter country-code followed by ISO 639-1 for the two-letter language code.
617 /// For example, "ko_KR" for Korean, "en_US" for American English.
619 /// <since_tizen> 3 </since_tizen>
621 /// Default language in STT.
624 /// http://tizen.org/privilege/recorder
627 /// Default Language string value.
629 public string DefaultLanguage
636 SttError error = SttGetDefaultLanguage(_handle, out language);
637 if (error != SttError.None)
639 Log.Error(LogTag, "DefaultLanguage Failed with error " + error);
649 /// Gets the microphone volume during recording.
651 /// <since_tizen> 3 </since_tizen>
653 /// Recording volume in STT.
656 /// http://tizen.org/privilege/recorder
659 /// The state must be recording.
661 public float RecordingVolume
668 SttError error = SttGetRecordingVolume(_handle, out volume);
669 if (error != SttError.None)
671 Log.Error(LogTag, "GetRecordingVolume Failed with error " + error);
682 /// Gets the current STT state.
684 /// <since_tizen> 3 </since_tizen>
686 /// Current state of STT.
689 /// http://tizen.org/privilege/recorder
692 /// Current STT state value.
694 public State CurrentState
701 SttError error = SttGetState(_handle, out state);
702 if (error != SttError.None)
704 Log.Error(LogTag, "GetState Failed with error " + error);
705 return State.Unavailable;
715 /// This property can be used to get and set the current engine id.
717 /// <since_tizen> 3 </since_tizen>
719 /// Current STT engine id.
722 /// http://tizen.org/privilege/recorder
724 /// <exception cref="InvalidOperationException">
725 /// This exceptioncan occur while setting due to the following reasons:
726 /// 1. Operation Failed
729 /// <exception cref="OutOfMemoryException">This exception can be due to out of memory.</exception>
730 /// <exception cref="NotSupportedException">This exception can be due to STT not supported.</exception>
731 /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception>
732 /// <exception cref="ArgumentException">This can happen if improper EngineId is provided while setting the value.</exception>
734 /// The state must be created.
743 SttError error = SttGetEngine(_handle, out engineId);
744 if (error != SttError.None)
746 Log.Error(LogTag, "Get EngineId Failed with error " + error);
757 SttError error = SttSetEngine(_handle, value);
758 if (error != SttError.None)
760 Log.Error(LogTag, "Set EngineId Failed with error " + error);
761 throw ExceptionFactory.CreateException(error);
769 /// Retrieves the time stamp of the current recognition result.
771 /// <since_tizen> 3 </since_tizen>
773 /// List of ResultTime.
776 /// http://tizen.org/privilege/recorder
779 /// http://tizen.org/feature/speech.recognition
780 /// http://tizen.org/feature/microphone
783 /// This function should only be called in the RecognitionResult event.
785 /// <exception cref="InvalidOperationException">This exception can be due to operation failed.</exception>
786 /// <exception cref="NotSupportedException">This exception can be due to STT not supported.</exception>
787 /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception>
788 public IEnumerable<ResultTime> GetDetailedResult()
790 List<ResultTime> list = new List<ResultTime>();
793 _resultTimeDelegate = (IntPtr handle, int index, TimeEvent e, IntPtr text, IntPtr startTime, IntPtr endTime, IntPtr userData) =>
795 _result = new ResultTime(index, e, Marshal.PtrToStringAnsi(text), (long)startTime, (long)endTime);
799 SttError error = SttForeachDetailedResult(_handle, _resultTimeDelegate, IntPtr.Zero);
800 if (error != SttError.None)
802 Log.Error(LogTag, "GetDetailedResult Failed with error " + error);
803 throw ExceptionFactory.CreateException(error);
811 /// Gets the private data from the STT engine.
813 /// <since_tizen> 3 </since_tizen>
814 /// <param name="key">
818 /// The data corresponding to the key is provided.
821 /// http://tizen.org/privilege/recorder
824 /// http://tizen.org/feature/speech.recognition
825 /// http://tizen.org/feature/microphone
827 /// <exception cref="InvalidOperationException">This exception can be due to invalid state.</exception>
828 /// <exception cref="NotSupportedException">This exception can be due to STT not supported.</exception>
829 /// <exception cref="TimeoutException">This exception can be due to No Answer from STT Service.</exception>
831 /// The state must be ready.
833 public string GetPrivateData(string key)
838 SttError error = SttGetPrivateData(_handle, key, out data);
839 if (error != SttError.None)
841 Log.Error(LogTag, "GetPrivateData Failed with error " + error);
842 throw ExceptionFactory.CreateException(error);
850 /// Sets the private data to the STT engine.
852 /// <since_tizen> 3 </since_tizen>
853 /// <param name="key">
856 /// <param name="data">
860 /// http://tizen.org/privilege/recorder
863 /// http://tizen.org/feature/speech.recognition
864 /// http://tizen.org/feature/microphone
866 /// <exception cref="InvalidOperationException">This exception can be due to invalid state.</exception>
867 /// <exception cref="NotSupportedException">This exception can be due to STT not supported.</exception>
868 /// <exception cref="TimeoutException">This exception can be due to No Answer from STT Service.</exception>
869 /// <exception cref="ArgumentException"> This can happen if Improper value is provided while setting the value. </exception>
871 /// The state must be ready.
873 public void SetPrivateData(string key, string data)
877 SttError error = SttSetPrivateData(_handle, key, data);
878 if (error != SttError.None)
880 Log.Error(LogTag, "SetPrivateData Failed with error " + error);
881 throw ExceptionFactory.CreateException(error);
887 /// Gets the list of supported engines.
889 /// <since_tizen> 3 </since_tizen>
891 /// IEnumerable<SupportedEngine> list of supported engines.
894 /// http://tizen.org/privilege/recorder
897 /// http://tizen.org/feature/speech.recognition
898 /// http://tizen.org/feature/microphone
900 /// <exception cref="InvalidOperationException">This exception can be due to operation failed.</exception>
901 /// <exception cref="OutOfMemoryException">This exception can be due to out of memory.</exception>
902 /// <exception cref="NotSupportedException">This exception can be due to STT not supported.</exception>
903 /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception>
904 public IEnumerable<SupportedEngine> GetSupportedEngines()
906 List<SupportedEngine> engineList = new List<SupportedEngine>();
909 SupportedEngineCallback supportedEngineDelegate = (IntPtr handle, IntPtr engineId, IntPtr engineName, IntPtr userData) =>
911 string id = Marshal.PtrToStringAnsi(engineId);
912 string name = Marshal.PtrToStringAnsi(engineName);
913 SupportedEngine engine = new SupportedEngine(id, name);
914 engineList.Add(engine);
917 SttError error = SttForeEachSupportedEngines(_handle, supportedEngineDelegate, IntPtr.Zero);
918 if (error != SttError.None)
920 Log.Error(LogTag, "Create Failed with error " + error);
921 throw ExceptionFactory.CreateException(error);
929 /// Sets the application credential.
931 /// <since_tizen> 3 </since_tizen>
932 /// <param name="credential">
933 /// The credential string.
936 /// http://tizen.org/privilege/recorder
939 /// http://tizen.org/feature/speech.recognition
940 /// http://tizen.org/feature/microphone
942 /// <exception cref="InvalidOperationException">
943 /// This exceptioncan be due to the following reasons:
944 /// 1. Operation Failed
947 /// <exception cref="OutOfMemoryException">This exception can be due to out of memory.</exception>
948 /// <exception cref="NotSupportedException">This exception can be due to STT not supported.</exception>
949 /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception>
950 /// <exception cref="ArgumentException"> This can happen if Improper value is provided while setting the value. </exception>
952 /// The state must be created.
954 public void SetCredential(string credential)
958 SttError error = SttSetcredential(_handle, credential);
959 if (error != SttError.None)
961 Log.Error(LogTag, "SetCredential Failed with error " + error);
962 throw ExceptionFactory.CreateException(error);
968 /// Connects to the STT service asynchronously.
970 /// <since_tizen> 3 </since_tizen>
972 /// http://tizen.org/privilege/recorder
975 /// http://tizen.org/feature/speech.recognition
976 /// http://tizen.org/feature/microphone
978 /// <exception cref="InvalidOperationException">This exception can be due to invalid state.</exception>
979 /// <exception cref="NotSupportedException">This exception can be due to STT not supported.</exception>
980 /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception>
982 /// The state must be created.
985 /// If this function is successful, the STT state will be ready.
986 /// If this function is unsuccessful, ErrorOccurred event will be invoked.
988 public void Prepare()
992 SttError error = SttPrepare(_handle);
993 if (error != SttError.None)
995 Log.Error(LogTag, "SetEngine Failed with error " + error);
996 throw ExceptionFactory.CreateException(error);
1002 /// Disconnects from the STT service.
1004 /// <since_tizen> 3 </since_tizen>
1006 /// http://tizen.org/privilege/recorder
1009 /// http://tizen.org/feature/speech.recognition
1010 /// http://tizen.org/feature/microphone
1012 /// <exception cref="InvalidOperationException">This exception can be due to invalid state.</exception>
1013 /// <exception cref="NotSupportedException">This exception can be due to STT not supported.</exception>
1014 /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception>
1016 /// The state must be ready.
1019 /// If this function is successful, the STT state will be Created.
1021 public void Unprepare()
1025 SttError error = SttUnprepare(_handle);
1026 if (error != SttError.None)
1028 Log.Error(LogTag, "Unprepare Failed with error " + error);
1029 throw ExceptionFactory.CreateException(error);
1035 /// Retrieves all the supported languages of the current engine.
1036 /// The language is specified as an ISO 3166 alpha-2 two letter country-code followed by ISO 639-1 for the two-letter language code.
1037 /// For example, "ko_KR" for Korean, "en_US" for American English.
1039 /// <since_tizen> 4 </since_tizen>
1041 /// http://tizen.org/privilege/recorder
1044 /// List of strings for supported languages.
1047 /// http://tizen.org/feature/speech.recognition
1048 /// http://tizen.org/feature/microphone
1050 /// <exception cref="InvalidOperationException">
1051 /// This exception can be due to the following reasons:
1052 /// 1. Engine Not Found.
1053 /// 2. Operation Failed.
1055 /// <exception cref="NotSupportedException">This exception can be due to STT not supported.</exception>
1056 /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception>
1057 public IEnumerable<string> GetSupportedLanguages()
1059 List<string> languageList = new List<string>();
1062 SupportedLanguageCallback supportedLanguageDelegate = (IntPtr handle, IntPtr language, IntPtr userData) =>
1064 string lang = Marshal.PtrToStringAnsi(language);
1065 languageList.Add(lang);
1069 SttError error = SttForeachSupportedLanguages(_handle, supportedLanguageDelegate, IntPtr.Zero);
1070 if (error != SttError.None)
1072 Log.Error(LogTag, "GetSupportedLanguages Failed with error " + error);
1073 throw ExceptionFactory.CreateException(error);
1077 return languageList;
1081 /// Checks whether the recognition type is supported.
1083 /// <since_tizen> 3 </since_tizen>
1085 /// http://tizen.org/privilege/recorder
1087 /// <param name="type">
1088 /// RecognitionType value.
1091 /// Bool value indicating whether the recognition type is supported.
1094 /// http://tizen.org/feature/speech.recognition
1095 /// http://tizen.org/feature/microphone
1097 /// <exception cref="InvalidOperationException">
1098 /// This exception can be due to the following reasons:
1099 /// 1. Invalid State
1100 /// 2. Engine Not Found
1101 /// 3. Operation Failed
1103 /// <exception cref="NotSupportedException">This exception can be due to STT not supported.</exception>
1105 /// The state should be ready.
1107 public bool IsRecognitionTypeSupported(RecognitionType type)
1112 string recType = "stt.recognition.type.FREE";
1115 case RecognitionType.Free:
1117 recType = "stt.recognition.type.FREE";
1121 case RecognitionType.Partial:
1123 recType = "stt.recognition.type.FREE.PARTIAL";
1127 case RecognitionType.Search:
1129 recType = "stt.recognition.type.SEARCH";
1133 case RecognitionType.WebSearch:
1135 recType = "stt.recognition.type.WEB_SEARCH";
1139 case RecognitionType.Map:
1141 recType = "stt.recognition.type.MAP";
1146 SttError error = SttIsRecognitionTypeSupported(_handle, recType, out supported);
1147 if (error != SttError.None)
1149 Log.Error(LogTag, "IsRecognitionTypeSupported Failed with error " + error);
1150 throw ExceptionFactory.CreateException(error);
1158 /// Sets the silence detection.
1160 /// <since_tizen> 3 </since_tizen>
1162 /// http://tizen.org/privilege/recorder
1164 /// <param name="type">
1165 /// SilenceDetection value.
1168 /// http://tizen.org/feature/speech.recognition
1169 /// http://tizen.org/feature/microphone
1171 /// <exception cref="InvalidOperationException">
1172 /// This exception can be due to the following reasons:
1173 /// 1. Invalid State
1174 /// 2. Not supported feature of current engine
1175 /// 3. Operation Failed
1177 /// <exception cref="NotSupportedException">This exception can be due to STT not supported.</exception>
1179 /// The state should be ready.
1181 public void SetSilenceDetection(SilenceDetection type)
1185 SttError error = SttSetSilenceDetection(_handle, type);
1186 if (error != SttError.None)
1188 Log.Error(LogTag, "SetSilenceDetection Failed with error " + error);
1189 throw ExceptionFactory.CreateException(error);
1195 /// Sets the sound to start recording.
1196 /// Sound file type should be .wav type.
1198 /// <since_tizen> 3 </since_tizen>
1200 /// http://tizen.org/privilege/recorder
1202 /// <param name="filePath">
1203 /// File path for the sound.
1206 /// http://tizen.org/feature/speech.recognition
1207 /// http://tizen.org/feature/microphone
1209 /// <exception cref="InvalidOperationException">
1210 /// This exception can be due to the following reasons:
1211 /// 1. Invalid State
1212 /// 2. Operation Failed
1214 /// <exception cref="NotSupportedException">This exception can be due to STT not supported.</exception>
1215 /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception>
1216 /// <exception cref="ArgumentException"> If an Invalid Parameter is provided. </exception>
1218 /// The state should be ready.
1220 public void SetStartSound(string filePath)
1224 SttError error = SttSetStartSound(_handle, filePath);
1225 if (error != SttError.None)
1227 Log.Error(LogTag, "SetStartSound Failed with error " + error);
1228 throw ExceptionFactory.CreateException(error);
1234 /// Unsets the sound to start recording.
1236 /// <since_tizen> 3 </since_tizen>
1238 /// http://tizen.org/privilege/recorder
1241 /// http://tizen.org/feature/speech.recognition
1242 /// http://tizen.org/feature/microphone
1244 /// <exception cref="InvalidOperationException">
1245 /// This exception can be due to the following reasons:
1246 /// 1. Invalid State
1247 /// 2. Operation Failed
1249 /// <exception cref="NotSupportedException">This exception can be due to STT not supported.</exception>
1250 /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception>
1252 /// The state should be ready.
1254 public void UnsetStartSound()
1258 SttError error = SttUnsetStartSound(_handle);
1259 if (error != SttError.None)
1261 Log.Error(LogTag, "UnsetStartSound Failed with error " + error);
1262 throw ExceptionFactory.CreateException(error);
1268 /// Sets the sound to stop recording.
1269 /// Sound file type should be .wav type.
1271 /// <since_tizen> 3 </since_tizen>
1273 /// http://tizen.org/privilege/recorder
1275 /// <param name="filePath">
1276 /// File Path for the sound.
1279 /// http://tizen.org/feature/speech.recognition
1280 /// http://tizen.org/feature/microphone
1282 /// <exception cref="InvalidOperationException">
1283 /// This exception can be due to the following reasons:
1284 /// 1. Invalid State
1285 /// 2. Operation Failed
1287 /// <exception cref="NotSupportedException">This exception can be due to STT not supported.</exception>
1288 /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception>
1289 /// <exception cref="ArgumentException">This exception can be due to Invalid Parameter.</exception>
1291 /// The state should be ready.
1293 public void SetStopSound(string filePath)
1297 SttError error = SttSetStopSound(_handle, filePath);
1298 if (error != SttError.None)
1300 Log.Error(LogTag, "SetStopSound Failed with error " + error);
1301 throw ExceptionFactory.CreateException(error);
1307 /// Unsets the sound to stop recording.
1309 /// <since_tizen> 3 </since_tizen>
1311 /// http://tizen.org/privilege/recorder
1314 /// http://tizen.org/feature/speech.recognition
1315 /// http://tizen.org/feature/microphone
1317 /// <exception cref="InvalidOperationException">
1318 /// This exception can be due to the following reasons:
1319 /// 1. Invalid State
1320 /// 2. Operation Failed
1322 /// <exception cref="NotSupportedException">This exception can be due to STT not supported.</exception>
1323 /// <exception cref="UnauthorizedAccessException"> his exception can be due to permission denied.</exception>
1325 /// The state should be ready.
1327 public void UnsetStopSound()
1331 SttError error = SttUnsetStopSound(_handle);
1332 if (error != SttError.None)
1334 Log.Error(LogTag, "UnsetStopSound Failed with error " + error);
1335 throw ExceptionFactory.CreateException(error);
1341 /// Starts the recording and recognition asynchronously.
1342 /// This function starts recording in the STT service and sends the recording data to the engine.
1343 /// This work continues until stop, cancel, or silence is detected by engine.
1345 /// <since_tizen> 3 </since_tizen>
1347 /// http://tizen.org/privilege/recorder
1349 /// <param name="language">
1350 /// The language selected.
1352 /// <param name="type">
1353 /// The type for recognition.
1356 /// http://tizen.org/feature/speech.recognition
1357 /// http://tizen.org/feature/microphone
1359 /// <exception cref="InvalidOperationException">
1360 /// This exception can be due to the following reasons:
1361 /// 1. Invalid State
1362 /// 2. Operation Failed
1363 /// 3. Recorder Busy
1364 /// 4. Progress to recording is not finished
1366 /// <exception cref="NotSupportedException">This exception can be due to STT not supported.</exception>
1367 /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception>
1368 /// <exception cref="ArgumentException">This exception can be due to an invalid language.</exception>
1370 /// The state should be ready.
1373 /// It will invoke the StateChanged event, if registered.
1374 /// If this function succeeds, the STT state will be recording.
1375 /// If you call this function again before the state changes, you will receive ErrorINProgressToRecording.
1377 public void Start(string language, RecognitionType type)
1381 string recType = "stt.recognition.type.FREE";
1384 case RecognitionType.Free:
1386 recType = "stt.recognition.type.FREE";
1390 case RecognitionType.Partial:
1392 recType = "stt.recognition.type.FREE.PARTIAL";
1396 case RecognitionType.Search:
1398 recType = "stt.recognition.type.SEARCH";
1402 case RecognitionType.WebSearch:
1404 recType = "stt.recognition.type.WEB_SEARCH";
1408 case RecognitionType.Map:
1410 recType = "stt.recognition.type.MAP";
1415 SttError error = SttStart(_handle, language, recType);
1416 if (error != SttError.None)
1418 Log.Error(LogTag, "Start Failed with error " + error);
1419 throw ExceptionFactory.CreateException(error);
1425 /// Finishes the recording and starts recognition processing in the engine asynchronously.
1427 /// <since_tizen> 3 </since_tizen>
1429 /// http://tizen.org/privilege/recorder
1432 /// http://tizen.org/feature/speech.recognition
1433 /// http://tizen.org/feature/microphone
1435 /// <exception cref="InvalidOperationException">
1436 /// This exception can be due to the following reasons:
1437 /// 1. Invalid State
1438 /// 2. Operation Failed
1439 /// 3. Progress to ready is not finished
1440 /// 4. Progress to recording is not finished
1441 /// 5. Progress to processing is not finished
1443 /// <exception cref="NotSupportedException">This exception can be due to STT not supported.</exception>
1444 /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception>
1446 /// The state should be Recording.
1449 /// It will invoke the StateChanged Event, if registered.
1450 /// If this function succeeds, the STT state will be processing.
1451 /// If you call this function again before the state changes, you will receive ErrorINProgressToProcessing.
1452 /// After processing of engine, the RecognitionResult event is invoked.
1458 SttError error = SttStop(_handle);
1459 if (error != SttError.None)
1461 Log.Error(LogTag, "Stop Failed with error " + error);
1462 throw ExceptionFactory.CreateException(error);
1468 /// Cancels processing the recognition and recording asynchronously.
1469 /// This function cancels recording and the engine cancels recognition processing.
1470 /// After successful cancellation, the StateChanged event is invoked, otherwise if an error is occurs, the ErrorOccurred event is invoked.
1472 /// <since_tizen> 3 </since_tizen>
1474 /// http://tizen.org/privilege/recorder
1477 /// http://tizen.org/feature/speech.recognition
1478 /// http://tizen.org/feature/microphone
1480 /// <exception cref="InvalidOperationException">
1481 /// This exception can be due to the following reasons:
1482 /// 1. Invalid State
1483 /// 2. Operation Failed
1484 /// 3. Progress to ready is not finished
1485 /// 4. Progress to recording is not finished
1486 /// 5. Progress to processing is not finished
1488 /// <exception cref="NotSupportedException">This exception can be due to STT not supported.</exception>
1489 /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception>
1491 /// The state should be Recording or Processing.
1494 /// It will invoke the StateChanged event, if registered.
1495 /// If this function succeeds, the STT state will be ready.
1496 /// If you call this function again before the state changes, you will receive ErrorINProgressToReady.
1498 public void Cancel()
1502 SttError error = SttCancel(_handle);
1503 if (error != SttError.None)
1505 Log.Error(LogTag, "Cancel Failed with error " + error);
1506 throw ExceptionFactory.CreateException(error);
1512 /// Method to release resources.
1514 /// <since_tizen> 3 </since_tizen>
1515 public void Dispose()
1518 GC.SuppressFinalize(this);
1522 /// Method to release resources.
1524 /// <since_tizen> 3 </since_tizen>
1525 /// <param name="disposing">
1526 /// The boolean value for destoying stt handle.
1528 protected virtual void Dispose(bool disposing)
1534 if (_handle != IntPtr.Zero)
1536 SttError error = SttDestroy(_handle);
1537 if (error != SttError.None)
1539 Log.Error(LogTag, "Destroy Failed with error " + error);
1541 _handle = IntPtr.Zero;
1545 disposedValue = true;