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 /// 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 the 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;
448 SttError error = SttUnsetStateChangedCB(_handle);
449 if (error != SttError.None)
451 Log.Error(LogTag, "Remove StateChanged Failed with error " + error);
454 _stateChanged -= value;
461 /// Event to be invoked when an error occurs.
463 /// <since_tizen> 4 </since_tizen>
464 public event EventHandler<ErrorOccurredEventArgs> ErrorOccurred
470 _errorDelegate = (IntPtr handle, SttError reason, IntPtr userData) =>
472 ErrorOccurredEventArgs args = new ErrorOccurredEventArgs(handle, reason);
473 _errorOccurred?.Invoke(this, args);
475 SttError error = SttSetErrorCB(_handle, _errorDelegate, IntPtr.Zero);
476 if (error != SttError.None)
478 Log.Error(LogTag, "Add ErrorOccurred Failed with error " + error);
483 _errorOccurred += value;
492 SttError error = SttUnsetErrorCB(_handle);
493 if (error != SttError.None)
495 Log.Error(LogTag, "Remove ErrorOccurred Failed with error " + error);
498 _errorOccurred -= value;
504 /// Event to be invoked when the default language changes.
506 /// <since_tizen> 3 </since_tizen>
507 public event EventHandler<DefaultLanguageChangedEventArgs> DefaultLanguageChanged
513 _languageDelegate = (IntPtr handle, IntPtr previousLanguage, IntPtr currentLanguage, IntPtr userData) =>
515 string previousLanguageString = Marshal.PtrToStringAnsi(previousLanguage);
516 string currentLanguageString = Marshal.PtrToStringAnsi(currentLanguage);
517 DefaultLanguageChangedEventArgs args = new DefaultLanguageChangedEventArgs(previousLanguageString, currentLanguageString);
518 _defaultLanguageChanged?.Invoke(this, args);
520 SttError error = SttSetDefaultLanguageChangedCB(_handle, _languageDelegate, IntPtr.Zero);
521 if (error != SttError.None)
523 Log.Error(LogTag, "Add DefaultLanguageChanged Failed with error " + error);
528 _defaultLanguageChanged += value;
537 SttError error = SttUnsetDefaultLanguageChangedCB(_handle);
538 if (error != SttError.None)
540 Log.Error(LogTag, "Remove DefaultLanguageChanged Failed with error " + error);
543 _defaultLanguageChanged -= value;
550 /// Event to be invoked to detect the engine change.
552 /// <since_tizen> 3 </since_tizen>
553 public event EventHandler<EngineChangedEventArgs> EngineChanged
559 _engineDelegate = (IntPtr handle, IntPtr engineId, IntPtr language, bool supportSilence, bool needCredential, IntPtr userData) =>
561 string engineIdString = Marshal.PtrToStringAnsi(engineId);
562 string languageString = Marshal.PtrToStringAnsi(language);
563 EngineChangedEventArgs args = new EngineChangedEventArgs(engineIdString, languageString, supportSilence, needCredential);
564 _engineChanged?.Invoke(this, args);
566 SttError error = SttSetEngineChangedCB(_handle, _engineDelegate, IntPtr.Zero);
567 if (error != SttError.None)
569 Log.Error(LogTag, "Add EngineChanged Failed with error " + error);
573 _engineChanged += value;
582 SttError error = SttUnsetEngineChangedCB(_handle);
583 if (error != SttError.None)
585 Log.Error(LogTag, "Remove EngineChanged Failed with error " + error);
588 _engineChanged -= value;
594 /// Gets the default language set by the user.
595 /// 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.
596 /// For example, "ko_KR" for Korean, "en_US" for American English.
598 /// <since_tizen> 3 </since_tizen>
600 /// Default language in STT.
603 /// http://tizen.org/privilege/recorder
606 /// Default Language string value.
608 public string DefaultLanguage
615 SttError error = SttGetDefaultLanguage(_handle, out language);
616 if (error != SttError.None)
618 Log.Error(LogTag, "DefaultLanguage Failed with error " + error);
628 /// Gets the microphone volume during recording.
630 /// <since_tizen> 3 </since_tizen>
632 /// Recording volume in STT.
635 /// http://tizen.org/privilege/recorder
638 /// The state must be recording.
640 public float RecordingVolume
647 SttError error = SttGetRecordingVolume(_handle, out volume);
648 if (error != SttError.None)
650 Log.Error(LogTag, "GetRecordingVolume Failed with error " + error);
661 /// Gets the current STT state.
663 /// <since_tizen> 3 </since_tizen>
665 /// Current state of STT.
668 /// http://tizen.org/privilege/recorder
671 /// Current STT state value.
673 public State CurrentState
680 SttError error = SttGetState(_handle, out state);
681 if (error != SttError.None)
683 Log.Error(LogTag, "GetState Failed with error " + error);
684 return State.Unavailable;
694 /// This property can be used to get and set the current engine id.
696 /// <since_tizen> 3 </since_tizen>
698 /// Current STT engine id.
701 /// http://tizen.org/privilege/recorder
703 /// <exception cref="InvalidOperationException">
704 /// This exceptioncan occur while setting due to the following reasons:
705 /// 1. Operation Failed
708 /// <exception cref="OutOfMemoryException">This exception can be due to out of memory.</exception>
709 /// <exception cref="NotSupportedException">This exception can be due to STT not supported.</exception>
710 /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception>
711 /// <exception cref="ArgumentException">This can happen if improper EngineId is provided while setting the value.</exception>
713 /// The state must be created.
722 SttError error = SttGetEngine(_handle, out engineId);
723 if (error != SttError.None)
725 Log.Error(LogTag, "Get EngineId Failed with error " + error);
736 SttError error = SttSetEngine(_handle, value);
737 if (error != SttError.None)
739 Log.Error(LogTag, "Set EngineId Failed with error " + error);
740 throw ExceptionFactory.CreateException(error);
748 /// Retrieves the time stamp of the current recognition result.
750 /// <since_tizen> 3 </since_tizen>
752 /// List of ResultTime.
755 /// http://tizen.org/privilege/recorder
758 /// http://tizen.org/feature/speech.recognition
759 /// http://tizen.org/feature/microphone
762 /// This function should only be called in the RecognitionResult event.
764 /// <exception cref="InvalidOperationException">This exception can be due to operation failed.</exception>
765 /// <exception cref="NotSupportedException">This exception can be due to STT not supported.</exception>
766 /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception>
767 public IEnumerable<ResultTime> GetDetailedResult()
769 List<ResultTime> list = new List<ResultTime>();
772 _resultTimeDelegate = (IntPtr handle, int index, TimeEvent e, IntPtr text, IntPtr startTime, IntPtr endTime, IntPtr userData) =>
774 _result = new ResultTime(index, e, Marshal.PtrToStringAnsi(text), (long)startTime, (long)endTime);
778 SttError error = SttForeachDetailedResult(_handle, _resultTimeDelegate, IntPtr.Zero);
779 if (error != SttError.None)
781 Log.Error(LogTag, "GetDetailedResult Failed with error " + error);
782 throw ExceptionFactory.CreateException(error);
790 /// Gets the private data from the STT engine.
792 /// <since_tizen> 3 </since_tizen>
793 /// <param name="key">
797 /// The data corresponding to the key is provided.
800 /// http://tizen.org/privilege/recorder
803 /// http://tizen.org/feature/speech.recognition
804 /// http://tizen.org/feature/microphone
806 /// <exception cref="InvalidOperationException">This exception can be due to invalid state.</exception>
807 /// <exception cref="NotSupportedException">This exception can be due to STT not supported.</exception>
808 /// <exception cref="TimeoutException">This exception can be due to No Answer from STT Service.</exception>
810 /// The state must be ready.
812 public string GetPrivateData(string key)
817 SttError error = SttGetPrivateData(_handle, key, out data);
818 if (error != SttError.None)
820 Log.Error(LogTag, "GetPrivateData Failed with error " + error);
821 throw ExceptionFactory.CreateException(error);
829 /// Sets the private data to the STT engine.
831 /// <since_tizen> 3 </since_tizen>
832 /// <param name="key">
835 /// <param name="data">
839 /// http://tizen.org/privilege/recorder
842 /// http://tizen.org/feature/speech.recognition
843 /// http://tizen.org/feature/microphone
845 /// <exception cref="InvalidOperationException">This exception can be due to invalid state.</exception>
846 /// <exception cref="NotSupportedException">This exception can be due to STT not supported.</exception>
847 /// <exception cref="TimeoutException">This exception can be due to No Answer from STT Service.</exception>
848 /// <exception cref="ArgumentException"> This can happen if Improper value is provided while setting the value. </exception>
850 /// The state must be ready.
852 public void SetPrivateData(string key, string data)
856 SttError error = SttSetPrivateData(_handle, key, data);
857 if (error != SttError.None)
859 Log.Error(LogTag, "SetPrivateData Failed with error " + error);
860 throw ExceptionFactory.CreateException(error);
866 /// Gets the list of supported engines.
868 /// <since_tizen> 3 </since_tizen>
870 /// IEnumerable<SupportedEngine> list of supported engines.
873 /// http://tizen.org/privilege/recorder
876 /// http://tizen.org/feature/speech.recognition
877 /// http://tizen.org/feature/microphone
879 /// <exception cref="InvalidOperationException">This exception can be due to operation failed.</exception>
880 /// <exception cref="OutOfMemoryException">This exception can be due to out of memory.</exception>
881 /// <exception cref="NotSupportedException">This exception can be due to STT not supported.</exception>
882 /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception>
883 public IEnumerable<SupportedEngine> GetSupportedEngines()
885 List<SupportedEngine> engineList = new List<SupportedEngine>();
888 SupportedEngineCallback supportedEngineDelegate = (IntPtr handle, IntPtr engineId, IntPtr engineName, IntPtr userData) =>
890 string id = Marshal.PtrToStringAnsi(engineId);
891 string name = Marshal.PtrToStringAnsi(engineName);
892 SupportedEngine engine = new SupportedEngine(id, name);
893 engineList.Add(engine);
896 SttError error = SttForeEachSupportedEngines(_handle, supportedEngineDelegate, IntPtr.Zero);
897 if (error != SttError.None)
899 Log.Error(LogTag, "Create Failed with error " + error);
900 throw ExceptionFactory.CreateException(error);
908 /// Sets the application credential.
910 /// <since_tizen> 3 </since_tizen>
911 /// <param name="credential">
912 /// The credential string.
915 /// http://tizen.org/privilege/recorder
918 /// http://tizen.org/feature/speech.recognition
919 /// http://tizen.org/feature/microphone
921 /// <exception cref="InvalidOperationException">
922 /// This exceptioncan be due to the following reasons:
923 /// 1. Operation Failed
926 /// <exception cref="OutOfMemoryException">This exception can be due to out of memory.</exception>
927 /// <exception cref="NotSupportedException">This exception can be due to STT not supported.</exception>
928 /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception>
929 /// <exception cref="ArgumentException"> This can happen if Improper value is provided while setting the value. </exception>
931 /// The state must be created.
933 public void SetCredential(string credential)
937 SttError error = SttSetcredential(_handle, credential);
938 if (error != SttError.None)
940 Log.Error(LogTag, "SetCredential Failed with error " + error);
941 throw ExceptionFactory.CreateException(error);
947 /// Connects to the STT service asynchronously.
949 /// <since_tizen> 3 </since_tizen>
951 /// http://tizen.org/privilege/recorder
954 /// http://tizen.org/feature/speech.recognition
955 /// http://tizen.org/feature/microphone
957 /// <exception cref="InvalidOperationException">This exception can be due to invalid state.</exception>
958 /// <exception cref="NotSupportedException">This exception can be due to STT not supported.</exception>
959 /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception>
961 /// The state must be created.
964 /// If this function is successful, the STT state will be ready.
965 /// If this function is unsuccessful, ErrorOccurred event will be invoked.
967 public void Prepare()
971 SttError error = SttPrepare(_handle);
972 if (error != SttError.None)
974 Log.Error(LogTag, "SetEngine Failed with error " + error);
975 throw ExceptionFactory.CreateException(error);
981 /// Disconnects from the STT service.
983 /// <since_tizen> 3 </since_tizen>
985 /// http://tizen.org/privilege/recorder
988 /// http://tizen.org/feature/speech.recognition
989 /// http://tizen.org/feature/microphone
991 /// <exception cref="InvalidOperationException">This exception can be due to invalid state.</exception>
992 /// <exception cref="NotSupportedException">This exception can be due to STT not supported.</exception>
993 /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception>
995 /// The state must be ready.
998 /// If this function is successful, the STT state will be Created.
1000 public void Unprepare()
1004 SttError error = SttUnprepare(_handle);
1005 if (error != SttError.None)
1007 Log.Error(LogTag, "Unprepare Failed with error " + error);
1008 throw ExceptionFactory.CreateException(error);
1014 /// Retrieves all the supported languages of the current engine.
1015 /// 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.
1016 /// For example, "ko_KR" for Korean, "en_US" for American English.
1018 /// <since_tizen> 4 </since_tizen>
1020 /// http://tizen.org/privilege/recorder
1023 /// List of strings for supported languages.
1026 /// http://tizen.org/feature/speech.recognition
1027 /// http://tizen.org/feature/microphone
1029 /// <exception cref="InvalidOperationException">
1030 /// This exception can be due to the following reasons:
1031 /// 1. Engine Not Found.
1032 /// 2. Operation Failed.
1034 /// <exception cref="NotSupportedException">This exception can be due to STT not supported.</exception>
1035 /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception>
1036 public IEnumerable<string> GetSupportedLanguages()
1038 List<string> languageList = new List<string>();
1041 SupportedLanguageCallback supportedLanguageDelegate = (IntPtr handle, IntPtr language, IntPtr userData) =>
1043 string lang = Marshal.PtrToStringAnsi(language);
1044 languageList.Add(lang);
1048 SttError error = SttForeachSupportedLanguages(_handle, supportedLanguageDelegate, IntPtr.Zero);
1049 if (error != SttError.None)
1051 Log.Error(LogTag, "GetSupportedLanguages Failed with error " + error);
1052 throw ExceptionFactory.CreateException(error);
1056 return languageList;
1060 /// Checks whether the recognition type is supported.
1062 /// <since_tizen> 3 </since_tizen>
1064 /// http://tizen.org/privilege/recorder
1066 /// <param name="type">
1067 /// RecognitionType value.
1070 /// Bool value indicating whether the recognition type is supported.
1073 /// http://tizen.org/feature/speech.recognition
1074 /// http://tizen.org/feature/microphone
1076 /// <exception cref="InvalidOperationException">
1077 /// This exception can be due to the following reasons:
1078 /// 1. Invalid State
1079 /// 2. Engine Not Found
1080 /// 3. Operation Failed
1082 /// <exception cref="NotSupportedException">This exception can be due to STT not supported.</exception>
1084 /// The state should be ready.
1086 public bool IsRecognitionTypeSupported(RecognitionType type)
1091 string recType = "stt.recognition.type.FREE";
1094 case RecognitionType.Free:
1096 recType = "stt.recognition.type.FREE";
1100 case RecognitionType.Partial:
1102 recType = "stt.recognition.type.FREE.PARTIAL";
1106 case RecognitionType.Search:
1108 recType = "stt.recognition.type.SEARCH";
1112 case RecognitionType.WebSearch:
1114 recType = "stt.recognition.type.WEB_SEARCH";
1118 case RecognitionType.Map:
1120 recType = "stt.recognition.type.MAP";
1125 SttError error = SttIsRecognitionTypeSupported(_handle, recType, out supported);
1126 if (error != SttError.None)
1128 Log.Error(LogTag, "IsRecognitionTypeSupported Failed with error " + error);
1129 throw ExceptionFactory.CreateException(error);
1137 /// Sets the silence detection.
1139 /// <since_tizen> 3 </since_tizen>
1141 /// http://tizen.org/privilege/recorder
1143 /// <param name="type">
1144 /// SilenceDetection value.
1147 /// http://tizen.org/feature/speech.recognition
1148 /// http://tizen.org/feature/microphone
1150 /// <exception cref="InvalidOperationException">
1151 /// This exception can be due to the following reasons:
1152 /// 1. Invalid State
1153 /// 2. Not supported feature of current engine
1154 /// 3. Operation Failed
1156 /// <exception cref="NotSupportedException">This exception can be due to STT not supported.</exception>
1158 /// The state should be ready.
1160 public void SetSilenceDetection(SilenceDetection type)
1164 SttError error = SttSetSilenceDetection(_handle, type);
1165 if (error != SttError.None)
1167 Log.Error(LogTag, "SetSilenceDetection Failed with error " + error);
1168 throw ExceptionFactory.CreateException(error);
1174 /// Sets the sound to start recording.
1175 /// Sound file type should be .wav type.
1177 /// <since_tizen> 3 </since_tizen>
1179 /// http://tizen.org/privilege/recorder
1181 /// <param name="filePath">
1182 /// File path for the sound.
1185 /// http://tizen.org/feature/speech.recognition
1186 /// http://tizen.org/feature/microphone
1188 /// <exception cref="InvalidOperationException">
1189 /// This exception can be due to the following reasons:
1190 /// 1. Invalid State
1191 /// 2. Operation Failed
1193 /// <exception cref="NotSupportedException">This exception can be due to STT not supported.</exception>
1194 /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception>
1195 /// <exception cref="ArgumentException"> If an Invalid Parameter is provided. </exception>
1197 /// The state should be ready.
1199 public void SetStartSound(string filePath)
1203 SttError error = SttSetStartSound(_handle, filePath);
1204 if (error != SttError.None)
1206 Log.Error(LogTag, "SetStartSound Failed with error " + error);
1207 throw ExceptionFactory.CreateException(error);
1213 /// Unsets the sound to start recording.
1215 /// <since_tizen> 3 </since_tizen>
1217 /// http://tizen.org/privilege/recorder
1220 /// http://tizen.org/feature/speech.recognition
1221 /// http://tizen.org/feature/microphone
1223 /// <exception cref="InvalidOperationException">
1224 /// This exception can be due to the following reasons:
1225 /// 1. Invalid State
1226 /// 2. Operation Failed
1228 /// <exception cref="NotSupportedException">This exception can be due to STT not supported.</exception>
1229 /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception>
1231 /// The state should be ready.
1233 public void UnsetStartSound()
1237 SttError error = SttUnsetStartSound(_handle);
1238 if (error != SttError.None)
1240 Log.Error(LogTag, "UnsetStartSound Failed with error " + error);
1241 throw ExceptionFactory.CreateException(error);
1247 /// Sets the sound to stop recording.
1248 /// Sound file type should be .wav type.
1250 /// <since_tizen> 3 </since_tizen>
1252 /// http://tizen.org/privilege/recorder
1254 /// <param name="filePath">
1255 /// File Path for the sound.
1258 /// http://tizen.org/feature/speech.recognition
1259 /// http://tizen.org/feature/microphone
1261 /// <exception cref="InvalidOperationException">
1262 /// This exception can be due to the following reasons:
1263 /// 1. Invalid State
1264 /// 2. Operation Failed
1266 /// <exception cref="NotSupportedException">This exception can be due to STT not supported.</exception>
1267 /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception>
1268 /// <exception cref="ArgumentException">This exception can be due to Invalid Parameter.</exception>
1270 /// The state should be ready.
1272 public void SetStopSound(string filePath)
1276 SttError error = SttSetStopSound(_handle, filePath);
1277 if (error != SttError.None)
1279 Log.Error(LogTag, "SetStopSound Failed with error " + error);
1280 throw ExceptionFactory.CreateException(error);
1286 /// Unsets the sound to stop recording.
1288 /// <since_tizen> 3 </since_tizen>
1290 /// http://tizen.org/privilege/recorder
1293 /// http://tizen.org/feature/speech.recognition
1294 /// http://tizen.org/feature/microphone
1296 /// <exception cref="InvalidOperationException">
1297 /// This exception can be due to the following reasons:
1298 /// 1. Invalid State
1299 /// 2. Operation Failed
1301 /// <exception cref="NotSupportedException">This exception can be due to STT not supported.</exception>
1302 /// <exception cref="UnauthorizedAccessException"> his exception can be due to permission denied.</exception>
1304 /// The state should be ready.
1306 public void UnsetStopSound()
1310 SttError error = SttUnsetStopSound(_handle);
1311 if (error != SttError.None)
1313 Log.Error(LogTag, "UnsetStopSound Failed with error " + error);
1314 throw ExceptionFactory.CreateException(error);
1320 /// Starts the recording and recognition asynchronously.
1321 /// This function starts recording in the STT service and sends the recording data to the engine.
1322 /// This work continues until stop, cancel, or silence is detected by engine.
1324 /// <since_tizen> 3 </since_tizen>
1326 /// http://tizen.org/privilege/recorder
1328 /// <param name="language">
1329 /// The language selected.
1331 /// <param name="type">
1332 /// The type for recognition.
1335 /// http://tizen.org/feature/speech.recognition
1336 /// http://tizen.org/feature/microphone
1338 /// <exception cref="InvalidOperationException">
1339 /// This exception can be due to the following reasons:
1340 /// 1. Invalid State
1341 /// 2. Operation Failed
1342 /// 3. Recorder Busy
1343 /// 4. Progress to recording is not finished
1345 /// <exception cref="NotSupportedException">This exception can be due to STT not supported.</exception>
1346 /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception>
1347 /// <exception cref="ArgumentException">This exception can be due to an invalid language.</exception>
1349 /// The state should be ready.
1352 /// It will invoke the StateChanged event, if registered.
1353 /// If this function succeeds, the STT state will be recording.
1354 /// If you call this function again before the state changes, you will receive ErrorINProgressToRecording.
1356 public void Start(string language, RecognitionType type)
1360 string recType = "stt.recognition.type.FREE";
1363 case RecognitionType.Free:
1365 recType = "stt.recognition.type.FREE";
1369 case RecognitionType.Partial:
1371 recType = "stt.recognition.type.FREE.PARTIAL";
1375 case RecognitionType.Search:
1377 recType = "stt.recognition.type.SEARCH";
1381 case RecognitionType.WebSearch:
1383 recType = "stt.recognition.type.WEB_SEARCH";
1387 case RecognitionType.Map:
1389 recType = "stt.recognition.type.MAP";
1394 SttError error = SttStart(_handle, language, recType);
1395 if (error != SttError.None)
1397 Log.Error(LogTag, "Start Failed with error " + error);
1398 throw ExceptionFactory.CreateException(error);
1404 /// Finishes the recording and starts recognition processing in the engine asynchronously.
1406 /// <since_tizen> 3 </since_tizen>
1408 /// http://tizen.org/privilege/recorder
1411 /// http://tizen.org/feature/speech.recognition
1412 /// http://tizen.org/feature/microphone
1414 /// <exception cref="InvalidOperationException">
1415 /// This exception can be due to the following reasons:
1416 /// 1. Invalid State
1417 /// 2. Operation Failed
1418 /// 3. Progress to ready is not finished
1419 /// 4. Progress to recording is not finished
1420 /// 5. Progress to processing is not finished
1422 /// <exception cref="NotSupportedException">This exception can be due to STT not supported.</exception>
1423 /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception>
1425 /// The state should be Recording.
1428 /// It will invoke the StateChanged Event, if registered.
1429 /// If this function succeeds, the STT state will be processing.
1430 /// If you call this function again before the state changes, you will receive ErrorINProgressToProcessing.
1431 /// After processing of engine, the RecognitionResult event is invoked.
1437 SttError error = SttStop(_handle);
1438 if (error != SttError.None)
1440 Log.Error(LogTag, "Stop Failed with error " + error);
1441 throw ExceptionFactory.CreateException(error);
1447 /// Cancels processing the recognition and recording asynchronously.
1448 /// This function cancels recording and the engine cancels recognition processing.
1449 /// After successful cancellation, the StateChanged event is invoked, otherwise if an error is occurs, the ErrorOccurred event is invoked.
1451 /// <since_tizen> 3 </since_tizen>
1453 /// http://tizen.org/privilege/recorder
1456 /// http://tizen.org/feature/speech.recognition
1457 /// http://tizen.org/feature/microphone
1459 /// <exception cref="InvalidOperationException">
1460 /// This exception can be due to the following reasons:
1461 /// 1. Invalid State
1462 /// 2. Operation Failed
1463 /// 3. Progress to ready is not finished
1464 /// 4. Progress to recording is not finished
1465 /// 5. Progress to processing is not finished
1467 /// <exception cref="NotSupportedException">This exception can be due to STT not supported.</exception>
1468 /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception>
1470 /// The state should be Recording or Processing.
1473 /// It will invoke the StateChanged event, if registered.
1474 /// If this function succeeds, the STT state will be ready.
1475 /// If you call this function again before the state changes, you will receive ErrorINProgressToReady.
1477 public void Cancel()
1481 SttError error = SttCancel(_handle);
1482 if (error != SttError.None)
1484 Log.Error(LogTag, "Cancel Failed with error " + error);
1485 throw ExceptionFactory.CreateException(error);
1491 /// Method to release resources.
1493 /// <since_tizen> 3 </since_tizen>
1494 public void Dispose()
1500 /// Method to release resources.
1502 /// <since_tizen> 3 </since_tizen>
1503 /// <param name="disposing">
1504 /// The boolean value for destoying stt handle.
1506 protected virtual void Dispose(bool disposing)
1514 SttError error = SttDestroy(_handle);
1515 if (error != SttError.None)
1517 Log.Error(LogTag, "Destroy Failed with error " + error);
1522 disposedValue = true;