--- /dev/null
+/*
+* Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* Licensed under the Apache License, Version 2.0 (the License);
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an AS IS BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+
+using System;
+using System.Runtime.InteropServices;
+
+/// <summary>
+/// Partial Interop Class
+/// </summary>
+internal static partial class Interop
+{
+ /// <summary>
+ /// Stt Interop Class
+ /// </summary>
+ internal static class Stt
+ {
+ internal static string LogTag = "Tizen.Uix.Stt";
+
+ private const int ErrorStt = -0x02F00000;
+
+ internal enum SttError
+ {
+ None = Tizen.Internals.Errors.ErrorCode.None, /**< Successful */
+ OutOfMemory = Tizen.Internals.Errors.ErrorCode.OutOfMemory, /**< Out of Memory */
+ IoError = Tizen.Internals.Errors.ErrorCode.IoError, /**< I/O error */
+ InvalidParameter = Tizen.Internals.Errors.ErrorCode.InvalidParameter, /**< Invalid parameter */
+ TimedOut = Tizen.Internals.Errors.ErrorCode.TimedOut, /**< No answer from the STT service */
+ RecorderBusy = Tizen.Internals.Errors.ErrorCode.ResourceBusy, /**< Device or resource busy */
+ OutOfNetwork = Tizen.Internals.Errors.ErrorCode.Networkdown, /**< Network is down */
+ PermissionDenied = Tizen.Internals.Errors.ErrorCode.PermissionDenied, /**< Permission denied */
+ NotSupported = Tizen.Internals.Errors.ErrorCode.NotSupported, /**< STT NOT supported */
+ InvalidState = ErrorStt | 0x01, /**< Invalid state */
+ InvalidLanguage = ErrorStt | 0x02, /**< Invalid language */
+ EngineNotFound = ErrorStt | 0x03, /**< No available engine */
+ OperationFailed = ErrorStt | 0x04, /**< Operation failed */
+ NotSupportedFeature = ErrorStt | 0x05, /**< Not supported feature of current engine */
+ RecordingTimedOut = ErrorStt | 0x06, /**< Recording timed out */
+ NoSpeech = ErrorStt | 0x07, /**< No speech while recording*/
+ InProgressToReady = ErrorStt | 0x08, /**< Progress to ready is not finished*/
+ InProgressToRecording = ErrorStt | 0x09, /**< Progress to recording is not finished*/
+ InProgressToProcessing = ErrorStt | 0x10, /**< Progress to processing is not finished*/
+ ServiceReset = ErrorStt | 0x11 /**< Service reset*/
+ };
+
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ internal delegate bool SupportedEngineCallback(IntPtr handle, IntPtr engineId, IntPtr engineName, IntPtr userData);
+
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ internal delegate void RecognitionResultCallback(IntPtr handle, Tizen.Uix.Stt.ResultEvent e, IntPtr data, int dataCount, IntPtr msg, IntPtr userData);
+
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ internal delegate bool ResultTimeCallback(IntPtr handle, int index, Tizen.Uix.Stt.TimeEvent e, IntPtr text, IntPtr startTime, IntPtr endTime, IntPtr userData);
+
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ internal delegate void StateChangedCallback(IntPtr handle, Tizen.Uix.Stt.State previous, Tizen.Uix.Stt.State current, IntPtr userData);
+
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ internal delegate void ErrorCallback(IntPtr handle, SttError reason, IntPtr userData);
+
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ internal delegate bool SupportedLanguageCallback(IntPtr handle, IntPtr language, IntPtr userData);
+
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ internal delegate void DefaultLanguageChangedCallback(IntPtr handle, IntPtr previousLanguage, IntPtr currentLanguage, IntPtr userData);
+
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ internal delegate void EngineChangedCallback(IntPtr handle, IntPtr engineId, IntPtr language, bool supportSilence, bool needCredential, IntPtr userData);
+
+ [DllImport(Libraries.Stt, EntryPoint = "stt_create", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern SttError SttCreate(out IntPtr handle);
+
+ [DllImport(Libraries.Stt, EntryPoint = "stt_destroy", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern SttError SttDestroy(IntPtr handle);
+
+ [DllImport(Libraries.Stt, EntryPoint = "stt_foreach_supported_engines", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern SttError SttForeEachSupportedEngines(IntPtr handle, SupportedEngineCallback callback, IntPtr userData);
+
+ [DllImport(Libraries.Stt, EntryPoint = "stt_get_engine", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern SttError SttGetEngine(IntPtr handle, out string engineId);
+
+ [DllImport(Libraries.Stt, EntryPoint = "stt_set_engine", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern SttError SttSetEngine(IntPtr handle, string engineId);
+
+ [DllImport(Libraries.Stt, EntryPoint = "stt_set_credential", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern SttError SttSetcredential(IntPtr handle, string credential);
+
+ [DllImport(Libraries.Stt, EntryPoint = "stt_set_private_data", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern SttError SttSetPrivateData(IntPtr handle, string key, string data);
+
+ [DllImport(Libraries.Stt, EntryPoint = "stt_get_private_data", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern SttError SttGetPrivateData(IntPtr handle, string key, out string data);
+
+ [DllImport(Libraries.Stt, EntryPoint = "stt_prepare", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern SttError SttPrepare(IntPtr handle);
+
+ [DllImport(Libraries.Stt, EntryPoint = "stt_unprepare", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern SttError SttUnprepare(IntPtr handle);
+
+ [DllImport(Libraries.Stt, EntryPoint = "stt_foreach_supported_languages", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern SttError SttForeachSupportedLanguages(IntPtr handle, SupportedLanguageCallback callback, IntPtr userData);
+
+ [DllImport(Libraries.Stt, EntryPoint = "stt_get_default_language", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern SttError SttGetDefaultLanguage(IntPtr handle, out string language);
+
+ [DllImport(Libraries.Stt, EntryPoint = "stt_get_state", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern SttError SttGetState(IntPtr handle, out Tizen.Uix.Stt.State state);
+
+ [DllImport(Libraries.Stt, EntryPoint = "stt_get_error_message", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern SttError SttGetErrorMessage(IntPtr handle, out string err_msg);
+
+ [DllImport(Libraries.Stt, EntryPoint = "stt_is_recognition_type_supported", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern SttError SttIsRecognitionTypeSupported(IntPtr handle, string type, out bool support);
+
+ [DllImport(Libraries.Stt, EntryPoint = "stt_set_silence_detection", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern SttError SttSetSilenceDetection(IntPtr handle, Tizen.Uix.Stt.SilenceDetection type);
+
+ [DllImport(Libraries.Stt, EntryPoint = "stt_set_start_sound", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern SttError SttSetStartSound(IntPtr handle, string filename);
+
+ [DllImport(Libraries.Stt, EntryPoint = "stt_unset_start_sound", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern SttError SttUnsetStartSound(IntPtr handle);
+
+ [DllImport(Libraries.Stt, EntryPoint = "stt_set_stop_sound", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern SttError SttSetStopSound(IntPtr handle, string filename);
+
+ [DllImport(Libraries.Stt, EntryPoint = "stt_unset_stop_sound", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern SttError SttUnsetStopSound(IntPtr handle);
+
+ [DllImport(Libraries.Stt, EntryPoint = "stt_start", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern SttError SttStart(IntPtr handle, string language, string type);
+
+ [DllImport(Libraries.Stt, EntryPoint = "stt_stop", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern SttError SttStop(IntPtr handle);
+
+ [DllImport(Libraries.Stt, EntryPoint = "stt_cancel", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern SttError SttCancel(IntPtr handle);
+
+ [DllImport(Libraries.Stt, EntryPoint = "stt_get_recording_volume", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern SttError SttGetRecordingVolume(IntPtr handle, out float volume);
+
+ [DllImport(Libraries.Stt, EntryPoint = "stt_foreach_detailed_result", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern SttError SttForeachDetailedResult(IntPtr handle, ResultTimeCallback callback, IntPtr userData);
+
+ [DllImport(Libraries.Stt, EntryPoint = "stt_set_recognition_result_cb", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern SttError SttSetRecognitionResultCB(IntPtr handle, RecognitionResultCallback callback, IntPtr userData);
+
+ [DllImport(Libraries.Stt, EntryPoint = "stt_unset_recognition_result_cb", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern SttError SttUnsetRecognitionResultCB(IntPtr handle);
+
+ [DllImport(Libraries.Stt, EntryPoint = "stt_set_state_changed_cb", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern SttError SttSetStateChangedCB(IntPtr handle, StateChangedCallback callback, IntPtr userData);
+
+ [DllImport(Libraries.Stt, EntryPoint = "stt_unset_state_changed_cb", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern SttError SttUnsetStateChangedCB(IntPtr handle);
+
+ [DllImport(Libraries.Stt, EntryPoint = "stt_set_error_cb", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern SttError SttSetErrorCB(IntPtr handle, ErrorCallback callback, IntPtr userData);
+
+ [DllImport(Libraries.Stt, EntryPoint = "stt_unset_error_cb", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern SttError SttUnsetErrorCB(IntPtr handle);
+
+ [DllImport(Libraries.Stt, EntryPoint = "stt_set_default_language_changed_cb", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern SttError SttSetDefaultLanguageChangedCB(IntPtr handle, DefaultLanguageChangedCallback callback, IntPtr userData);
+
+ [DllImport(Libraries.Stt, EntryPoint = "stt_unset_default_language_changed_cb", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern SttError SttUnsetDefaultLanguageChangedCB(IntPtr handle);
+
+ [DllImport(Libraries.Stt, EntryPoint = "stt_set_engine_changed_cb", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern SttError SttSetEngineChangedCB(IntPtr handle, EngineChangedCallback callback, IntPtr userData);
+
+ [DllImport(Libraries.Stt, EntryPoint = "stt_unset_engine_changed_cb", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern SttError SttUnsetEngineChangedCB(IntPtr handle);
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+* Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* Licensed under the Apache License, Version 2.0 (the License);
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an AS IS BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+
+using System;
+using System.Collections.Generic;
+using System.Runtime.InteropServices;
+using static Interop.Stt;
+
+namespace Tizen.Uix.Stt
+{
+ /// <summary>
+ /// The token event
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ public enum ResultEvent
+ {
+ /// <summary>
+ /// Event when the recognition full or last result is ready
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ FinalResult = 0,
+ /// <summary>
+ /// Event when the recognition partial result is ready
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ PartialResult,
+ /// <summary>
+ /// Event when the recognition has failed
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ Error
+ };
+
+ /// <summary>
+ /// Enumeration representing the result message
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ public enum ResultMessage
+ {
+ /// <summary>
+ /// No Error
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ None,
+ /// <summary>
+ /// Recognition failed because the speech started too soon.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ TooSoon,
+ /// <summary>
+ /// Recognition failed because the speech is too short.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ TooShort,
+ /// <summary>
+ /// Recognition failed because the speech is too long.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ TooLong,
+ /// <summary>
+ /// Recognition failed because the speech is too quiet to listen.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ TooQuiet,
+ /// <summary>
+ /// Recognition failed because the speech is too loud to listen.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ TooLoud,
+ /// <summary>
+ /// Recognition failed because the speech is too fast to listen.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ TooFast
+ };
+
+ /// <summary>
+ /// Enumeration for the Token type
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ public enum TimeEvent
+ {
+ /// <summary>
+ /// Event when the token is beginning type
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ Beginning = 0,
+ /// <summary>
+ /// Event when the token is middle type
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ Middle = 1,
+ /// <summary>
+ /// Event when the token is end type
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ End = 2
+ };
+
+ /// <summary>
+ /// Enum for Error values that can occur
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ public enum Error
+ {
+ /// <summary>
+ /// Successful, No error
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ None,
+ /// <summary>
+ /// Out of Memory
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ OutOfMemory,
+ /// <summary>
+ /// I/O error
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ IoError,
+ /// <summary>
+ /// Invalid parameter
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ InvalidParameter,
+ /// <summary>
+ /// No answer from the STT service
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ TimedOut,
+ /// <summary>
+ /// Device or resource busy
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ RecorderBusy,
+ /// <summary>
+ /// Network is down
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ OutOfNetwork,
+ /// <summary>
+ /// Permission denied
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ PermissionDenied,
+ /// <summary>
+ /// STT NOT supported
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ NotSupported,
+ /// <summary>
+ /// Invalid state
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ InvalidState,
+ /// <summary>
+ /// Invalid language
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ InvalidLanguage,
+ /// <summary>
+ /// No available engine
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ EngineNotFound,
+ /// <summary>
+ /// Operation failed
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ OperationFailed,
+ /// <summary>
+ /// Not supported feature of current engine
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ NotSupportedFeature,
+ /// <summary>
+ /// Recording timed out
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ RecordingTimedOut,
+ /// <summary>
+ /// No speech while recording
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ NoSpeech,
+ /// <summary>
+ /// Progress to ready is not finished
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ InProgressToReady,
+ /// <summary>
+ /// Progress to recording is not finished
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ InProgressToRecording,
+ /// <summary>
+ /// Progress to processing is not finished
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ InProgressToProcessing,
+ /// <summary>
+ /// Service reset
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ ServiceReset
+ };
+
+ /// <summary>
+ /// Enumeration for Recognition Types
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ public enum RecognitionType
+ {
+ /// <summary>
+ /// Free form dictation
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ Free,
+ /// <summary>
+ /// Continuous free dictation.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ Partial,
+ /// <summary>
+ /// Search
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ Search,
+ /// <summary>
+ /// Web Search
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ WebSearch,
+ /// <summary>
+ /// Map
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ Map
+ };
+
+ /// <summary>
+ /// Enumeration for the State types
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ public enum State
+ {
+ /// <summary>
+ /// Created state
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ Created = 0,
+ /// <summary>
+ /// Ready state
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ Ready = 1,
+ /// <summary>
+ /// Recording state
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ Recording = 2,
+ /// <summary>
+ /// Processing state
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ Processing = 3,
+ /// <summary>
+ /// Unavailable
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ Unavailable
+ };
+
+ /// <summary>
+ /// Enumeration for the Silence Detection types
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ public enum SilenceDetection
+ {
+ /// <summary>
+ /// Silence detection type - False
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ False = 0,
+ /// <summary>
+ /// Silence detection type - True
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ True = 1,
+ /// <summary>
+ /// Silence detection type - Auto
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ Auto = 2
+ };
+
+ /// <summary>
+ /// A main function of Speech-To-Text (below STT) API recognizes sound data recorded by users.
+ /// After choosing a language, applications will start recording and recognizing.
+ /// After recording, the applications will receive the recognized result.
+ /// The STT has a client-server for the service of multi-applications.
+ /// 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.
+ /// 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.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ public class SttClient : IDisposable
+ {
+ private IntPtr _handle;
+ private Object thisLock = new Object();
+ private event EventHandler<RecognitionResultEventArgs> _recognitionResult;
+ private event EventHandler<StateChangedEventArgs> _stateChanged;
+ private event EventHandler<ErrorOccurredEventArgs> _errorOccurred;
+ private event EventHandler<DefaultLanguageChangedEventArgs> _defaultLanguageChanged;
+ private event EventHandler<EngineChangedEventArgs> _engineChanged;
+ private bool disposedValue = false;
+ private Interop.Stt.RecognitionResultCallback _resultDelegate;
+ private Interop.Stt.StateChangedCallback _stateDelegate;
+ private Interop.Stt.ErrorCallback _errorDelegate;
+ private Interop.Stt.DefaultLanguageChangedCallback _languageDelegate;
+ private Interop.Stt.EngineChangedCallback _engineDelegate;
+ private ResultTime _result;
+ private ResultTimeCallback _resultTimeDelegate;
+
+ /// <summary>
+ /// Constructor to create a STT instance.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <privilege>
+ /// http://tizen.org/privilege/recorder
+ /// </privilege>
+ /// <feature>
+ /// http://tizen.org/feature/speech.recognition
+ /// http://tizen.org/feature/microphone
+ /// </feature>
+ /// <exception cref="InvalidOperationException"> This Exception can be due to Operation Failed. </exception>
+ /// <exception cref="OutOfMemoryException"> This Exception can be due to Out of Memory. </exception>
+ /// <exception cref="NotSupportedException"> This Exception can be due to STT Not Supported. </exception>
+ /// <exception cref="UnauthorizedAccessException"> This Exception can be due to Permission Denied. </exception>
+ public SttClient()
+ {
+ IntPtr handle;
+ SttError error = SttCreate(out handle);
+ if (error != SttError.None)
+ {
+ Log.Error(LogTag, "Create Failed with error " + error);
+ throw ExceptionFactory.CreateException(error);
+ }
+
+ _handle = handle;
+ }
+
+ /// <summary>
+ /// Event to be invoked when the recognition is done.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ public event EventHandler<RecognitionResultEventArgs> RecognitionResult
+ {
+ add
+ {
+ lock (thisLock)
+ {
+ _resultDelegate = (IntPtr handle, ResultEvent e, IntPtr data, int dataCount, IntPtr msg, IntPtr userData) =>
+ {
+ Log.Info(LogTag, "Recognition Result Event Triggered");
+ if (data != null && msg != null)
+ {
+ RecognitionResultEventArgs args = new RecognitionResultEventArgs(e, data, dataCount, Marshal.PtrToStringAnsi(msg));
+ _recognitionResult?.Invoke(this, args);
+ }
+ else
+ {
+ Log.Info(LogTag, "Recognition Result Event null received");
+ }
+ };
+ SttError error = SttSetRecognitionResultCB(_handle, _resultDelegate, IntPtr.Zero);
+ if (error != SttError.None)
+ {
+ Log.Error(LogTag, "Add RecognitionResult Failed with error " + error);
+ }
+ else
+ {
+ _recognitionResult += value;
+ }
+ }
+ }
+
+ remove
+ {
+ lock (thisLock)
+ {
+ SttError error = SttUnsetRecognitionResultCB(_handle);
+ if (error != SttError.None)
+ {
+ Log.Error(LogTag, "Remove RecognitionResult Failed with error " + error);
+ }
+
+ _recognitionResult -= value;
+ }
+ }
+ }
+
+ /// <summary>
+ /// Event to be invoked when STT state changes.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ public event EventHandler<StateChangedEventArgs> StateChanged
+ {
+ add
+ {
+ lock (thisLock)
+ {
+ SttClient obj = this;
+ _stateDelegate = (IntPtr handle, State previous, State current, IntPtr userData) =>
+ {
+ StateChangedEventArgs args = new StateChangedEventArgs(previous, current);
+ _stateChanged?.Invoke(obj, args);
+ };
+ SttError error = SttSetStateChangedCB(_handle, _stateDelegate, IntPtr.Zero);
+ if (error != SttError.None)
+ {
+ Log.Error(LogTag, "Add StateChanged Failed with error " + error);
+ }
+ else
+ {
+ _stateChanged += value;
+ }
+
+ }
+ }
+
+ remove
+ {
+ lock (thisLock)
+ {
+ SttError error = SttUnsetStateChangedCB(_handle);
+ if (error != SttError.None)
+ {
+ Log.Error(LogTag, "Remove StateChanged Failed with error " + error);
+ }
+
+ _stateChanged -= value;
+ }
+ }
+
+ }
+
+ /// <summary>
+ /// Event to be invoked when an error occurs.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ public event EventHandler<ErrorOccurredEventArgs> ErrorOccurred
+ {
+ add
+ {
+ lock (thisLock)
+ {
+ _errorDelegate = (IntPtr handle, SttError reason, IntPtr userData) =>
+ {
+ ErrorOccurredEventArgs args = new ErrorOccurredEventArgs(handle, reason);
+ _errorOccurred?.Invoke(this, args);
+ };
+ SttError error = SttSetErrorCB(_handle, _errorDelegate, IntPtr.Zero);
+ if (error != SttError.None)
+ {
+ Log.Error(LogTag, "Add ErrorOccurred Failed with error " + error);
+ }
+
+ else
+ {
+ _errorOccurred += value;
+ }
+ }
+
+ }
+
+ remove
+ {
+ lock (thisLock)
+ {
+ SttError error = SttUnsetErrorCB(_handle);
+ if (error != SttError.None)
+ {
+ Log.Error(LogTag, "Remove ErrorOccurred Failed with error " + error);
+ }
+
+ _errorOccurred -= value;
+ }
+ }
+ }
+
+ /// <summary>
+ /// Event to be invoked when default language change.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ public event EventHandler<DefaultLanguageChangedEventArgs> DefaultLanguageChanged
+ {
+ add
+ {
+ lock (thisLock)
+ {
+ _languageDelegate = (IntPtr handle, IntPtr previousLanguage, IntPtr currentLanguage, IntPtr userData) =>
+ {
+ string previousLanguageString = Marshal.PtrToStringAnsi(previousLanguage);
+ string currentLanguageString = Marshal.PtrToStringAnsi(currentLanguage);
+ DefaultLanguageChangedEventArgs args = new DefaultLanguageChangedEventArgs(previousLanguageString, currentLanguageString);
+ _defaultLanguageChanged?.Invoke(this, args);
+ };
+ SttError error = SttSetDefaultLanguageChangedCB(_handle, _languageDelegate, IntPtr.Zero);
+ if (error != SttError.None)
+ {
+ Log.Error(LogTag, "Add DefaultLanguageChanged Failed with error " + error);
+ }
+
+ else
+ {
+ _defaultLanguageChanged += value;
+ }
+ }
+
+ }
+
+ remove
+ {
+ lock (thisLock)
+ {
+ SttError error = SttUnsetDefaultLanguageChangedCB(_handle);
+ if (error != SttError.None)
+ {
+ Log.Error(LogTag, "Remove DefaultLanguageChanged Failed with error " + error);
+ }
+
+ _defaultLanguageChanged -= value;
+ }
+ }
+
+ }
+
+ /// <summary>
+ /// Event to be invoked to detect engine change.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ public event EventHandler<EngineChangedEventArgs> EngineChanged
+ {
+ add
+ {
+ lock (thisLock)
+ {
+ _engineDelegate = (IntPtr handle, IntPtr engineId, IntPtr language, bool supportSilence, bool needCredential, IntPtr userData) =>
+ {
+ string engineIdString = Marshal.PtrToStringAnsi(engineId);
+ string languageString = Marshal.PtrToStringAnsi(language);
+ EngineChangedEventArgs args = new EngineChangedEventArgs(engineIdString, languageString, supportSilence, needCredential);
+ _engineChanged?.Invoke(this, args);
+ };
+ SttError error = SttSetEngineChangedCB(_handle, _engineDelegate, IntPtr.Zero);
+ if (error != SttError.None)
+ {
+ Log.Error(LogTag, "Add EngineChanged Failed with error " + error);
+ }
+ else
+ {
+ _engineChanged += value;
+ }
+ }
+ }
+
+ remove
+ {
+ lock (thisLock)
+ {
+ SttError error = SttUnsetEngineChangedCB(_handle);
+ if (error != SttError.None)
+ {
+ Log.Error(LogTag, "Remove EngineChanged Failed with error " + error);
+ }
+
+ _engineChanged -= value;
+ }
+ }
+ }
+
+ /// <summary>
+ /// Gets the default language set by the user.
+ /// 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.
+ /// For example, "ko_KR" for Korean, "en_US" for American English.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <value>
+ /// Default language in STT.
+ /// </value>
+ /// <privilege>
+ /// http://tizen.org/privilege/recorder
+ /// </privilege>
+ /// <returns>
+ /// Default Language string value.
+ /// </returns>
+ public string DefaultLanguage
+ {
+ get
+ {
+ string language;
+ lock (thisLock)
+ {
+ SttError error = SttGetDefaultLanguage(_handle, out language);
+ if (error != SttError.None)
+ {
+ Log.Error(LogTag, "DefaultLanguage Failed with error " + error);
+ return "";
+ }
+ }
+
+ return language;
+ }
+ }
+
+ /// <summary>
+ /// Gets the microphone volume during recording.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <value>
+ /// Recording volume in STT.
+ /// </value>
+ /// <privilege>
+ /// http://tizen.org/privilege/recorder
+ /// </privilege>
+ /// <pre>
+ /// The State must be Recording.
+ /// </pre>
+ public float RecordingVolume
+ {
+ get
+ {
+ float volume;
+ lock (thisLock)
+ {
+ SttError error = SttGetRecordingVolume(_handle, out volume);
+ if (error != SttError.None)
+ {
+ Log.Error(LogTag, "GetRecordingVolume Failed with error " + error);
+ return 0.0f;
+ }
+
+ }
+
+ return volume;
+ }
+
+ }
+
+ /// <summary>
+ /// Gets the current STT state.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <value>
+ /// Current state of STT.
+ /// </value>
+ /// <privilege>
+ /// http://tizen.org/privilege/recorder
+ /// </privilege>
+ /// <returns>
+ /// Current STT State value.
+ /// </returns>
+ public State CurrentState
+ {
+ get
+ {
+ State state;
+ lock (thisLock)
+ {
+ SttError error = SttGetState(_handle, out state);
+ if (error != SttError.None)
+ {
+ Log.Error(LogTag, "GetState Failed with error " + error);
+ return State.Unavailable;
+ }
+ }
+
+ return state;
+ }
+
+ }
+
+ /// <summary>
+ /// This property can be used to get and set the current engine id.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <value>
+ /// Current STT engine id.
+ /// </value>
+ /// <privilege>
+ /// http://tizen.org/privilege/recorder
+ /// </privilege>
+ /// <exception cref="InvalidOperationException">
+ /// This Exception can occur while setting due to the following reasons
+ /// 1. Operation Failed
+ /// 2. Invalid State
+ /// </exception>
+ /// <exception cref="OutOfMemoryException"> This Exception can be due to Out of Memory. </exception>
+ /// <exception cref="NotSupportedException"> This Exception can be due to STT Not Supported. </exception>
+ /// <exception cref="UnauthorizedAccessException"> This Exception can be due to Permission Denied. </exception>
+ /// <exception cref="ArgumentException"> This can happen if Improper EngineId is provided while setting the value. </exception>
+ /// <pre>
+ /// The State must be Created.
+ /// </pre>
+ public string Engine
+ {
+ get
+ {
+ string engineId;
+ lock (thisLock)
+ {
+ SttError error = SttGetEngine(_handle, out engineId);
+ if (error != SttError.None)
+ {
+ Log.Error(LogTag, "Get EngineId Failed with error " + error);
+ return "";
+ }
+ }
+
+ return engineId;
+ }
+ set
+ {
+ lock (thisLock)
+ {
+ SttError error = SttSetEngine(_handle, value);
+ if (error != SttError.None)
+ {
+ Log.Error(LogTag, "Set EngineId Failed with error " + error);
+ throw ExceptionFactory.CreateException(error);
+ }
+ }
+
+ }
+ }
+
+ /// <summary>
+ /// Retrieves the time stamp of the current recognition result
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <returns>
+ /// list of ResultTime
+ /// </returns>
+ /// <privilege>
+ /// http://tizen.org/privilege/recorder
+ /// </privilege>
+ /// <feature>
+ /// http://tizen.org/feature/speech.recognition
+ /// http://tizen.org/feature/microphone
+ /// </feature>
+ /// <remarks>
+ /// This function should only be called in RecognitionResult Event
+ /// </remarks>
+ /// <exception cref="InvalidOperationException"> This Exception can be due to Operation Failed. </exception>
+ /// <exception cref="NotSupportedException"> This Exception can be due to STT Not Supported. </exception>
+ /// <exception cref="UnauthorizedAccessException"> This Exception can be due to Permission Denied. </exception>
+ public IEnumerable<ResultTime> GetDetailedResult()
+ {
+ List<ResultTime> list = new List<ResultTime>();
+ _resultTimeDelegate = (IntPtr handle, int index, TimeEvent e, IntPtr text, IntPtr startTime, IntPtr endTime, IntPtr userData) =>
+ {
+ _result = new ResultTime(index, e, Marshal.PtrToStringAnsi(text), (long)startTime, (long)endTime);
+ list.Add(_result);
+ return true;
+ };
+ SttError error = SttForeachDetailedResult(_handle, _resultTimeDelegate, IntPtr.Zero);
+ if (error != SttError.None)
+ {
+ Log.Error(LogTag, "GetDetailedResult Failed with error " + error);
+ throw ExceptionFactory.CreateException(error);
+ }
+ return list;
+ }
+
+
+ /// <summary>
+ /// Gets the private data from stt engine.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <param name="key">
+ /// The key string
+ /// </param>
+ /// <returns>
+ /// The Data Corresponding to the Key provided
+ /// </returns>
+ /// <privilege>
+ /// http://tizen.org/privilege/recorder
+ /// </privilege>
+ /// <feature>
+ /// http://tizen.org/feature/speech.recognition
+ /// http://tizen.org/feature/microphone
+ /// </feature>
+ /// <exception cref="InvalidOperationException"> This Exception can be due to Invalid State. </exception>
+ /// <exception cref="NotSupportedException"> This Exception can be due to STT Not Supported. </exception>
+ /// <exception cref="TimeoutException"> This Exception can be due to No Answer from STT Service. </exception>
+ /// <pre>
+ /// The State must be Ready.
+ /// </pre>
+ public string GetPrivateData(string key)
+ {
+ string data;
+ lock (thisLock)
+ {
+ SttError error = SttGetPrivateData(_handle, key, out data);
+ if (error != SttError.None)
+ {
+ Log.Error(LogTag, "GetPrivateData Failed with error " + error);
+ throw ExceptionFactory.CreateException(error);
+ }
+ }
+
+ return data;
+ }
+
+ /// <summary>
+ /// Sets the private data to stt engine.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <param name="key">
+ /// The key string
+ /// </param>
+ /// <param name="data">
+ /// The data string
+ /// </param>
+ /// <privilege>
+ /// http://tizen.org/privilege/recorder
+ /// </privilege>
+ /// <feature>
+ /// http://tizen.org/feature/speech.recognition
+ /// http://tizen.org/feature/microphone
+ /// </feature>
+ /// <exception cref="InvalidOperationException"> This Exception can be due to Invalid State. </exception>
+ /// <exception cref="NotSupportedException"> This Exception can be due to STT Not Supported. </exception>
+ /// <exception cref="TimeoutException"> This Exception can be due to No Answer from STT Service. </exception>
+ /// <exception cref="ArgumentException"> This can happen if Improper value is provided while setting the value. </exception>
+ /// <pre>
+ /// The State must be Ready.
+ /// </pre>
+ public void SetPrivateData(string key, string data)
+ {
+ lock (thisLock)
+ {
+ SttError error = SttSetPrivateData(_handle, key, data);
+ if (error != SttError.None)
+ {
+ Log.Error(LogTag, "SetPrivateData Failed with error " + error);
+ throw ExceptionFactory.CreateException(error);
+ }
+ }
+ }
+
+ /// <summary>
+ /// Gets the list of Supported Engine
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <returns>
+ /// IEnumerable<SupportedEngine> list of supported engines
+ /// </returns>
+ /// <privilege>
+ /// http://tizen.org/privilege/recorder
+ /// </privilege>
+ /// <feature>
+ /// http://tizen.org/feature/speech.recognition
+ /// http://tizen.org/feature/microphone
+ /// </feature>
+ /// <exception cref="InvalidOperationException"> This Exception can be due to Operation Failed. </exception>
+ /// <exception cref="OutOfMemoryException"> This Exception can be due to Out of Memory. </exception>
+ /// <exception cref="NotSupportedException"> This Exception can be due to STT Not Supported. </exception>
+ /// <exception cref="UnauthorizedAccessException"> This Exception can be due to Permission Denied. </exception>
+ public IEnumerable<SupportedEngine> GetSupportedEngines()
+ {
+ List<SupportedEngine> engineList = new List<SupportedEngine>();
+ lock (thisLock)
+ {
+ SupportedEngineCallback supportedEngineDelegate = (IntPtr handle, IntPtr engineId, IntPtr engineName, IntPtr userData) =>
+ {
+ string id = Marshal.PtrToStringAnsi(engineId);
+ string name = Marshal.PtrToStringAnsi(engineName);
+ SupportedEngine engine = new SupportedEngine(id, name);
+ engineList.Add(engine);
+ return true;
+ };
+ SttError error = SttForeEachSupportedEngines(_handle, supportedEngineDelegate, IntPtr.Zero);
+ if (error != SttError.None)
+ {
+ Log.Error(LogTag, "Create Failed with error " + error);
+ throw ExceptionFactory.CreateException(error);
+ }
+ }
+
+ return engineList;
+ }
+
+ /// <summary>
+ /// Sets the app credential
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <param name="credential">
+ /// The credential string
+ /// </param>
+ /// <privilege>
+ /// http://tizen.org/privilege/recorder
+ /// </privilege>
+ /// <feature>
+ /// http://tizen.org/feature/speech.recognition
+ /// http://tizen.org/feature/microphone
+ /// </feature>
+ /// <exception cref="InvalidOperationException">
+ /// This Exception can be due to the following reasons
+ /// 1. Operation Failed
+ /// 2. Invalid State
+ /// </exception>
+ /// <exception cref="OutOfMemoryException"> This Exception can be due to Out of Memory. </exception>
+ /// <exception cref="NotSupportedException"> This Exception can be due to STT Not Supported. </exception>
+ /// <exception cref="UnauthorizedAccessException"> This Exception can be due to Permission Denied. </exception>
+ /// <exception cref="ArgumentException"> This can happen if Improper value is provided while setting the value. </exception>
+ /// <pre>
+ /// The State must be Created.
+ /// </pre>
+ public void SetCredential(string credential)
+ {
+ lock (thisLock)
+ {
+ SttError error = SttSetcredential(_handle, credential);
+ if (error != SttError.None)
+ {
+ Log.Error(LogTag, "SetCredential Failed with error " + error);
+ throw ExceptionFactory.CreateException(error);
+ }
+ }
+ }
+
+ /// <summary>
+ /// Connects to the STT service asynchronously.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <privilege>
+ /// http://tizen.org/privilege/recorder
+ /// </privilege>
+ /// <feature>
+ /// http://tizen.org/feature/speech.recognition
+ /// http://tizen.org/feature/microphone
+ /// </feature>
+ /// <exception cref="InvalidOperationException"> This Exception can be due to Invalid State. </exception>
+ /// <exception cref="NotSupportedException"> This Exception can be due to STT Not Supported. </exception>
+ /// <exception cref="UnauthorizedAccessException"> This Exception can be due to Permission Denied. </exception>
+ /// <pre>
+ /// The State must be Created.
+ /// </pre>
+ /// <post>
+ /// If this function is successful, the STT state will be Ready
+ /// If this function is unsuccessful, ErrorOccurred event will be invoked
+ /// </post>
+ public void Prepare()
+ {
+ lock (thisLock)
+ {
+ SttError error = SttPrepare(_handle);
+ if (error != SttError.None)
+ {
+ Log.Error(LogTag, "SetEngine Failed with error " + error);
+ throw ExceptionFactory.CreateException(error);
+ }
+ }
+ }
+
+ /// <summary>
+ /// Disconnects from the STT service.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <privilege>
+ /// http://tizen.org/privilege/recorder
+ /// </privilege>
+ /// <feature>
+ /// http://tizen.org/feature/speech.recognition
+ /// http://tizen.org/feature/microphone
+ /// </feature>
+ /// <exception cref="InvalidOperationException"> This Exception can be due to Invalid State. </exception>
+ /// <exception cref="NotSupportedException"> This Exception can be due to STT Not Supported. </exception>
+ /// <exception cref="UnauthorizedAccessException"> This Exception can be due to Permission Denied. </exception>
+ /// <pre>
+ /// The State must be Ready.
+ /// </pre>
+ /// <post>
+ /// If this function is successful, the STT state will be Created
+ /// </post>
+ public void Unprepare()
+ {
+ lock (thisLock)
+ {
+ SttError error = SttUnprepare(_handle);
+ if (error != SttError.None)
+ {
+ Log.Error(LogTag, "Unprepare Failed with error " + error);
+ throw ExceptionFactory.CreateException(error);
+ }
+ }
+ }
+
+ /// <summary>
+ /// Retrieves all supported languages of current engine.
+ /// 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.
+ /// For example, "ko_KR" for Korean, "en_US" for American English.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <privilege>
+ /// http://tizen.org/privilege/recorder
+ /// </privilege>
+ /// <returns>
+ /// list of strings of supported languages.
+ /// </returns>
+ /// <feature>
+ /// http://tizen.org/feature/speech.recognition
+ /// http://tizen.org/feature/microphone
+ /// </feature>
+ /// <exception cref="InvalidOperationException">
+ /// This Exception can be due to the following reasons
+ /// 1. Engine Not Found.
+ /// 2. Operation Failed.
+ /// </exception>
+ /// <exception cref="NotSupportedException"> This Exception can be due to STT Not Supported. </exception>
+ /// <exception cref="UnauthorizedAccessException"> This Exception can be due to Permission Denied. </exception>
+ public IEnumerable<string> GetSupportedLanguages()
+ {
+ List<string> languageList = new List<string>();
+ lock (thisLock)
+ {
+ SupportedLanguageCallback supportedLanguageDelegate = (IntPtr handle, IntPtr language, IntPtr userData) =>
+ {
+ string lang = Marshal.PtrToStringAnsi(language);
+ languageList.Add(lang);
+ return true;
+ };
+
+ SttError error = SttForeachSupportedLanguages(_handle, supportedLanguageDelegate, IntPtr.Zero);
+ if (error != SttError.None)
+ {
+ Log.Error(LogTag, "GetSupportedLanguages Failed with error " + error);
+ throw ExceptionFactory.CreateException(error);
+ }
+ }
+
+ return languageList;
+ }
+
+ /// <summary>
+ /// Checks whether the recognition type is supported.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <privilege>
+ /// http://tizen.org/privilege/recorder
+ /// </privilege>
+ /// <param name="type">
+ /// RecognitionType value.
+ /// </param>
+ /// <returns>
+ /// bool value indicating whether the recognition type is supported.
+ /// </returns>
+ /// <feature>
+ /// http://tizen.org/feature/speech.recognition
+ /// http://tizen.org/feature/microphone
+ /// </feature>
+ /// <exception cref="InvalidOperationException">
+ /// This Exception can be due to the following reasons
+ /// 1. Invalid State
+ /// 2. Engine Not Found.
+ /// 3. Operation Failed.
+ /// </exception>
+ /// <exception cref="NotSupportedException"> This Exception can be due to STT Not Supported. </exception>
+ /// <pre>
+ /// The state should be Ready.
+ /// </pre>
+ public bool IsRecognitionTypeSupported(RecognitionType type)
+ {
+ bool supported;
+ lock (thisLock)
+ {
+ string recType = "stt.recognition.type.FREE";
+ switch (type)
+ {
+ case RecognitionType.Free:
+ {
+ recType = "stt.recognition.type.FREE";
+ break;
+ }
+
+ case RecognitionType.Partial:
+ {
+ recType = "stt.recognition.type.FREE.PARTIAL";
+ break;
+ }
+
+ case RecognitionType.Search:
+ {
+ recType = "stt.recognition.type.SEARCH";
+ break;
+ }
+
+ case RecognitionType.WebSearch:
+ {
+ recType = "stt.recognition.type.WEB_SEARCH";
+ break;
+ }
+
+ case RecognitionType.Map:
+ {
+ recType = "stt.recognition.type.MAP";
+ break;
+ }
+
+ }
+
+ SttError error = SttIsRecognitionTypeSupported(_handle, recType, out supported);
+ if (error != SttError.None)
+ {
+ Log.Error(LogTag, "IsRecognitionTypeSupported Failed with error " + error);
+ throw ExceptionFactory.CreateException(error);
+ }
+
+ }
+
+ return supported;
+ }
+
+ /// <summary>
+ /// Sets the silence detection.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <privilege>
+ /// http://tizen.org/privilege/recorder
+ /// </privilege>
+ /// <param name="type">
+ /// SilenceDetection value.
+ /// </param>
+ /// <feature>
+ /// http://tizen.org/feature/speech.recognition
+ /// http://tizen.org/feature/microphone
+ /// </feature>
+ /// <exception cref="InvalidOperationException">
+ /// This Exception can be due to the following reasons
+ /// 1. Invalid State
+ /// 2. Not supported feature of current engine.
+ /// 3. Operation Failed.
+ /// </exception>
+ /// <exception cref="NotSupportedException"> This Exception can be due to STT Not Supported. </exception>
+ /// <pre>
+ /// The state should be Ready.
+ /// </pre>
+ public void SetSilenceDetection(SilenceDetection type)
+ {
+ lock (thisLock)
+ {
+ SttError error = SttSetSilenceDetection(_handle, type);
+ if (error != SttError.None)
+ {
+ Log.Error(LogTag, "SetSilenceDetection Failed with error " + error);
+ throw ExceptionFactory.CreateException(error);
+ }
+ }
+ }
+
+ /// <summary>
+ /// Sets the sound to start recording.
+ /// Sound file type should be wav type.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <privilege>
+ /// http://tizen.org/privilege/recorder
+ /// </privilege>
+ /// <param name="filePath">
+ /// File Path for the sound.
+ /// </param>
+ /// <feature>
+ /// http://tizen.org/feature/speech.recognition
+ /// http://tizen.org/feature/microphone
+ /// </feature>
+ /// <exception cref="InvalidOperationException">
+ /// This Exception can be due to the following reasons
+ /// 1. Invalid State.
+ /// 2. Operation Failed.
+ /// </exception>
+ /// <exception cref="NotSupportedException"> This Exception can be due to STT Not Supported. </exception>
+ /// <exception cref="UnauthorizedAccessException"> This Exception can be due to Permission Denied. </exception>
+ /// <exception cref="ArgumentException"> If an Invalid Parameter is provided. </exception>
+ /// <pre>
+ /// The state should be Ready.
+ /// </pre>
+ public void SetStartSound(string filePath)
+ {
+ lock (thisLock)
+ {
+ SttError error = SttSetStartSound(_handle, filePath);
+ if (error != SttError.None)
+ {
+ Log.Error(LogTag, "SetStartSound Failed with error " + error);
+ throw ExceptionFactory.CreateException(error);
+ }
+ }
+ }
+
+ /// <summary>
+ /// Unsets the sound to start recording.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <privilege>
+ /// http://tizen.org/privilege/recorder
+ /// </privilege>
+ /// <feature>
+ /// http://tizen.org/feature/speech.recognition
+ /// http://tizen.org/feature/microphone
+ /// </feature>
+ /// <exception cref="InvalidOperationException">
+ /// This Exception can be due to the following reasons
+ /// 1. Invalid State.
+ /// 2. Operation Failed.
+ /// </exception>
+ /// <exception cref="NotSupportedException"> This Exception can be due to STT Not Supported. </exception>
+ /// <exception cref="UnauthorizedAccessException"> This Exception can be due to Permission Denied. </exception>
+ /// <pre>
+ /// The state should be Ready.
+ /// </pre>
+ public void UnsetStartSound()
+ {
+ lock (thisLock)
+ {
+ SttError error = SttUnsetStartSound(_handle);
+ if (error != SttError.None)
+ {
+ Log.Error(LogTag, "UnsetStartSound Failed with error " + error);
+ throw ExceptionFactory.CreateException(error);
+ }
+ }
+ }
+
+ /// <summary>
+ /// Sets the sound to stop recording.
+ /// Sound file type should be wav type.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <privilege>
+ /// http://tizen.org/privilege/recorder
+ /// </privilege>
+ /// <param name="filePath">
+ /// File Path for the sound.
+ /// </param>
+ /// <feature>
+ /// http://tizen.org/feature/speech.recognition
+ /// http://tizen.org/feature/microphone
+ /// </feature>
+ /// <exception cref="InvalidOperationException">
+ /// This Exception can be due to the following reasons
+ /// 1. Invalid State.
+ /// 2. Operation Failed.
+ /// </exception>
+ /// <exception cref="NotSupportedException"> This Exception can be due to STT Not Supported. </exception>
+ /// <exception cref="UnauthorizedAccessException"> This Exception can be due to Permission Denied. </exception>
+ /// <exception cref="ArgumentException"> If an Invalid Parameter is provided. </exception>
+ /// <pre>
+ /// The state should be Ready.
+ /// </pre>
+ public void SetStopSound(string filePath)
+ {
+ lock (thisLock)
+ {
+ SttError error = SttSetStopSound(_handle, filePath);
+ if (error != SttError.None)
+ {
+ Log.Error(LogTag, "SetStopSound Failed with error " + error);
+ throw ExceptionFactory.CreateException(error);
+ }
+ }
+ }
+
+ /// <summary>
+ /// Unsets the sound to stop recording.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <privilege>
+ /// http://tizen.org/privilege/recorder
+ /// </privilege>
+ /// <feature>
+ /// http://tizen.org/feature/speech.recognition
+ /// http://tizen.org/feature/microphone
+ /// </feature>
+ /// <exception cref="InvalidOperationException">
+ /// This Exception can be due to the following reasons
+ /// 1. Invalid State.
+ /// 2. Operation Failed.
+ /// </exception>
+ /// <exception cref="NotSupportedException"> This Exception can be due to STT Not Supported. </exception>
+ /// <exception cref="UnauthorizedAccessException"> This Exception can be due to Permission Denied. </exception>
+ /// <pre>
+ /// The state should be Ready.
+ /// </pre>
+ public void UnsetStopSound()
+ {
+ lock (thisLock)
+ {
+ SttError error = SttUnsetStopSound(_handle);
+ if (error != SttError.None)
+ {
+ Log.Error(LogTag, "UnsetStopSound Failed with error " + error);
+ throw ExceptionFactory.CreateException(error);
+ }
+ }
+ }
+
+ /// <summary>
+ /// Starts recording and recognition asynchronously.
+ /// This function starts recording in the STT service and sending recording data to engine.
+ /// This work continues until Stop, Cancel or silence detected by engine
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <privilege>
+ /// http://tizen.org/privilege/recorder
+ /// </privilege>
+ /// <param name="language">
+ /// The language selected
+ /// </param>
+ /// <param name="type">
+ /// The type for recognition
+ /// </param>
+ /// <feature>
+ /// http://tizen.org/feature/speech.recognition
+ /// http://tizen.org/feature/microphone
+ /// </feature>
+ /// <exception cref="InvalidOperationException">
+ /// This Exception can be due to the following reasons
+ /// 1. Invalid State.
+ /// 2. Operation Failed.
+ /// 3. Recorder Busy.
+ /// 4. Progress to recording is not finished
+ /// </exception>
+ /// <exception cref="NotSupportedException"> This Exception can be due to STT Not Supported. </exception>
+ /// <exception cref="UnauthorizedAccessException"> This Exception can be due to Permission Denied. </exception>
+ /// <exception cref="ArgumentException"> If an Invalid Language is provided. </exception>
+ /// <pre>
+ /// The state should be Ready.
+ /// </pre>
+ /// <post>
+ /// It will invoke StateChanged Event if registered.
+ /// If this function succeeds, the STT state will be Recording.
+ /// If you call this function again before state changes, you will receive ErrorINProgressToRecording.
+ /// </post>
+ public void Start(string language, RecognitionType type)
+ {
+ lock (thisLock)
+ {
+ string recType = "stt.recognition.type.FREE";
+ switch (type)
+ {
+ case RecognitionType.Free:
+ {
+ recType = "stt.recognition.type.FREE";
+ break;
+ }
+
+ case RecognitionType.Partial:
+ {
+ recType = "stt.recognition.type.FREE.PARTIAL";
+ break;
+ }
+
+ case RecognitionType.Search:
+ {
+ recType = "stt.recognition.type.SEARCH";
+ break;
+ }
+
+ case RecognitionType.WebSearch:
+ {
+ recType = "stt.recognition.type.WEB_SEARCH";
+ break;
+ }
+
+ case RecognitionType.Map:
+ {
+ recType = "stt.recognition.type.MAP";
+ break;
+ }
+
+ }
+
+ SttError error = SttStart(_handle, language, recType);
+ if (error != SttError.None)
+ {
+ Log.Error(LogTag, "Start Failed with error " + error);
+ throw ExceptionFactory.CreateException(error);
+ }
+ }
+ }
+
+ /// <summary>
+ /// Finishes the recording and starts recognition processing in engine asynchronously.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <privilege>
+ /// http://tizen.org/privilege/recorder
+ /// </privilege>
+ /// <feature>
+ /// http://tizen.org/feature/speech.recognition
+ /// http://tizen.org/feature/microphone
+ /// </feature>
+ /// <exception cref="InvalidOperationException">
+ /// This Exception can be due to the following reasons
+ /// 1. Invalid State.
+ /// 2. Operation Failed.
+ /// 3. Progress to ready is not finished.
+ /// 4. Progress to recording is not finished.
+ /// 5. Progress to processing is not finished.
+ /// </exception>
+ /// <exception cref="NotSupportedException"> This Exception can be due to STT Not Supported. </exception>
+ /// <exception cref="UnauthorizedAccessException"> This Exception can be due to Permission Denied. </exception>
+ /// <pre>
+ /// The state should be Recording.
+ /// </pre>
+ /// <post>
+ /// It will invoke StateChanged Event if registered.
+ /// If this function succeeds, the STT state will be Processing.
+ /// If you call this function again before state changes, you will receive ErrorINProgressToProcessing.
+ /// After processing of engine, RecognitionResult event is invoked
+ /// </post>
+ public void Stop()
+ {
+ lock (thisLock)
+ {
+ SttError error = SttStop(_handle);
+ if (error != SttError.None)
+ {
+ Log.Error(LogTag, "Stop Failed with error " + error);
+ throw ExceptionFactory.CreateException(error);
+ }
+ }
+ }
+
+ /// <summary>
+ /// Cancels processing recognition and recording asynchronously.
+ /// This function cancels recording and engine cancels recognition processing.
+ /// After successful cancel, StateChanged event is invoked otherwise if error is occurred, ErrorOccurred event is invoked.
+ /// </summary>
+ /// <since_tizen> 3 </since_tizen>
+ /// <privilege>
+ /// http://tizen.org/privilege/recorder
+ /// </privilege>
+ /// <feature>
+ /// http://tizen.org/feature/speech.recognition
+ /// http://tizen.org/feature/microphone
+ /// </feature>
+ /// <exception cref="InvalidOperationException">
+ /// This Exception can be due to the following reasons
+ /// 1. Invalid State.
+ /// 2. Operation Failed.
+ /// 3. Progress to ready is not finished.
+ /// 4. Progress to recording is not finished.
+ /// 5. Progress to processing is not finished.
+ /// </exception>
+ /// <exception cref="NotSupportedException"> This Exception can be due to STT Not Supported. </exception>
+ /// <exception cref="UnauthorizedAccessException"> This Exception can be due to Permission Denied. </exception>
+ /// <pre>
+ /// The state should be Recording or Processing.
+ /// </pre>
+ /// <post>
+ /// It will invoke StateChanged Event if registered.
+ /// If this function succeeds, the STT state will be Ready.
+ /// If you call this function again before state changes, you will receive ErrorINProgressToReady.
+ /// </post>
+ public void Cancel()
+ {
+ lock (thisLock)
+ {
+ SttError error = SttCancel(_handle);
+ if (error != SttError.None)
+ {
+ Log.Error(LogTag, "Cancel Failed with error " + error);
+ throw ExceptionFactory.CreateException(error);
+ }
+ }
+ }
+
+ /// <summary>
+ /// Method to release resources
+ /// </summary>
+ public void Dispose()
+ {
+ Dispose(true);
+ }
+
+ protected virtual void Dispose(bool disposing)
+ {
+ if (!disposedValue)
+ {
+ if (disposing)
+ {
+ SttError error = SttDestroy(_handle);
+ if (error != SttError.None)
+ {
+ Log.Error(LogTag, "Destroy Failed with error " + error);
+ }
+ }
+
+ disposedValue = true;
+ }
+ }
+ }
+}