/* * 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 { /// /// The token event /// /// 3 public enum ResultEvent { /// /// Event when the recognition full or last result is ready /// /// 3 FinalResult = 0, /// /// Event when the recognition partial result is ready /// /// 3 PartialResult, /// /// Event when the recognition has failed /// /// 3 Error }; /// /// Enumeration representing the result message /// /// 3 public enum ResultMessage { /// /// No Error /// /// 3 None, /// /// Recognition failed because the speech started too soon. /// /// 3 TooSoon, /// /// Recognition failed because the speech is too short. /// /// 3 TooShort, /// /// Recognition failed because the speech is too long. /// /// 3 TooLong, /// /// Recognition failed because the speech is too quiet to listen. /// /// 3 TooQuiet, /// /// Recognition failed because the speech is too loud to listen. /// /// 3 TooLoud, /// /// Recognition failed because the speech is too fast to listen. /// /// 3 TooFast }; /// /// Enumeration for the Token type /// /// 3 public enum TimeEvent { /// /// Event when the token is beginning type /// /// 3 Beginning = 0, /// /// Event when the token is middle type /// /// 3 Middle = 1, /// /// Event when the token is end type /// /// 3 End = 2 }; /// /// Enum for Error values that can occur /// /// 3 public enum Error { /// /// Successful, No error /// /// 3 None, /// /// Out of Memory /// /// 3 OutOfMemory, /// /// I/O error /// /// 3 IoError, /// /// Invalid parameter /// /// 3 InvalidParameter, /// /// No answer from the STT service /// /// 3 TimedOut, /// /// Device or resource busy /// /// 3 RecorderBusy, /// /// Network is down /// /// 3 OutOfNetwork, /// /// Permission denied /// /// 3 PermissionDenied, /// /// STT NOT supported /// /// 3 NotSupported, /// /// Invalid state /// /// 3 InvalidState, /// /// Invalid language /// /// 3 InvalidLanguage, /// /// No available engine /// /// 3 EngineNotFound, /// /// Operation failed /// /// 3 OperationFailed, /// /// Not supported feature of current engine /// /// 3 NotSupportedFeature, /// /// Recording timed out /// /// 3 RecordingTimedOut, /// /// No speech while recording /// /// 3 NoSpeech, /// /// Progress to ready is not finished /// /// 3 InProgressToReady, /// /// Progress to recording is not finished /// /// 3 InProgressToRecording, /// /// Progress to processing is not finished /// /// 3 InProgressToProcessing, /// /// Service reset /// /// 3 ServiceReset }; /// /// Enumeration for Recognition Types /// /// 3 public enum RecognitionType { /// /// Free form dictation /// /// 3 Free, /// /// Continuous free dictation. /// /// 3 Partial, /// /// Search /// /// 3 Search, /// /// Web Search /// /// 3 WebSearch, /// /// Map /// /// 3 Map }; /// /// Enumeration for the State types /// /// 3 public enum State { /// /// Created state /// /// 3 Created = 0, /// /// Ready state /// /// 3 Ready = 1, /// /// Recording state /// /// 3 Recording = 2, /// /// Processing state /// /// 3 Processing = 3, /// /// Unavailable /// /// 3 Unavailable }; /// /// Enumeration for the Silence Detection types /// /// 3 public enum SilenceDetection { /// /// Silence detection type - False /// /// 3 False = 0, /// /// Silence detection type - True /// /// 3 True = 1, /// /// Silence detection type - Auto /// /// 3 Auto = 2 }; /// /// 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. /// /// 3 public class SttClient : IDisposable { private IntPtr _handle; private Object thisLock = new Object(); private event EventHandler _recognitionResult; private event EventHandler _stateChanged; private event EventHandler _errorOccured; private event EventHandler _defaultLanguageChanged; private event EventHandler _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; /// /// Constructor to create a STT instance. /// /// 3 /// /// http://tizen.org/privilege/recorder /// /// /// http://tizen.org/feature/speech.recognition /// http://tizen.org/feature/microphone /// /// This Exception can be due to Operation Failed. /// This Exception can be due to Out of Memory. /// This Exception can be due to STT Not Supported. /// This Exception can be due to Permission Denied. 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; } /// /// Event to be invoked when the recognition is done. /// /// 3 public event EventHandler 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; } } } /// /// Event to be invoked when STT state changes. /// /// 3 public event EventHandler 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; } } } /// /// Event to be invoked when an error occurs. /// /// 3 public event EventHandler ErrorOccured { add { lock (thisLock) { _errorDelegate = (IntPtr handle, SttError reason, IntPtr userData) => { ErrorOccuredEventArgs args = new ErrorOccuredEventArgs(handle, reason); _errorOccured?.Invoke(this, args); }; SttError error = SttSetErrorCB(_handle, _errorDelegate, IntPtr.Zero); if (error != SttError.None) { Log.Error(LogTag, "Add ErrorOccured Failed with error " + error); } else { _errorOccured += value; } } } remove { lock (thisLock) { SttError error = SttUnsetErrorCB(_handle); if (error != SttError.None) { Log.Error(LogTag, "Remove ErrorOccured Failed with error " + error); } _errorOccured -= value; } } } /// /// Event to be invoked when default laungage change. /// /// 3 public event EventHandler 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; } } } /// /// Event to be invoked to detect engine change. /// /// 3 public event EventHandler 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; } } } /// /// 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. /// /// 3 /// /// Default language in STT. /// /// /// http://tizen.org/privilege/recorder /// /// /// Default Lanaguage string value. /// public string DefaultLanguage { get { string language; lock (thisLock) { SttError error = SttGetDefaultLanguage(_handle, out language); if (error != SttError.None) { Log.Error(LogTag, "DefaultLanaguage Failed with error " + error); return ""; } } return language; } } /// /// Gets the microphone volume during recording. /// /// 3 /// /// Recording volume in STT. /// /// /// http://tizen.org/privilege/recorder /// ///
        /// The State must be Recording.
        /// 
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; } } /// /// Gets the current STT state. /// /// 3 /// /// Current state of STT. /// /// /// http://tizen.org/privilege/recorder /// /// /// Current STT State value. /// 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; } } /// /// This property can be used to get and set the current engine id. /// /// 3 /// /// Current STT engine id. /// /// /// http://tizen.org/privilege/recorder /// /// /// This Exception can occur while setting due to the following reaons /// 1. Operation Failed /// 2. Invalid State /// /// This Exception can be due to Out of Memory. /// This Exception can be due to STT Not Supported. /// This Exception can be due to Permission Denied. /// This can happen if Improper EngineId is provided while setting the value. ///
        /// The State must be Created.
        /// 
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); } } } } /// /// Retrieves the time stamp of the current recognition result /// /// 3 /// /// list of ResultTime /// /// /// http://tizen.org/privilege/recorder /// /// /// http://tizen.org/feature/speech.recognition /// http://tizen.org/feature/microphone /// /// /// This function should only be called in RecognitionResult Event /// /// This Exception can be due to Opearation Failed. /// This Exception can be due to STT Not Supported. /// This Exception can be due to Permission Denied. public IEnumerable GetDetailedResult() { List list = new List(); _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; } /// /// Gets the private data from stt engine. /// /// 3 /// /// The key string /// /// /// The Data Corresponding to the Key provided /// /// /// http://tizen.org/privilege/recorder /// /// /// http://tizen.org/feature/speech.recognition /// http://tizen.org/feature/microphone /// /// This Exception can be due to Invalid State. /// This Exception can be due to STT Not Supported. /// This Exception can be due to No Answer from STT Service. ///
        /// The State must be Ready.
        /// 
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; } /// /// Sets the private data to stt engine. /// /// 3 /// /// The key string /// /// /// The data string /// /// /// http://tizen.org/privilege/recorder /// /// /// http://tizen.org/feature/speech.recognition /// http://tizen.org/feature/microphone /// /// This Exception can be due to Invalid State. /// This Exception can be due to STT Not Supported. /// This Exception can be due to No Answer from STT Service. /// This can happen if Improper value is provided while setting the value. ///
        /// The State must be Ready.
        /// 
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); } } } /// /// Gets the list of Supported Engine /// /// 3 /// /// IEnumerable list of supported engines /// /// /// http://tizen.org/privilege/recorder /// /// /// http://tizen.org/feature/speech.recognition /// http://tizen.org/feature/microphone /// /// This Exception can be due to Operation Failed. /// This Exception can be due to Out of Memory. /// This Exception can be due to STT Not Supported. /// This Exception can be due to Permission Denied. public IEnumerable GetSupportedEngines() { List engineList = new List(); 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; } /// /// Sets the app credential /// /// 3 /// /// The credential string /// /// /// http://tizen.org/privilege/recorder /// /// /// http://tizen.org/feature/speech.recognition /// http://tizen.org/feature/microphone /// /// /// This Exception can be due to the following reaons /// 1. Operation Failed /// 2. Invalid State /// /// This Exception can be due to Out of Memory. /// This Exception can be due to STT Not Supported. /// This Exception can be due to Permission Denied. /// This can happen if Improper value is provided while setting the value. ///
        /// The State must be Created.
        /// 
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); } } } /// /// Connects to the STT service asynchronously. /// /// 3 /// /// http://tizen.org/privilege/recorder /// /// /// http://tizen.org/feature/speech.recognition /// http://tizen.org/feature/microphone /// /// This Exception can be due to Invalid State. /// This Exception can be due to STT Not Supported. /// This Exception can be due to Permission Denied. ///
        /// The State must be Created.
        /// 
/// /// If this function is successful, the STT state will be Ready /// If this function is unsuccessful, ErrorOccured event will be invoked /// 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); } } } /// /// Disconnects from the STT service. /// /// 3 /// /// http://tizen.org/privilege/recorder /// /// /// http://tizen.org/feature/speech.recognition /// http://tizen.org/feature/microphone /// /// This Exception can be due to Invalid State. /// This Exception can be due to STT Not Supported. /// This Exception can be due to Permission Denied. ///
        /// The State must be Ready.
        /// 
/// /// If this function is successful, the STT state will be Created /// 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); } } } /// /// 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. /// /// 3 /// /// http://tizen.org/privilege/recorder /// /// /// list of strings of supported languages. /// /// /// http://tizen.org/feature/speech.recognition /// http://tizen.org/feature/microphone /// /// /// This Exception can be due to the following reasons /// 1. Engine Not Found. /// 2. Operation Failed. /// /// This Exception can be due to STT Not Supported. /// This Exception can be due to Permission Denied. public IEnumerable GetSupportedLangauages() { List languageList = new List(); 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, "GetSupportedLangauages Failed with error " + error); throw ExceptionFactory.CreateException(error); } } return languageList; } /// /// Checks whether the recognition type is supported. /// /// 3 /// /// http://tizen.org/privilege/recorder /// /// /// RecognitionType value. /// /// /// bool value indicating whether the recognition type is supported. /// /// /// http://tizen.org/feature/speech.recognition /// http://tizen.org/feature/microphone /// /// /// This Exception can be due to the following reasons /// 1. Invalid State /// 2. Engine Not Found. /// 3. Operation Failed. /// /// This Exception can be due to STT Not Supported. ///
        /// The state should be Ready.
        /// 
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; } /// /// Sets the silence detection. /// /// 3 /// /// http://tizen.org/privilege/recorder /// /// /// SilenceDetection value. /// /// /// http://tizen.org/feature/speech.recognition /// http://tizen.org/feature/microphone /// /// /// This Exception can be due to the following reasons /// 1. Invalid State /// 2. Not supported feature of current engine. /// 3. Operation Failed. /// /// This Exception can be due to STT Not Supported. ///
        /// The state should be Ready.
        /// 
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); } } } /// /// Sets the sound to start recording. /// Sound file type should be wav type. /// /// 3 /// /// http://tizen.org/privilege/recorder /// /// /// File Path for the sound. /// /// /// http://tizen.org/feature/speech.recognition /// http://tizen.org/feature/microphone /// /// /// This Exception can be due to the following reasons /// 1. Invalid State. /// 2. Operation Failed. /// /// This Exception can be due to STT Not Supported. /// This Exception can be due to Permission Denied. /// If an Invalid Parameter is provided. ///
        /// The state should be Ready.
        /// 
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); } } } /// /// Unsets the sound to start recording. /// /// 3 /// /// http://tizen.org/privilege/recorder /// /// /// http://tizen.org/feature/speech.recognition /// http://tizen.org/feature/microphone /// /// /// This Exception can be due to the following reasons /// 1. Invalid State. /// 2. Operation Failed. /// /// This Exception can be due to STT Not Supported. /// This Exception can be due to Permission Denied. ///
        /// The state should be Ready.
        /// 
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); } } } /// /// Sets the sound to stop recording. /// Sound file type should be wav type. /// /// 3 /// /// http://tizen.org/privilege/recorder /// /// /// File Path for the sound. /// /// /// http://tizen.org/feature/speech.recognition /// http://tizen.org/feature/microphone /// /// /// This Exception can be due to the following reasons /// 1. Invalid State. /// 2. Operation Failed. /// /// This Exception can be due to STT Not Supported. /// This Exception can be due to Permission Denied. /// If an Invalid Parameter is provided. ///
        /// The state should be Ready.
        /// 
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); } } } /// /// Unsets the sound to stop recording. /// /// 3 /// /// http://tizen.org/privilege/recorder /// /// /// http://tizen.org/feature/speech.recognition /// http://tizen.org/feature/microphone /// /// /// This Exception can be due to the following reasons /// 1. Invalid State. /// 2. Operation Failed. /// /// This Exception can be due to STT Not Supported. /// This Exception can be due to Permission Denied. ///
        /// The state should be Ready.
        /// 
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); } } } /// /// 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 /// /// 3 /// /// http://tizen.org/privilege/recorder /// /// /// The language selected /// /// /// The type for recognition /// /// /// http://tizen.org/feature/speech.recognition /// http://tizen.org/feature/microphone /// /// /// 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 /// /// This Exception can be due to STT Not Supported. /// This Exception can be due to Permission Denied. /// If an Invalid Language is provided. ///
        /// The state should be Ready.
        /// 
/// /// It will invoke StateChanged Event if registerd. /// If this function succeeds, the STT state will be Recording. /// If you call this function again before state changes, you will receive ErrorINProgressToRecording. /// 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); } } } /// /// Finishes the recording and starts recognition processing in engine asynchronously. /// /// 3 /// /// http://tizen.org/privilege/recorder /// /// /// http://tizen.org/feature/speech.recognition /// http://tizen.org/feature/microphone /// /// /// 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. /// /// This Exception can be due to STT Not Supported. /// This Exception can be due to Permission Denied. ///
        /// The state should be Recording.
        /// 
/// /// It will invoke StateChanged Event if registerd. /// 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 /// 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); } } } /// /// 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, ErrorOccured event is invoked. /// /// 3 /// /// http://tizen.org/privilege/recorder /// /// /// http://tizen.org/feature/speech.recognition /// http://tizen.org/feature/microphone /// /// /// 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. /// /// This Exception can be due to STT Not Supported. /// This Exception can be due to Permission Denied. ///
        /// The state should be Recording or Processing.
        /// 
/// /// It will invoke StateChanged Event if registerd. /// If this function succeeds, the STT state will be Ready. /// If you call this function again before state changes, you will receive ErrorINProgressToReady. /// 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); } } } /// /// Method to release resources /// 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; } } } }