Modification of GetResult API 13/129213/2 accepted/tizen/unified/20170515.155108 submit/tizen/20170515.131857
authormanish.r <manish.r@samsung.com>
Mon, 15 May 2017 11:49:41 +0000 (17:19 +0530)
committermanish.r <manish.r@samsung.com>
Mon, 15 May 2017 13:07:19 +0000 (18:37 +0530)
Change-Id: Iabf8ccb6ba1e8496fcf65248613012498d34b569
Signed-off-by: manish.r <manish.r@samsung.com>
Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl.csproj
Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl/RecognitionResult.cs [new file with mode: 0755]
Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl/RecognitionResultEventArgs.cs
Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl/VoiceControlClient.cs

index ce235f0..1b581ca 100755 (executable)
@@ -48,6 +48,7 @@
     <Compile Include="Interop\Interop.Libraries.cs" />
     <Compile Include="Interop\Interop.VoiceControlCommand.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
+    <Compile Include="Tizen.Uix.VoiceControl\RecognitionResult.cs" />
     <Compile Include="Tizen.Uix.VoiceControl\VoiceCommand.cs" />
     <Compile Include="Tizen.Uix.VoiceControl\VoiceCommandList.cs" />
     <Compile Include="Tizen.Uix.VoiceControl\VoiceControlClient.cs" />
diff --git a/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl/RecognitionResult.cs b/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl/RecognitionResult.cs
new file mode 100755 (executable)
index 0000000..4fb5ea8
--- /dev/null
@@ -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
+{
+    /// <summary>
+    /// 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.
+    /// </summary>
+    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);
+        }
+
+        /// <summary>
+        /// The result event
+        /// </summary>
+        public ResultEvent Result
+        {
+            get
+            {
+                return _resultEvent;
+            }
+        }
+
+        /// <summary>
+        /// The spoken text
+        /// </summary>
+        public string ResultMessage
+        {
+            get
+            {
+                return _result;
+            }
+        }
+
+
+        /// <summary>
+        /// The recognized command list
+        /// </summary>
+        public VoiceCommandList CommandList
+        {
+            get
+            {
+                return _list;
+            }
+        }
+    }
+}
index ab764b0..e81bde5 100755 (executable)
 */
 
 using System;
-using System.Collections.Generic;
-using System.Runtime.InteropServices;
-using static Interop.VoiceControl;
-using static Interop.VoiceControlCommand;
 
 namespace Tizen.Uix.VoiceControl
 {
     /// <summary>
     /// 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.
     /// </summary>
-    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);
-        }
-
-        /// <summary>
-        /// The result event
-        /// </summary>
-        public ResultEvent Result
-        {
-            get
-            {
-                return _resultEvent;
-            }
+            _result = result;
         }
 
         /// <summary>
-        /// The spoken text
+        /// Gets the Recognition result
         /// </summary>
-        public string ResultMessage
+        public RecognitionResult Result
         {
             get
             {
@@ -63,16 +40,5 @@ namespace Tizen.Uix.VoiceControl
             }
         }
 
-
-        /// <summary>
-        /// The recognized command list
-        /// </summary>
-        public VoiceCommandList CommandList
-        {
-            get
-            {
-                return _list;
-            }
-        }
     }
 }
index b395f47..f9d689a 100755 (executable)
@@ -220,6 +220,7 @@ namespace Tizen.Uix.VoiceControl
         private static List<string> s_supportedLanguages;
         private static VcSupportedLanguageCb s_supportedLanguagesCb;
         private static VcResultCb s_resultCb;
+        private static RecognitionResult s_recognitionResult;
 
         /// <summary>
         /// Gets current language.
@@ -496,7 +497,7 @@ namespace Tizen.Uix.VoiceControl
         /// <precondition>
         /// The State should be Ready or Initialized
         /// </precondition>
-        public static IEnumerable<string> GetSupportedLangauges()
+        public static IEnumerable<string> GetSupportedLanguages()
         {
             s_supportedLanguages = new List<string>();
             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
         /// <precondition>
         /// The State should be Ready
         /// </precondition>
-        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
         /// </feature>
-        /// <param name="resultDelegate">
-        /// Callback function to get recognition result
-        /// </param>
         /// <exception cref="InvalidOperationException"> This Exception can be due to Invalid State. </exception>
         /// <exception cref="ArgumentException"> This Exception can be due to Invalid Parameter. </exception>
         /// <exception cref="NotSupportedException"> This Exception can be due to Not Supported. </exception>
+        /// <returns>The Recognition Result if possible else a null object</returns>
         /// <precondition>
         /// The State should be Ready
         /// </precondition>
-        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;
         }
 
         /// <summary>
@@ -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