From: manish.r Date: Mon, 15 May 2017 11:49:41 +0000 (+0530) Subject: Modification of GetResult API X-Git-Tag: submit/trunk/20170823.075128~68^2~8 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=01be120fd6496bac7f52a7287bbc82283166b240;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git Modification of GetResult API Change-Id: Iabf8ccb6ba1e8496fcf65248613012498d34b569 Signed-off-by: manish.r --- diff --git a/src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl.csproj b/src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl.csproj index ce235f0..1b581ca 100755 --- a/src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl.csproj +++ b/src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl.csproj @@ -48,6 +48,7 @@ + diff --git a/src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl/RecognitionResult.cs b/src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl/RecognitionResult.cs new file mode 100755 index 0000000..4fb5ea8 --- /dev/null +++ b/src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl/RecognitionResult.cs @@ -0,0 +1,78 @@ +/* +* 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.VoiceControl; +using static Interop.VoiceControlCommand; + +namespace Tizen.Uix.VoiceControl +{ + /// + /// The recognition result from the engine. + /// If the duplicated commands are recognized, the event(e.g. Result.Rejected) of command may be rejected + /// for selecting command as priority.If you set similar or same commands or the recognized results are multi-results, CommandList has the multi commands. + /// + public class RecognitionResult + { + private ResultEvent _resultEvent; + private VoiceCommandList _list; + private string _result; + + internal RecognitionResult(ResultEvent evt, IntPtr cmdList, IntPtr result) + { + _resultEvent = evt; + SafeCommandListHandle handle = new SafeCommandListHandle(cmdList); + _list = new VoiceCommandList(handle); + _result = Marshal.PtrToStringAnsi(result); + } + + /// + /// The result event + /// + public ResultEvent Result + { + get + { + return _resultEvent; + } + } + + /// + /// The spoken text + /// + public string ResultMessage + { + get + { + return _result; + } + } + + + /// + /// The recognized command list + /// + public VoiceCommandList CommandList + { + get + { + return _list; + } + } + } +} diff --git a/src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl/RecognitionResultEventArgs.cs b/src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl/RecognitionResultEventArgs.cs index ab764b0..e81bde5 100755 --- a/src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl/RecognitionResultEventArgs.cs +++ b/src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl/RecognitionResultEventArgs.cs @@ -15,47 +15,24 @@ */ using System; -using System.Collections.Generic; -using System.Runtime.InteropServices; -using static Interop.VoiceControl; -using static Interop.VoiceControlCommand; namespace Tizen.Uix.VoiceControl { /// /// The recognition result from the engine. - /// If the duplicated commands are recognized, the event(e.g. Result.Rejected) of command may be rejected - /// for selecting command as priority.If you set similar or same commands or the recognized results are multi-results, CommandList has the multi commands. /// - public class RecognitionResultEventArgs + public class RecognitionResultEventArgs : EventArgs { - private ResultEvent _resultEvent; - private VoiceCommandList _list; - private string _result; - - internal RecognitionResultEventArgs(ResultEvent evt, IntPtr cmdList, IntPtr result) + private RecognitionResult _result; + internal RecognitionResultEventArgs(RecognitionResult result) { - _resultEvent = evt; - SafeCommandListHandle handle = new SafeCommandListHandle(cmdList); - _list = new VoiceCommandList(handle); - _result = Marshal.PtrToStringAnsi(result); - } - - /// - /// The result event - /// - public ResultEvent Result - { - get - { - return _resultEvent; - } + _result = result; } /// - /// The spoken text + /// Gets the Recognition result /// - public string ResultMessage + public RecognitionResult Result { get { @@ -63,16 +40,5 @@ namespace Tizen.Uix.VoiceControl } } - - /// - /// The recognized command list - /// - public VoiceCommandList CommandList - { - get - { - return _list; - } - } } } diff --git a/src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl/VoiceControlClient.cs b/src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl/VoiceControlClient.cs index b395f47..f9d689a 100755 --- a/src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl/VoiceControlClient.cs +++ b/src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl/VoiceControlClient.cs @@ -220,6 +220,7 @@ namespace Tizen.Uix.VoiceControl private static List s_supportedLanguages; private static VcSupportedLanguageCb s_supportedLanguagesCb; private static VcResultCb s_resultCb; + private static RecognitionResult s_recognitionResult; /// /// Gets current language. @@ -496,7 +497,7 @@ namespace Tizen.Uix.VoiceControl /// /// The State should be Ready or Initialized /// - public static IEnumerable GetSupportedLangauges() + public static IEnumerable GetSupportedLanguages() { s_supportedLanguages = new List(); s_supportedLanguagesCb = (IntPtr language, IntPtr userData) => @@ -508,7 +509,7 @@ namespace Tizen.Uix.VoiceControl ErrorCode error = VcForeachSupportedLanguages(s_supportedLanguagesCb, IntPtr.Zero); if (error != ErrorCode.None) { - Log.Error(LogTag, "GetSupportedLangauges Failed with error " + error); + Log.Error(LogTag, "GetSupportedLanguages Failed with error " + error); throw ExceptionFactory.CreateException(error); } @@ -542,7 +543,7 @@ namespace Tizen.Uix.VoiceControl /// /// The State should be Ready /// - public static VoiceCommandList GetSytemCommandList() + public static VoiceCommandList GetSystemCommandList() { IntPtr handle = IntPtr.Zero; ErrorCode error = VcGetSystemCommandList(out handle); @@ -702,22 +703,19 @@ namespace Tizen.Uix.VoiceControl /// http://tizen.org/feature/speech.control /// http://tizen.org/feature/microphone /// - /// - /// Callback function to get recognition result - /// /// This Exception can be due to Invalid State. /// This Exception can be due to Invalid Parameter. /// This Exception can be due to Not Supported. + /// The Recognition Result if possible else a null object /// /// The State should be Ready /// - public static void GetResult(RecognitionResultDelegate resultDelegate) + public static RecognitionResult GetResult() { + s_recognitionResult = null; s_resultCb = (ResultEvent evt, IntPtr cmdList, IntPtr result, IntPtr userData) => { - VoiceCommandList list = new VoiceCommandList(new SafeCommandListHandle(cmdList)); - string resultStr = Marshal.PtrToStringAnsi(result); - resultDelegate(evt, list, resultStr); + s_recognitionResult = new RecognitionResult(evt, cmdList, result); }; ErrorCode error = VcGetResult(s_resultCb, IntPtr.Zero); if (error != ErrorCode.None) @@ -725,6 +723,8 @@ namespace Tizen.Uix.VoiceControl Log.Error(LogTag, "GetResult Failed with error " + error); throw ExceptionFactory.CreateException(error); } + + return s_recognitionResult; } /// @@ -742,7 +742,7 @@ namespace Tizen.Uix.VoiceControl Log.Info(LogTag, "Recognition Result Event Triggered"); if ((cmdList != null) && (result != null)) { - RecognitionResultEventArgs args = new RecognitionResultEventArgs(evt, cmdList, result); + RecognitionResultEventArgs args = new RecognitionResultEventArgs(new RecognitionResult( evt, cmdList, result)); _recognitionResult?.Invoke(null, args); } else