From ba377ddb8154160fdbf591b66bfccf1d1950a6df Mon Sep 17 00:00:00 2001 From: "manish.r" Date: Thu, 23 Feb 2017 15:29:23 +0530 Subject: [PATCH] [VoiceControl] Base Code Change-Id: I81cb0224525f35f53ba2c86ce0b2eb2480724695 Signed-off-by: manish.r --- LICENSE | 202 +++++ packaging/csapi-uix-voicecontrol.manifest | 5 + packaging/csapi-uix-voicecontrol.spec | 44 ++ .../Interop/Interop.Libraries.cs | 29 + .../Interop/Interop.VoiceControl.cs | 156 ++++ .../Interop/Interop.VoiceControlCommand.cs | 165 ++++ .../Properties/AssemblyInfo.cs | 52 ++ .../Tizen.Uix.VoiceControl.Net45.csproj | 77 ++ .../Tizen.Uix.VoiceControl.Net45.project.json | 11 + .../Tizen.Uix.VoiceControl.csproj | 90 +++ .../Tizen.Uix.VoiceControl.nuspec | 21 + .../Tizen.Uix.VoiceControl.project.json | 9 + .../Tizen.Uix.VoiceControl.snk | Bin 0 -> 596 bytes .../CurrentLanguageChangedEventArgs.cs | 48 ++ .../ErrorOccuredEventArgs.cs | 156 ++++ .../Tizen.Uix.VoiceControl/ExceptionFactory.cs | 148 ++++ .../RecognitionResultEventArgs.cs | 78 ++ .../ServiceStateChangedEventArgs.cs | 48 ++ .../StateChangedEventArgs.cs | 48 ++ .../Tizen.Uix.VoiceControl/VoiceCommand.cs | 216 +++++ .../Tizen.Uix.VoiceControl/VoiceCommandList.cs | 248 ++++++ .../Tizen.Uix.VoiceControl/VoiceControlClient.cs | 879 +++++++++++++++++++++ 22 files changed, 2730 insertions(+) create mode 100755 LICENSE create mode 100755 packaging/csapi-uix-voicecontrol.manifest create mode 100755 packaging/csapi-uix-voicecontrol.spec create mode 100755 src/Tizen.Uix.VoiceControl/Interop/Interop.Libraries.cs create mode 100755 src/Tizen.Uix.VoiceControl/Interop/Interop.VoiceControl.cs create mode 100755 src/Tizen.Uix.VoiceControl/Interop/Interop.VoiceControlCommand.cs create mode 100755 src/Tizen.Uix.VoiceControl/Properties/AssemblyInfo.cs create mode 100755 src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl.Net45.csproj create mode 100755 src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl.Net45.project.json create mode 100755 src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl.csproj create mode 100755 src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl.nuspec create mode 100755 src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl.project.json create mode 100755 src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl.snk create mode 100755 src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl/CurrentLanguageChangedEventArgs.cs create mode 100755 src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl/ErrorOccuredEventArgs.cs create mode 100755 src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl/ExceptionFactory.cs create mode 100755 src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl/RecognitionResultEventArgs.cs create mode 100755 src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl/ServiceStateChangedEventArgs.cs create mode 100755 src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl/StateChangedEventArgs.cs create mode 100755 src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl/VoiceCommand.cs create mode 100755 src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl/VoiceCommandList.cs create mode 100755 src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl/VoiceControlClient.cs diff --git a/LICENSE b/LICENSE new file mode 100755 index 0000000..d645695 --- /dev/null +++ b/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + 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. diff --git a/packaging/csapi-uix-voicecontrol.manifest b/packaging/csapi-uix-voicecontrol.manifest new file mode 100755 index 0000000..75b0fa5 --- /dev/null +++ b/packaging/csapi-uix-voicecontrol.manifest @@ -0,0 +1,5 @@ + + + + + diff --git a/packaging/csapi-uix-voicecontrol.spec b/packaging/csapi-uix-voicecontrol.spec new file mode 100755 index 0000000..a722d82 --- /dev/null +++ b/packaging/csapi-uix-voicecontrol.spec @@ -0,0 +1,44 @@ +Name: csapi-uix-voicecontrol +Summary: Tizen Uix Voice Control API for C# +Version: 1.0.2 +Release: 1 +Group: Development/Libraries +License: Apache-2.0 +URL: https://www.tizen.org +Source0: %{name}-%{version}.tar.gz +Source1: %{name}.manifest + +AutoReqProv: no +ExcludeArch: aarch64 + +BuildRequires: dotnet-build-tools + +# C# API Requires +BuildRequires: csapi-tizen-nuget + +%define Assemblies Tizen.Uix.VoiceControl + +%description +%{summary} + +%dotnet_import_sub_packages + +%prep +%setup -q +cp %{SOURCE1} . + +%build +for ASM in %{Assemblies}; do +%dotnet_build $ASM +%dotnet_pack $ASM/$ASM.nuspec %{version} +done + +%install +for ASM in %{Assemblies}; do +%dotnet_install $ASM +done + +%files +%manifest %{name}.manifest +%license LICENSE +%attr(644,root,root) %{dotnet_assembly_files} diff --git a/src/Tizen.Uix.VoiceControl/Interop/Interop.Libraries.cs b/src/Tizen.Uix.VoiceControl/Interop/Interop.Libraries.cs new file mode 100755 index 0000000..22f391b --- /dev/null +++ b/src/Tizen.Uix.VoiceControl/Interop/Interop.Libraries.cs @@ -0,0 +1,29 @@ +/* +* 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. +*/ + +/// +/// Partial Interop Class +/// +internal static partial class Interop +{ + /// + /// Partial Libraries Class + /// + internal static partial class Libraries + { + internal const string VoiceControl = "libvc.so"; + } +} diff --git a/src/Tizen.Uix.VoiceControl/Interop/Interop.VoiceControl.cs b/src/Tizen.Uix.VoiceControl/Interop/Interop.VoiceControl.cs new file mode 100755 index 0000000..edc20f6 --- /dev/null +++ b/src/Tizen.Uix.VoiceControl/Interop/Interop.VoiceControl.cs @@ -0,0 +1,156 @@ +/* +* 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; +using Tizen.Uix.VoiceControl; +using static Interop.VoiceControlCommand; + +/// +/// Partial Interop Class +/// +internal static partial class Interop +{ + /// + /// VoiceControl Interop Class + /// + internal static class VoiceControl + { + internal static string LogTag = "Tizen.Uix.VoiceControl"; + + private const int ErrorVoiceControl = -0x02F50000; + + internal enum ErrorCode + { + 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 service */ + RecorderBusy = Tizen.Internals.Errors.ErrorCode.ResourceBusy, /**< Busy recorder */ + PermissionDenied = Tizen.Internals.Errors.ErrorCode.PermissionDenied, /**< Permission denied */ + NotSupported = Tizen.Internals.Errors.ErrorCode.NotSupported, /**< VC NOT supported */ + InvalidState = ErrorVoiceControl | 0x011, /**< Invalid state */ + InvalidLanguage = ErrorVoiceControl | 0x012, /**< Invalid language */ + EngineNotFound = ErrorVoiceControl | 0x013, /**< No available engine */ + OperationFailed = ErrorVoiceControl | 0x014, /**< Operation failed */ + OperationRejected = ErrorVoiceControl | 0x015, /**< Operation rejected */ + IterationEnd = ErrorVoiceControl | 0x016, /**< List reached end */ + Empty = ErrorVoiceControl | 0x017, /**< List empty */ + ServiceReset = ErrorVoiceControl | 0x018, /**< Service daemon reset (Since 3.0) */ + InProgressToReady = ErrorVoiceControl | 0x019, /**< In progress to ready (Since 3.0) */ + InProgressToRecording = ErrorVoiceControl | 0x020, /**< In progress to recording (Since 3.0) */ + InProgressToProcessing = ErrorVoiceControl | 0x021 /**< In progress to processing (Since 3.0) */ + }; + + internal enum VoiceCommandType + { + Foreground = 1, /* Foreground command type. */ + BackGround = 2 /* background command type. */ + }; + + [DllImport(Libraries.VoiceControl, EntryPoint = "vc_initialize")] + internal static extern ErrorCode VcInitialize(); + + [DllImport(Libraries.VoiceControl, EntryPoint = "vc_deinitialize")] + internal static extern ErrorCode VcDeinitialize(); + + [DllImport(Libraries.VoiceControl, EntryPoint = "vc_prepare")] + internal static extern ErrorCode VcPrepare(); + + [DllImport(Libraries.VoiceControl, EntryPoint = "vc_unprepare")] + internal static extern ErrorCode VcUnprepare(); + + [DllImport(Libraries.VoiceControl, EntryPoint = "vc_foreach_supported_languages")] + internal static extern ErrorCode VcForeachSupportedLanguages(VcSupportedLanguageCb callback, IntPtr userData); + + [DllImport(Libraries.VoiceControl, EntryPoint = "vc_get_current_language")] + internal static extern ErrorCode VcGetCurrentLanguage(out string language); + + [DllImport(Libraries.VoiceControl, EntryPoint = "vc_get_state")] + internal static extern ErrorCode VcGetState(out State state); + + [DllImport(Libraries.VoiceControl, EntryPoint = "vc_get_service_state")] + internal static extern ErrorCode VcGetServiceState(out ServiceState state); + + [DllImport(Libraries.VoiceControl, EntryPoint = "vc_get_system_command_list")] + internal static extern ErrorCode VcGetSystemCommandList(out IntPtr vc_sys_cmd_list); + + [DllImport(Libraries.VoiceControl, EntryPoint = "vc_set_invocation_name")] + internal static extern ErrorCode VcSetInvocationName(string name); + + [DllImport(Libraries.VoiceControl, EntryPoint = "vc_request_dialog")] + internal static extern ErrorCode VcRequestDialog(string dispText, string uttText, bool autoStart); + + [DllImport(Libraries.VoiceControl, EntryPoint = "vc_set_command_list")] + internal static extern ErrorCode VcSetCommandList(SafeCommandListHandle cmdList, VoiceCommandType type); + + [DllImport(Libraries.VoiceControl, EntryPoint = "vc_unset_command_list")] + internal static extern ErrorCode VcUnsetCommandList(VoiceCommandType type); + + [DllImport(Libraries.VoiceControl, EntryPoint = "vc_get_result")] + internal static extern ErrorCode VcGetResult(VcResultCb callback, IntPtr userData); + + [DllImport(Libraries.VoiceControl, EntryPoint = "vc_set_result_cb")] + internal static extern ErrorCode VcSetResultCb(VcResultCb callback, IntPtr userData); + + [DllImport(Libraries.VoiceControl, EntryPoint = "vc_unset_result_cb")] + internal static extern ErrorCode VcUnsetResultCb(); + + [DllImport(Libraries.VoiceControl, EntryPoint = "vc_set_service_state_changed_cb")] + internal static extern ErrorCode VcSetServiceStateChangedCb(VcServiceStateChangedCb callback, IntPtr userData); + + [DllImport(Libraries.VoiceControl, EntryPoint = "vc_unset_service_state_changed_cb")] + internal static extern ErrorCode VcUnsetServiceStateChangedCb(); + + [DllImport(Libraries.VoiceControl, EntryPoint = "vc_set_state_changed_cb")] + internal static extern ErrorCode VcSetStateChangedCb(VcStateChangedCb callback, IntPtr userData); + + [DllImport(Libraries.VoiceControl, EntryPoint = "vc_unset_state_changed_cb")] + internal static extern ErrorCode VcUnsetStateChangedCb(); + + [DllImport(Libraries.VoiceControl, EntryPoint = "vc_set_current_language_changed_cb")] + internal static extern ErrorCode VcSetCurrentLanguageChangedCb(VcCurrentLanguageChangedCb callback, IntPtr userData); + + [DllImport(Libraries.VoiceControl, EntryPoint = "vc_unset_current_language_changed_cb")] + internal static extern ErrorCode VcUnsetCurrentLanguageChangedCb(); + + [DllImport(Libraries.VoiceControl, EntryPoint = "vc_set_error_cb")] + internal static extern ErrorCode VcSetErrorCb(VcErrorCb callback, IntPtr userData); + + [DllImport(Libraries.VoiceControl, EntryPoint = "vc_unset_error_cb")] + internal static extern ErrorCode VcUnsetErrorCb(); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void VcResultCb(ResultEvent evt, IntPtr cmdList, IntPtr result, IntPtr userData); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void VcCurrentLanguageChangedCb(IntPtr previous, IntPtr current, IntPtr userData); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate bool VcSupportedLanguageCb(IntPtr language, IntPtr userData); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void VcStateChangedCb(State previous, State current, IntPtr userData); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void VcServiceStateChangedCb(ServiceState previous, ServiceState current, IntPtr userData); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void VcErrorCb(ErrorCode reason, IntPtr userData); + } +} \ No newline at end of file diff --git a/src/Tizen.Uix.VoiceControl/Interop/Interop.VoiceControlCommand.cs b/src/Tizen.Uix.VoiceControl/Interop/Interop.VoiceControlCommand.cs new file mode 100755 index 0000000..b9ca66e --- /dev/null +++ b/src/Tizen.Uix.VoiceControl/Interop/Interop.VoiceControlCommand.cs @@ -0,0 +1,165 @@ +/* +* 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; +using Tizen; +using Tizen.Uix.VoiceControl; + +/// +/// Partial Interop Class +/// +internal static partial class Interop +{ + /// + /// VoiceControlCommand Interop Class + /// + internal static class VoiceControlCommand + { + [DllImport(Libraries.VoiceControl, EntryPoint = "vc_cmd_list_create")] + internal static extern Interop.VoiceControl.ErrorCode VcCmdListCreate(out SafeCommandListHandle cmdList); + + [DllImport(Libraries.VoiceControl, EntryPoint = "vc_cmd_list_destroy")] + internal static extern Interop.VoiceControl.ErrorCode VcCmdListDestroy(IntPtr cmdList, bool freeCommand); + + [DllImport(Libraries.VoiceControl, EntryPoint = "vc_cmd_list_get_count")] + internal static extern Interop.VoiceControl.ErrorCode VcCmdListGetCount(SafeCommandListHandle cmdList, out int count); + + [DllImport(Libraries.VoiceControl, EntryPoint = "vc_cmd_list_add")] + internal static extern Interop.VoiceControl.ErrorCode VcCmdListAdd(SafeCommandListHandle cmdList, SafeCommandHandle vcCommand); + + [DllImport(Libraries.VoiceControl, EntryPoint = "vc_cmd_list_remove")] + internal static extern Interop.VoiceControl.ErrorCode VcCmdListRemove(SafeCommandListHandle cmdList, SafeCommandHandle vcCommand); + + [DllImport(Libraries.VoiceControl, EntryPoint = "vc_cmd_list_foreach_commands")] + internal static extern Interop.VoiceControl.ErrorCode VcCmdListForeachCommands(SafeCommandListHandle cmdList, VcCmdListCb callback, IntPtr userData); + + [DllImport(Libraries.VoiceControl, EntryPoint = "vc_cmd_list_first")] + internal static extern Interop.VoiceControl.ErrorCode VcCmdListFirst(SafeCommandListHandle cmdList); + + [DllImport(Libraries.VoiceControl, EntryPoint = "vc_cmd_list_last")] + internal static extern Interop.VoiceControl.ErrorCode VcCmdListLast(SafeCommandListHandle cmdList); + + [DllImport(Libraries.VoiceControl, EntryPoint = "vc_cmd_list_next")] + internal static extern Interop.VoiceControl.ErrorCode VcCmdListNext(SafeCommandListHandle cmdList); + + [DllImport(Libraries.VoiceControl, EntryPoint = "vc_cmd_list_prev")] + internal static extern Interop.VoiceControl.ErrorCode VcCmdListPrev(SafeCommandListHandle cmdList); + + [DllImport(Libraries.VoiceControl, EntryPoint = "vc_cmd_list_get_current")] + internal static extern Interop.VoiceControl.ErrorCode VcCmdListGetCurrent(SafeCommandListHandle cmdList, out SafeCommandHandle vcCommand); + + [DllImport(Libraries.VoiceControl, EntryPoint = "vc_cmd_create")] + internal static extern Interop.VoiceControl.ErrorCode VcCmdCreate(out SafeCommandHandle vcCommand); + + [DllImport(Libraries.VoiceControl, EntryPoint = "vc_cmd_destroy")] + internal static extern Interop.VoiceControl.ErrorCode VcCmdDestroy(IntPtr vcCommand); + + [DllImport(Libraries.VoiceControl, EntryPoint = "vc_cmd_set_command")] + internal static extern Interop.VoiceControl.ErrorCode VcCmdSetCommand(SafeCommandHandle vcCommand, string command); + + [DllImport(Libraries.VoiceControl, EntryPoint = "vc_cmd_get_command")] + internal static extern Interop.VoiceControl.ErrorCode VcCmdGetCommand(SafeCommandHandle vcCommand, out string command); + + [DllImport(Libraries.VoiceControl, EntryPoint = "vc_cmd_get_unfixed_command")] + internal static extern Interop.VoiceControl.ErrorCode VcCmdGetUnfixedCommand(SafeCommandHandle vcCommand, out string command); + + [DllImport(Libraries.VoiceControl, EntryPoint = "vc_cmd_set_type")] + internal static extern Interop.VoiceControl.ErrorCode VcCmdSetType(SafeCommandHandle vcCommand, CommandType type); + + [DllImport(Libraries.VoiceControl, EntryPoint = "vc_cmd_get_type")] + internal static extern Interop.VoiceControl.ErrorCode VcCmdGetType(SafeCommandHandle vcCommand, out int type); + + [DllImport(Libraries.VoiceControl, EntryPoint = "vc_cmd_set_format")] + internal static extern Interop.VoiceControl.ErrorCode VcCmdSetFormat(SafeCommandHandle vcCommand, CommandFormat format); + + [DllImport(Libraries.VoiceControl, EntryPoint = "vc_cmd_get_format")] + internal static extern Interop.VoiceControl.ErrorCode VcCmdGetFormat(SafeCommandHandle vcCommand, out CommandFormat format); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate bool VcCmdListCb(IntPtr vcCommand, IntPtr userData); + + internal sealed class SafeCommandListHandle : SafeHandle + { + public SafeCommandListHandle(IntPtr handle) + : base(handle, true) + { + } + + public SafeCommandListHandle() + : base(IntPtr.Zero, true) + { + } + + public override bool IsInvalid + { + get { return this.handle == IntPtr.Zero; } + } + + protected override bool ReleaseHandle() + { + if (!IsInvalid) + { + Interop.VoiceControl.ErrorCode error = VcCmdListDestroy(this.handle, false); + if (error != Interop.VoiceControl.ErrorCode.None) + { + Log.Error(VoiceControl.LogTag, "Destroy Failed with error " + error); + } + } + this.SetHandle(IntPtr.Zero); + return true; + } + } + + internal sealed class SafeCommandHandle : SafeHandle + { + internal bool _ownership; + + public SafeCommandHandle(IntPtr handle) + : base(handle, true) + { + _ownership = true; + } + + public SafeCommandHandle() + : base(IntPtr.Zero, true) + { + _ownership = true; + } + + public override bool IsInvalid + { + get { return this.handle == IntPtr.Zero; } + } + + protected override bool ReleaseHandle() + { + Interop.VoiceControl.ErrorCode error = VoiceControl.ErrorCode.None; + if (_ownership && !IsInvalid) + { + error = VcCmdDestroy(this.handle); + if (error != Interop.VoiceControl.ErrorCode.None) + { + Log.Error(VoiceControl.LogTag, "Destroy Failed with error " + error); + } + } + this.SetHandle(IntPtr.Zero); + return true; + } + } + } +} \ No newline at end of file diff --git a/src/Tizen.Uix.VoiceControl/Properties/AssemblyInfo.cs b/src/Tizen.Uix.VoiceControl/Properties/AssemblyInfo.cs new file mode 100755 index 0000000..9bbcd14 --- /dev/null +++ b/src/Tizen.Uix.VoiceControl/Properties/AssemblyInfo.cs @@ -0,0 +1,52 @@ +/* + * 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.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Tizen.Uix.VoiceControl")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Tizen.Uix.VoiceControl")] +[assembly: AssemblyCopyright("Copyright \u00A9 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("23e28ff0-aa5f-457b-ad1c-ad42d5f59254")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl.Net45.csproj b/src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl.Net45.csproj new file mode 100755 index 0000000..74d1b2f --- /dev/null +++ b/src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl.Net45.csproj @@ -0,0 +1,77 @@ + + + + Debug + AnyCPU + {090D9725-02F5-4F2C-B41F-3B0D493904E8} + Library + Properties + Tizen.Uix.VoiceControl + Tizen.Uix.VoiceControl + 512 + v4.5 + + + true + full + false + bin\Debug\Net45\ + DEBUG;TRACE + prompt + 4 + false + + + pdbonly + true + bin\Release\Net45\ + TRACE + prompt + 4 + false + + + true + + + Tizen.Uix.VoiceControl.snk + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl.Net45.project.json b/src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl.Net45.project.json new file mode 100755 index 0000000..ab1a0ee --- /dev/null +++ b/src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl.Net45.project.json @@ -0,0 +1,11 @@ +{ + "dependencies": { + "Tizen": "1.0.1" + }, + "frameworks": { + "net45": {} + }, + "runtimes": { + "win": {} + } +} diff --git a/src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl.csproj b/src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl.csproj new file mode 100755 index 0000000..ce235f0 --- /dev/null +++ b/src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl.csproj @@ -0,0 +1,90 @@ + + + + Debug + AnyCPU + {23E28FF0-AA5F-457B-AD1C-AD42D5F59254} + Library + Properties + Tizen.Uix.VoiceControl + Tizen.Uix.VoiceControl + 512 + + + .NETStandard + v1.3 + .NETStandard,Version=v1.3 + false + true + $(NoWarn);1701;1702 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + false + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + false + + + true + + + Tizen.Uix.VoiceControl.snk + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + <_TargetFrameworkDirectories>$(MSBuildThisFileDirectory) + <_FullFrameworkReferenceAssemblyPaths>$(MSBuildThisFileDirectory) + true + + \ No newline at end of file diff --git a/src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl.nuspec b/src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl.nuspec new file mode 100755 index 0000000..d9aa4ef --- /dev/null +++ b/src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl.nuspec @@ -0,0 +1,21 @@ + + + + Tizen.Uix.VoiceControl + $version$ + Samsung Electronics + false + https://www.apache.org/licenses/LICENSE-2.0 + https://www.tizen.org/ + https://developer.tizen.org/sites/default/files/images/tizen-pinwheel-on-light-rgb_64_64.png + © Samsung Electronics Co., Ltd All Rights Reserved + VoiceControl API for Tizen.Net + + + + + + + + + diff --git a/src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl.project.json b/src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl.project.json new file mode 100755 index 0000000..db7436c --- /dev/null +++ b/src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl.project.json @@ -0,0 +1,9 @@ +{ + "dependencies": { + "NETStandard.Library": "1.6.0", + "Tizen": "1.0.1" + }, + "frameworks": { + "netstandard1.3": {} + } +} diff --git a/src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl.snk b/src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl.snk new file mode 100755 index 0000000000000000000000000000000000000000..fc12d26f0425a492808b21d0ccef12e051b99570 GIT binary patch literal 596 zcmV-a0;~N80ssI2Bme+XQ$aES1ONa50097fsI@Ef_F62h?AB1zbWnYT|I_*7LnMG9 zEkh|9ju0PeuoE3pn*woeAG=Q`Gc9&3Y8ed&p@f9lbX)2-74M}a^_9zOhBfDz%yIM3i~f+7<0Pw}-E0jN~!!@C9m7Wt62@bJfF^rvKqe4d;NTE4Z$=d2mX0i; zjD;RWn|4cig1iOmjr1~k$^cm3M!}_DY0A~EwAciLOKkX2+G=URh}bWA=F0&^qm=bC zfqWjS@Ujk6THAKRnMbXHCdGN^Y?07N18IYgo?FFrPnDK8@7eKlqDC`tp=JvTE$_Yh i + /// This class holds information about the CurrentLanguageChanged Event + /// + public class CurrentLanguageChangedEventArgs + { + internal CurrentLanguageChangedEventArgs(string previous, string current) + { + PreviousLanguage = previous; + CurrentLanguage = current; + } + + /// + /// The previous language + /// + public string PreviousLanguage + { + get; + internal set; + } + + /// + /// The current language + /// + public string CurrentLanguage + { + get; + internal set; + } + } +} \ No newline at end of file diff --git a/src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl/ErrorOccuredEventArgs.cs b/src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl/ErrorOccuredEventArgs.cs new file mode 100755 index 0000000..f55df8d --- /dev/null +++ b/src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl/ErrorOccuredEventArgs.cs @@ -0,0 +1,156 @@ +/* +* 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 static Interop.VoiceControl; + +namespace Tizen.Uix.VoiceControl +{ + /// + /// This class holds information related to the VoiceControl ErrorOccured Event + /// + public class ErrorOccuredEventArgs + { + internal ErrorOccuredEventArgs(ErrorCode error) + { + switch (error) + { + case ErrorCode.None: + { + ErrorValue = Error.None; + break; + } + + case ErrorCode.OutOfMemory: + { + ErrorValue = Error.OutOfMemory; + break; + } + + case ErrorCode.IoError: + { + ErrorValue = Error.IoError; + break; + } + + case ErrorCode.InvalidParameter: + { + ErrorValue = Error.InvalidParameter; + break; + } + + case ErrorCode.TimedOut: + { + ErrorValue = Error.TimedOut; + break; + } + + case ErrorCode.RecorderBusy: + { + ErrorValue = Error.RecorderBusy; + break; + } + + case ErrorCode.PermissionDenied: + { + ErrorValue = Error.PermissionDenied; + break; + } + + case ErrorCode.NotSupported: + { + ErrorValue = Error.NotSupported; + break; + } + + case ErrorCode.InvalidState: + { + ErrorValue = Error.InvalidState; + break; + } + + case ErrorCode.InvalidLanguage: + { + ErrorValue = Error.InvalidLanguage; + break; + } + + case ErrorCode.EngineNotFound: + { + ErrorValue = Error.EngineNotFound; + break; + } + + case ErrorCode.OperationFailed: + { + ErrorValue = Error.OperationFailed; + break; + } + + case ErrorCode.OperationRejected: + { + ErrorValue = Error.OperationRejected; + break; + } + + case ErrorCode.IterationEnd: + { + ErrorValue = Error.IterationEnd; + break; + } + + case ErrorCode.Empty: + { + ErrorValue = Error.Empty; + break; + } + + case ErrorCode.InProgressToReady: + { + ErrorValue = Error.InProgressToReady; + break; + } + + case ErrorCode.InProgressToRecording: + { + ErrorValue = Error.InProgressToRecording; + break; + } + + case ErrorCode.InProgressToProcessing: + { + ErrorValue = Error.InProgressToProcessing; + break; + } + + case ErrorCode.ServiceReset: + { + ErrorValue = Error.ServiceReset; + break; + } + } + } + + /// + /// The Error Value + /// + public Error ErrorValue + { + get; + internal set; + } + } +} \ No newline at end of file diff --git a/src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl/ExceptionFactory.cs b/src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl/ExceptionFactory.cs new file mode 100755 index 0000000..a4d57a9 --- /dev/null +++ b/src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl/ExceptionFactory.cs @@ -0,0 +1,148 @@ +/* +* 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 static Interop.VoiceControl; + +namespace Tizen.Uix.VoiceControl +{ + internal static class ExceptionFactory + { + internal static Exception CreateException(ErrorCode err) + { + Tizen.Log.Error(LogTag, "Error " + err); + Exception exp; + switch (err) + { + case ErrorCode.OutOfMemory: + { + exp = new InvalidOperationException("Out Of Memory"); + break; + } + + case ErrorCode.IoError: + { + exp = new InvalidOperationException("I/O Error Occured"); + break; + } + + case ErrorCode.InvalidParameter: + { + exp = new InvalidOperationException("Invalid Parameters Provided"); + break; + } + + case ErrorCode.TimedOut: + { + exp = new InvalidOperationException("No answer from service"); + break; + } + + case ErrorCode.RecorderBusy: + { + exp = new InvalidOperationException("Recorder is Busy "); + break; + } + + case ErrorCode.PermissionDenied: + { + exp = new InvalidOperationException("Permission Denied"); + break; + } + + case ErrorCode.NotSupported: + { + exp = new InvalidOperationException("VC NOT supported"); + break; + } + + case ErrorCode.InvalidState: + { + exp = new InvalidOperationException("Invalid state"); + break; + } + + case ErrorCode.InvalidLanguage: + { + exp = new InvalidOperationException("Invalid language"); + break; + } + + case ErrorCode.EngineNotFound: + { + exp = new InvalidOperationException("No available engine"); + break; + } + + case ErrorCode.OperationFailed: + { + exp = new InvalidOperationException("Operation Failed"); + break; + } + + case ErrorCode.OperationRejected: + { + exp = new InvalidOperationException("Operation Rejected"); + break; + } + + case ErrorCode.IterationEnd: + { + exp = new InvalidOperationException("List Reached End"); + break; + } + + case ErrorCode.Empty: + { + exp = new InvalidOperationException("List Empty"); + break; + } + + case ErrorCode.InProgressToReady: + { + exp = new InvalidOperationException("Progress to ready is not finished"); + break; + } + + case ErrorCode.InProgressToRecording: + { + exp = new InvalidOperationException("Progress to recording is not finished"); + break; + } + + case ErrorCode.InProgressToProcessing: + { + exp = new InvalidOperationException("Progress to processing is not finished"); + break; + } + + case ErrorCode.ServiceReset: + { + exp = new InvalidOperationException("Service reset"); + break; + } + + default: + { + exp = new Exception(""); + break; + } + } + + return exp; + } + } +} diff --git a/src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl/RecognitionResultEventArgs.cs b/src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl/RecognitionResultEventArgs.cs new file mode 100755 index 0000000..ab764b0 --- /dev/null +++ b/src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl/RecognitionResultEventArgs.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 RecognitionResultEventArgs + { + private ResultEvent _resultEvent; + private VoiceCommandList _list; + private string _result; + + internal RecognitionResultEventArgs(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/ServiceStateChangedEventArgs.cs b/src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl/ServiceStateChangedEventArgs.cs new file mode 100755 index 0000000..6d1bef9 --- /dev/null +++ b/src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl/ServiceStateChangedEventArgs.cs @@ -0,0 +1,48 @@ +/* +* 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. +*/ + +namespace Tizen.Uix.VoiceControl +{ + /// + /// This class holds information related to the VoiceControl service ServiceStateChanged event + /// + public class ServiceStateChangedEventArgs + { + internal ServiceStateChangedEventArgs(ServiceState previous, ServiceState current) + { + Previous = previous; + Current = current; + } + + /// + /// A previous state + /// + public ServiceState Previous + { + get; + internal set; + } + + /// + /// A current state + /// + public ServiceState Current + { + get; + internal set; + } + } +} diff --git a/src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl/StateChangedEventArgs.cs b/src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl/StateChangedEventArgs.cs new file mode 100755 index 0000000..8241a7a --- /dev/null +++ b/src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl/StateChangedEventArgs.cs @@ -0,0 +1,48 @@ +/* +* 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. +*/ + +namespace Tizen.Uix.VoiceControl +{ + /// + /// This class holds information related to the VoiceControl client StateChanged event + /// + public class StateChangedEventArgs + { + internal StateChangedEventArgs(State previous, State current) + { + Previous = previous; + Current = current; + } + + /// + /// A previous state + /// + public State Previous + { + get; + internal set; + } + + /// + /// A current state + /// + public State Current + { + get; + internal set; + } + } +} diff --git a/src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl/VoiceCommand.cs b/src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl/VoiceCommand.cs new file mode 100755 index 0000000..d750ee6 --- /dev/null +++ b/src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl/VoiceCommand.cs @@ -0,0 +1,216 @@ +/* +* 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 static Interop.VoiceControl; +using static Interop.VoiceControlCommand; + +namespace Tizen.Uix.VoiceControl +{ + /// + /// Enumeration for Command Format + /// + public enum CommandFormat + { + /// + /// fixed command format. + /// + Fixed = 0, + /// + /// fixed and variable fixed command format. + /// + FixedAndVFixed = 1, + /// + /// variable fixed and fixed command format. + /// + VFixedAndFixed = 2, + /// + /// fixed and non-fixed command format. + /// + FixedAndNonFixed = 3, + /// + /// non-fixed and fixed command format. + /// + NonFixedAndFixed = 4, + /// + /// Undefined + /// + Undefined = 5 + }; + + /// + /// This class represents a Voice Command + /// + public class VoiceCommand + { + internal SafeCommandHandle _handle; + + /// + /// Public Constructor + /// + /// + /// This Exception can be due to the following reaons + /// 1. Out of memory + /// 2. Permission Denied + /// 3. Invalid State + /// + public VoiceCommand() + { + SafeCommandHandle handle; + ErrorCode error = VcCmdCreate(out handle); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "Create Failed with error " + error); + throw ExceptionFactory.CreateException(error); + } + _handle = handle; + } + + internal VoiceCommand(SafeCommandHandle handle) + { + _handle = handle; + } + + /// + /// Gets the unfixed command. + /// This property should be used for commands which have non-fixed format. + /// empty string will be returned in case of some internal error + /// + public string GetUnfixedCommand + { + get + { + string unfixedCommand; + ErrorCode error = VcCmdGetUnfixedCommand(_handle, out unfixedCommand); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "GetUnfixedCommand Failed with error " + error); + return ""; + } + + return unfixedCommand; + } + } + + /// + /// Gets/Sets command type. + /// + /// If you do not set the command type, the default value is Undefined. You should set type if command is valid + /// + /// This Exception can be due to the following reaons for set operation + /// 1. Invalid parameter + /// 2. Permission Denied + /// 3. Not supported + /// + public CommandType Type + { + get + { + CommandType cmdType = CommandType.Undefined; + int type; + ErrorCode error = VcCmdGetType(_handle, out type); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "GetType Failed with error " + error); + return CommandType.Undefined; + } + + if (type != -1) + { + cmdType = (CommandType)type; + } + + return cmdType; + } + set + { + ErrorCode error = VcCmdSetType(_handle, value); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "SetType Failed with error " + error); + } + } + } + + /// + /// Gets/Sets the command format. + /// + /// The default format is Fixed + /// + /// This Exception can be due to the following reaons for set operation + /// 1. Invalid parameter + /// 2. Permission Denied + /// 3. Not supported + /// + public CommandFormat Format + { + get + { + CommandFormat format; + ErrorCode error = VcCmdGetFormat(_handle, out format); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "GetFormat Failed with error " + error); + return CommandFormat.Undefined; + } + + return format; + } + set + { + ErrorCode error = VcCmdSetFormat(_handle, value); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "SetFormat Failed with error " + error); + } + } + } + + /// + /// Gets/Sets command + /// in case of get empty string will be returned in case of some internal error + /// + /// + /// This Exception can be due to the following reaons for set operation + /// 1. Invalid parameter + /// 2. Permission Denied + /// 3. Not supported + /// + public string Command + { + get + { + string command; + ErrorCode error = VcCmdGetCommand(_handle, out command); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "GetCommand Failed with error " + error); + return ""; + } + + return command; + } + set + { + ErrorCode error = VcCmdSetCommand(_handle, value); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "SetCommand Failed with error " + error); + } + } + } + } +} diff --git a/src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl/VoiceCommandList.cs b/src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl/VoiceCommandList.cs new file mode 100755 index 0000000..bb1da4f --- /dev/null +++ b/src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl/VoiceCommandList.cs @@ -0,0 +1,248 @@ +/* +* 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 static Interop.VoiceControl; +using static Interop.VoiceControlCommand; + +namespace Tizen.Uix.VoiceControl +{ + /// + /// this class represents list of Voice Commands + /// + public class VoiceCommandList + { + internal SafeCommandListHandle _handle; + private List _list; + private VcCmdListCb _callback; + + /// + /// Public Constructor + /// + /// + /// This Exception can be due to the following reaons + /// 1. Invalid parameter + /// 2. Permission Denied + /// 3. Not supported + /// 4. Out of memory + /// + public VoiceCommandList() + { + SafeCommandListHandle handle = new SafeCommandListHandle(); + ErrorCode error = VcCmdListCreate(out handle); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "Create Failed with error " + error); + throw ExceptionFactory.CreateException(error); + } + _handle = handle; + } + + internal VoiceCommandList(SafeCommandListHandle handle) + { + _handle = handle; + } + + /// + /// Gets command count of list. + /// -1 is returned in case of internal failure. + /// + public int GetCount + { + get + { + int count; + ErrorCode error = VcCmdListGetCount(_handle, out count); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "Count Failed with error " + error); + return -1; + } + + return count; + } + } + + /// + /// Get current command from command list by index. + /// null will be returned in case of Empty List + /// + public VoiceCommand GetCurrent + { + get + { + SafeCommandHandle current; + ErrorCode error = VcCmdListGetCurrent(_handle, out current); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "Current Failed with error " + error); + return null; + } + current._ownership = false; + return new VoiceCommand(current); + } + } + + /// + /// Adds command to command list. + /// + /// The command + /// + /// This Exception can be due to the following reaons + /// 1. Invalid parameter + /// 2. Permission Denied + /// 3. Not supported + /// + /// This will occur if the provide parameter is null + public void Add(VoiceCommand command) + { + ErrorCode error = VcCmdListAdd(_handle, command._handle); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "Add Failed with error " + error); + throw ExceptionFactory.CreateException(error); + } + } + + /// + /// Removes command from command list. + /// + /// The command + /// + /// This Exception can be due to the following reaons + /// 1. Invalid parameter + /// 2. Permission Denied + /// 3. Not supported + /// + /// This will occur if the provide parameter is null + public void Remove(VoiceCommand command) + { + ErrorCode error = VcCmdListRemove(_handle, command._handle); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "Remove Failed with error " + error); + throw ExceptionFactory.CreateException(error); + } + } + + /// + /// Retrieves all commands of command list. + /// + /// + /// This Exception can be due to the following reaons + /// 1. Permission Denied + /// 2. Not supported + /// + public IEnumerable GetAllCommands() + { + _list = new List(); + _callback = (IntPtr vcCommand, IntPtr userData) => + { + SafeCommandHandle handle = new SafeCommandHandle(vcCommand); + handle._ownership = false; + _list.Add(new VoiceCommand(handle)); + return true; + }; + ErrorCode error = VcCmdListForeachCommands(_handle, _callback, IntPtr.Zero); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "GetAllCommands Failed with error " + error); + throw ExceptionFactory.CreateException(error); + } + + return _list; + } + + /// + /// Moves index to first command. + /// + /// + /// This Exception can be due to the following reaons + /// 1. List Empty + /// 2. Permission Denied + /// 3. Not supported + /// + public void First() + { + ErrorCode error = VcCmdListFirst(_handle); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "First Failed with error " + error); + throw ExceptionFactory.CreateException(error); + } + } + + /// + /// Moves index to last command. + /// + /// + /// This Exception can be due to the following reaons + /// 1. List Empty + /// 2. Permission Denied + /// 3. Not supported + /// + public void Last() + { + ErrorCode error = VcCmdListLast(_handle); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "Last Failed with error " + error); + throw ExceptionFactory.CreateException(error); + } + } + + /// + /// Moves index to next command. + /// + /// + /// This Exception can be due to the following reaons + /// 1. List Empty + /// 2. List reached end + /// 3. Permission Denied + /// 4. Not supported + /// + public void Next() + { + ErrorCode error = VcCmdListNext(_handle); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "Next Failed with error " + error); + throw ExceptionFactory.CreateException(error); + } + } + + /// + /// Moves index to previous command. + /// + /// + /// This Exception can be due to the following reaons + /// 1. List Empty + /// 2. List reached end + /// 3. Permission Denied + /// 4. Not supported + /// + public void Previous() + { + ErrorCode error = VcCmdListPrev(_handle); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "Previous Failed with error " + error); + throw ExceptionFactory.CreateException(error); + } + } + } +} diff --git a/src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl/VoiceControlClient.cs b/src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl/VoiceControlClient.cs new file mode 100755 index 0000000..78ea25d --- /dev/null +++ b/src/Tizen.Uix.VoiceControl/Tizen.Uix.VoiceControl/VoiceControlClient.cs @@ -0,0 +1,879 @@ +/* +* 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 +{ + /// + /// Enum for Error values that can occur + /// + public enum Error + { + /// + /// Successful, No error + /// + None, + /// + /// Out of Memory + /// + OutOfMemory, + /// + /// I/O error + /// + IoError, + /// + /// Invalid parameter + /// + InvalidParameter, + /// + /// No answer from the STT service + /// + TimedOut, + /// + /// Device or resource busy + /// + RecorderBusy, + /// + /// Permission denied + /// + PermissionDenied, + /// + /// VC NOT supported + /// + NotSupported, + /// + /// Invalid state + /// + InvalidState, + /// + /// Invalid language + /// + InvalidLanguage, + /// + /// No available engine + /// + EngineNotFound, + /// + /// Operation failed + /// + OperationFailed, + /// + /// Operation Rejected + /// + OperationRejected, + /// + /// List reached end + /// + IterationEnd, + /// + /// List Empty + /// + Empty, + /// + /// Service reset + /// + ServiceReset, + /// + /// Progress to ready is not finished + /// + InProgressToReady, + /// + /// Progress to recording is not finished + /// + InProgressToRecording, + /// + /// Progress to processing is not finished + /// + InProgressToProcessing + }; + + /// + /// Enumeration for the client state. + /// + public enum State + { + /// + /// 'None' state + /// + None = 0, + /// + /// 'Initialized' state + /// + Initialized = 1, + /// + /// 'Ready' state + /// + Ready = 2, + /// + /// state cannot be determined + /// + Unavailable + }; + + /// + /// Enumerations of service state. + /// + public enum ServiceState + { + /// + /// 'None' state + /// + None = 0, + /// + /// 'Ready' state + /// + Ready = 1, + /// + /// 'Recording' state + /// + Recording = 2, + /// + /// 'Processing' state + /// + Processing = 3, + /// + /// state cannot be determined + /// + Unavailable + }; + + /// + /// Enumerations of result event. + /// + public enum ResultEvent + { + /// + /// Normal result + /// + Success = 0, + /// + /// Rejected result + /// + Rejected = 1 + }; + + /// + /// Enumerations of command type. + /// + public enum CommandType + { + /// + /// Foreground command by client + /// + Foreground = 1, + /// + /// Background command by client + /// + Background = 2, + /// + /// Undefined command + /// + Undefined = -1 + }; + + /// + /// A main function of Voice Control API register command and gets notification for recognition result. + /// Applications can add their own commands and be provided result when their command is recognized by user voice input. + /// + public static class VoiceControlClient + { + /// + /// Called when client gets the recognition result. + /// + /// + /// 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, cmdList has the multi commands. + /// + /// The ResultEvent + /// Command List + /// Result + public delegate void RecognitionResultDelegate(ResultEvent evt, VoiceCommandList cmdList, string result); + + private static event EventHandler _recognitionResult; + private static event EventHandler _stateChanged; + private static event EventHandler _serviceStateChanged; + private static event EventHandler _errorOccured; + private static event EventHandler _currentLanguageChanged; + private static VcResultCb s_resultDelegate; + private static VcStateChangedCb s_stateDelegate; + private static VcServiceStateChangedCb s_serviceStateDelegate; + private static VcErrorCb s_errorDelegate; + private static VcCurrentLanguageChangedCb s_languageDelegate; + private static List s_supportedLanguages; + private static VcSupportedLanguageCb s_supportedLanguagesCb; + private static VcResultCb s_resultCb; + + /// + /// Gets current language. + /// A 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. + /// Empty string is returned incase of some internal error + /// + /// + /// http://tizen.org/privilege/recorder + /// + /// + /// The State must be Initialized or Ready. + /// + public static string GetCurrentLanaguge + { + get + { + string currentLanaguge; + + ErrorCode error = VcGetCurrentLanguage(out currentLanaguge); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "CurrentLanaguge Failed with error " + error); + return ""; + } + + return currentLanaguge; + } + } + + /// + /// Gets current state of voice control client. + /// + /// + /// http://tizen.org/privilege/recorder + /// + /// + /// The State must be Initialized or Ready. + /// + public static State GetState + { + get + { + State state; + + ErrorCode error = VcGetState(out state); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "GetState Failed with error " + error); + return State.Unavailable; + } + + return state; + } + } + + /// + /// Gets current state of voice control service. + /// + /// + /// http://tizen.org/privilege/recorder + /// + /// + /// The State must be Ready. + /// + public static ServiceState GetServiceState + { + get + { + ServiceState state; + + ErrorCode error = VcGetServiceState(out state); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "GetServiceState Failed with error " + error); + return ServiceState.Unavailable; + } + + return state; + } + } + + /// + /// Sets the invocation name. + /// + /// + /// http://tizen.org/privilege/recorder + /// + /// + /// Invocation name is used to activate background commands. The invocation name can be the same as the application name or any other phrase. + /// For example, an application "Tizen Sample" has a background command, "Play music", and the invocation name of the application is set to "Tizen Sample". + /// In order to activate the background command, users can say "Tizen Sample, Play music". The invocation name is dependent on the current language. + /// For example, if the current language is "en_US"(English), the invocation name is also "en_US". + /// If the current language is "ja_JP"(Japanese) and the invocation name is "en_US", the invocation name will not be recognized. + /// This function should be called before SetCommandList(). + /// + /// Invocation name that an application wants to be invoked by + /// + /// This Exception can be due to the following reaons + /// 1. Invalid parameter + /// 2. Invalid state + /// 3. Not Supported + /// 4. Permission Denied + /// + /// + /// The State must be Ready. + /// + public static void SetInvocationName(string name) + { + ErrorCode error = VcSetInvocationName(name); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "SetInvocationName Failed with error " + error); + throw ExceptionFactory.CreateException(error); + } + } + + /// + /// Initializes voice control. + /// + /// + /// http://tizen.org/privilege/recorder + /// + /// + /// This Exception can be due to the following reaons + /// 1. Out Of Memory + /// 2. Operation Failed + /// 3. Not Supported + /// 4. Permission Denied + /// + /// + /// The State will be Initialized. + /// + public static void Initialize() + { + ErrorCode error = VcInitialize(); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "Initialize Failed with error " + error); + throw ExceptionFactory.CreateException(error); + } + } + + /// + /// Deinitializes voice control. + /// + /// + /// http://tizen.org/privilege/recorder + /// + /// + /// This Exception can be due to the following reaons + /// 1. Operation Failed + /// 2. Invalid state + /// 3. Not Supported + /// 4. Permission Denied + /// + public static void Deinitialize() + { + ErrorCode error = VcDeinitialize(); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "Deinitialize Failed with error " + error); + throw ExceptionFactory.CreateException(error); + } + } + + /// + /// Connects the voice control service. + /// + /// + /// http://tizen.org/privilege/recorder + /// + /// + /// This Exception can be due to the following reaons + /// 1. Operation Failed + /// 2. Not Supported + /// 3. Permission Denied + /// 4. Invalid State + /// + /// + /// The State should be Initialized + /// + /// + /// The State will be Ready + /// + public static void Prepare() + { + ErrorCode error = VcPrepare(); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "Prepare Failed with error " + error); + throw ExceptionFactory.CreateException(error); + } + } + + /// + /// Disconnects the voice control service. + /// + /// + /// http://tizen.org/privilege/recorder + /// + /// + /// This Exception can be due to the following reaons + /// 1. Not Supported + /// 2. Permission Denied + /// 3. Invalid State + /// + /// + /// The State should be Ready + /// + /// + /// The State should be Initialized + /// + public static void Unprepare() + { + ErrorCode error = VcUnprepare(); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "Unprepare Failed with error " + error); + throw ExceptionFactory.CreateException(error); + } + } + + /// + /// Retrieves all supported languages. + /// A 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. + /// + /// + /// http://tizen.org/privilege/recorder + /// + /// + /// This Exception can be due to the following reaons + /// 1. Operation Failed + /// 2. Not Supported + /// 3. Permission Denied + /// 4. Invalid State + /// + /// + /// The State should be Ready or Initialized + /// + public static IEnumerable GetSupportedLangauges() + { + s_supportedLanguages = new List(); + s_supportedLanguagesCb = (IntPtr language, IntPtr userData) => + { + string languageStr = Marshal.PtrToStringAnsi(language); + s_supportedLanguages.Add(languageStr); + return true; + }; + ErrorCode error = VcForeachSupportedLanguages(s_supportedLanguagesCb, IntPtr.Zero); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "GetSupportedLangauges Failed with error " + error); + throw ExceptionFactory.CreateException(error); + } + + return s_supportedLanguages; + } + + /// + /// Gets the system command list. + /// + /// + /// The Command List else null in case of no System Commands + /// + /// + /// http://tizen.org/privilege/recorder + /// + /// + /// In the system command list, there are system commands predefined by product manufacturers. + /// Those commands have the highest priority. Therefore, the user can not set any commands same with the system commands. + /// + /// + /// This Exception can be due to the following reaons + /// 1. Not Supported + /// 2. Permission Denied + /// 3. Invalid State + /// + /// + /// The State should be Ready + /// + public static VoiceCommandList GetSytemCommandList() + { + IntPtr handle = IntPtr.Zero; + ErrorCode error = VcGetSystemCommandList(out handle); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "GetSystemCommandList Failed with error " + error); + throw ExceptionFactory.CreateException(error); + } + + if (handle == IntPtr.Zero) + { + Log.Error(LogTag, "GetSystemCommandList handle is null"); + return null; + } + + SafeCommandListHandle list = new SafeCommandListHandle(handle); + return new VoiceCommandList(list); + } + + /// + /// Requests to start the dialogue. + /// Using this function, the developer can request starting the dialogue to the framework. + /// When the developer requests the dialogue, two types of texts, dispText and uttText, can be sent by this function.dispText is a text for displaying, and uttText is that for uttering. + /// For example, if dispText is "October 10th" and uttText is "Today is October 10th.", "October 10th" will be displayed on the screen and "Today is October 10th." will be spoken. + /// Also, the developer can set whether the dialogue starts automatically or not, using autoStart. + /// If the developer sets autoStart as true, the framework will start to record next speech and continue the dialogue. + /// + /// + /// http://tizen.org/privilege/recorder + /// + /// + /// If autoStart is true, the recognition will start again. In this case, it can be restarted up to 4 times. + /// + /// Text to be displayed on the screen/// + /// Text to be spoken + /// A variable for setting whether the dialog session will be restarted automatically or not + /// + /// This Exception can be due to the following reaons + /// 1. Not Supported + /// 2. Permission Denied + /// 3. Invalid State + /// 4. Invalid parameter + /// + /// + /// The State should be Ready + /// + public static void RequestDialog(string dispText, string uttText, bool autoStart) + { + ErrorCode error = VcRequestDialog(dispText, uttText, autoStart); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "RequestDialog Failed with error " + error); + throw ExceptionFactory.CreateException(error); + } + } + + /// + /// Sets command list. + /// + /// + /// http://tizen.org/privilege/recorder + /// + /// + /// The command type is valid for CommandType 'Foreground' or 'Background'. + /// The matched commands of command list should be set and they should include type and command text at least. + /// + /// Command list + /// Command type + /// + /// This Exception can be due to the following reaons + /// 1. Not Supported + /// 2. Permission Denied + /// 3. Invalid State + /// 4. Invalid parameter + /// + /// + /// The State should be Ready + /// + public static void SetCommandList(VoiceCommandList list, CommandType type) + { + if ((type == CommandType.Foreground) || (type == CommandType.Background)) + { + ErrorCode error = VcSetCommandList(list._handle, (VoiceCommandType)type); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "SetCommandList Failed with error " + error); + throw ExceptionFactory.CreateException(error); + } + } + + else + { + throw ExceptionFactory.CreateException(ErrorCode.InvalidParameter); + } + } + + /// + /// Unsets command list. + /// + /// + /// http://tizen.org/privilege/recorder + /// + /// Command type + /// + /// This Exception can be due to the following reaons + /// 1. Not Supported + /// 2. Permission Denied + /// 3. Invalid State + /// 4. Invalid parameter + /// + /// + /// The State should be Ready + /// + public static void UnsetCommandList(CommandType type) + { + if ((type == CommandType.Foreground) || (type == CommandType.Background)) + { + VoiceCommandType commandType = VoiceCommandType.Foreground; + if (type == CommandType.Background) + commandType = VoiceCommandType.BackGround; + ErrorCode error = VcUnsetCommandList(commandType); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "UnsetCommandList Failed with error " + error); + throw ExceptionFactory.CreateException(error); + } + } + + else + { + throw ExceptionFactory.CreateException(ErrorCode.InvalidParameter); + } + } + + /// + /// Gets the recognition result. + /// + /// + /// http://tizen.org/privilege/recorder + /// + /// + /// Callback function to get recognition result + /// + /// + /// This Exception can be due to the following reaons + /// 1. Not Supported + /// 2. Invalid State + /// 3. Invalid parameter + /// + /// + /// The State should be Ready + /// + public static void GetResult(RecognitionResultDelegate resultDelegate) + { + 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); + }; + ErrorCode error = VcGetResult(s_resultCb, IntPtr.Zero); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "GetResult Failed with error " + error); + throw ExceptionFactory.CreateException(error); + } + } + + /// + /// Event to be invoked when the recognition is done. + /// + /// + /// The State should be Initialized + /// + public static event EventHandler RecognitionResult + { + add + { + s_resultDelegate = (ResultEvent evt, IntPtr cmdList, IntPtr result, IntPtr userData) => + { + Log.Info(LogTag, "Recognition Result Event Triggered"); + if ((cmdList != null) && (result != null)) + { + RecognitionResultEventArgs args = new RecognitionResultEventArgs(evt, cmdList, result); + _recognitionResult?.Invoke(null, args); + } + else + { + Log.Info(LogTag, "Recognition Result Event null received"); + } + }; + ErrorCode error = VcSetResultCb(s_resultDelegate, IntPtr.Zero); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "Add RecognitionResult Failed with error " + error); + } + else + { + _recognitionResult += value; + } + } + + remove + { + ErrorCode error = VcUnsetResultCb(); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "Remove RecognitionResult Failed with error " + error); + } + + _recognitionResult -= value; + } + } + + /// + /// Event to be invoked when VoiceControl service state changes. + /// + /// + /// The State should be Initialized + /// + public static event EventHandler ServiceStateChanged + { + add + { + s_serviceStateDelegate = (ServiceState previous, ServiceState current, IntPtr userData) => + { + ServiceStateChangedEventArgs args = new ServiceStateChangedEventArgs(previous, current); + _serviceStateChanged?.Invoke(null, args); + }; + ErrorCode error = VcSetServiceStateChangedCb(s_serviceStateDelegate, IntPtr.Zero); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "Add ServiceStateChanged Failed with error " + error); + } + else + { + _serviceStateChanged += value; + } + } + + remove + { + ErrorCode error = VcUnsetServiceStateChangedCb(); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "Remove ServiceStateChanged Failed with error " + error); + } + + _serviceStateChanged -= value; + } + } + + /// + /// Event to be invoked when VoiceControl client state changes. + /// + /// + /// The State should be Initialized + /// + public static event EventHandler StateChanged + { + add + { + s_stateDelegate = (State previous, State current, IntPtr userData) => + { + StateChangedEventArgs args = new StateChangedEventArgs(previous, current); + _stateChanged?.Invoke(null, args); + }; + ErrorCode error = VcSetStateChangedCb(s_stateDelegate, IntPtr.Zero); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "Add StateChanged Failed with error " + error); + } + else + { + _stateChanged += value; + } + } + + remove + { + ErrorCode error = VcUnsetStateChangedCb(); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "Remove StateChanged Failed with error " + error); + } + + _stateChanged -= value; + } + } + + /// + /// Event to be invoked when an error occurs. + /// + /// + /// The State should be Initialized + /// + public static event EventHandler ErrorOccured + { + add + { + s_errorDelegate = (ErrorCode reason, IntPtr userData) => + { + ErrorOccuredEventArgs args = new ErrorOccuredEventArgs(reason); + _errorOccured?.Invoke(null, args); + }; + ErrorCode error = VcSetErrorCb(s_errorDelegate, IntPtr.Zero); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "Add ErrorOccured Failed with error " + error); + } + + else + { + _errorOccured += value; + } + } + + + remove + { + ErrorCode error = VcUnsetErrorCb(); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "Remove ErrorOccured Failed with error " + error); + } + + _errorOccured -= value; + } + } + + /// + /// Event to be invoked when default laungage change. + /// + /// + /// The State should be Initialized + /// + public static event EventHandler CurrentLanguageChanged + { + add + { + s_languageDelegate = (IntPtr previousLanguage, IntPtr currentLanguage, IntPtr userData) => + { + string previousLanguageString = Marshal.PtrToStringAnsi(previousLanguage); + string currentLanguageString = Marshal.PtrToStringAnsi(currentLanguage); + CurrentLanguageChangedEventArgs args = new CurrentLanguageChangedEventArgs(previousLanguageString, currentLanguageString); + _currentLanguageChanged?.Invoke(null, args); + }; + ErrorCode error = VcSetCurrentLanguageChangedCb(s_languageDelegate, IntPtr.Zero); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "Add CurrentLanguageChanged Failed with error " + error); + } + + else + { + _currentLanguageChanged += value; + } + } + + remove + { + ErrorCode error = VcUnsetCurrentLanguageChangedCb(); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "Remove CurrentLanguageChanged Failed with error " + error); + } + + _currentLanguageChanged -= value; + } + } + } +} -- 2.7.4