From 0838a51f223b6e7fda07815387787d6365094058 Mon Sep 17 00:00:00 2001 From: Inhong Date: Thu, 30 May 2019 09:52:38 +0900 Subject: [PATCH] [VoiceControlManager][TCSACR-213] Add VoiceControlManager APIs (#841) * Add Tizen.Uix.VoiceControlManager Signed-off-by: sungrae jo * [VoiceControlManager] Modified code by API review --- .../Interop/Interop.Libraries.cs | 30 + .../Interop/Interop.Manager.cs | 278 +++ .../Interop/Interop.VoiceControlCommand.cs | 160 ++ .../Tizen.Uix.VoiceControlManager.csproj | 20 + .../Tizen.Uix.VoiceControlManager.sln | 42 + .../AllRecognitionResultEventArgs.cs | 55 + .../ConversationRequestedEventArgs.cs | 74 + .../CurrentLanguageChangedEventArgs.cs | 53 + .../ErrorOccurerdEventArgs.cs | 42 + .../ExceptionFactory.cs | 86 + .../FeedbackAudioFormatEventArgs.cs | 63 + .../FeedbackStreamingEventArgs.cs | 52 + .../PreRecognitionResultUpdatedEventArgs.cs | 52 + .../PrivateDataUpdatedEventArgs.cs | 52 + .../RecognitionResultUpdatedEventArgs.cs | 122 ++ .../ServiceStateChangedEventArgs.cs | 53 + .../SpecificEngineResultEventArgs.cs | 68 + .../StateChangedEventArgs.cs | 53 + .../VcTtsStreamingEventArgs.cs | 74 + .../Tizen.Uix.VoiceControlManager/VoiceCommand.cs | 261 +++ .../VoiceCommandsGroup.cs | 158 ++ .../VoiceControlManagerClient.cs | 1990 ++++++++++++++++++++ 22 files changed, 3838 insertions(+) create mode 100755 src/Tizen.Uix.VoiceControlManager/Interop/Interop.Libraries.cs create mode 100755 src/Tizen.Uix.VoiceControlManager/Interop/Interop.Manager.cs create mode 100755 src/Tizen.Uix.VoiceControlManager/Interop/Interop.VoiceControlCommand.cs create mode 100644 src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager.csproj create mode 100755 src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager.sln create mode 100755 src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager/AllRecognitionResultEventArgs.cs create mode 100755 src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager/ConversationRequestedEventArgs.cs create mode 100755 src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager/CurrentLanguageChangedEventArgs.cs create mode 100755 src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager/ErrorOccurerdEventArgs.cs create mode 100755 src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager/ExceptionFactory.cs create mode 100755 src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager/FeedbackAudioFormatEventArgs.cs create mode 100755 src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager/FeedbackStreamingEventArgs.cs create mode 100755 src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager/PreRecognitionResultUpdatedEventArgs.cs create mode 100755 src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager/PrivateDataUpdatedEventArgs.cs create mode 100755 src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager/RecognitionResultUpdatedEventArgs.cs create mode 100755 src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager/ServiceStateChangedEventArgs.cs create mode 100755 src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager/SpecificEngineResultEventArgs.cs create mode 100755 src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager/StateChangedEventArgs.cs create mode 100755 src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager/VcTtsStreamingEventArgs.cs create mode 100755 src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager/VoiceCommand.cs create mode 100755 src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager/VoiceCommandsGroup.cs create mode 100755 src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager/VoiceControlManagerClient.cs diff --git a/src/Tizen.Uix.VoiceControlManager/Interop/Interop.Libraries.cs b/src/Tizen.Uix.VoiceControlManager/Interop/Interop.Libraries.cs new file mode 100755 index 0000000..68f559b --- /dev/null +++ b/src/Tizen.Uix.VoiceControlManager/Interop/Interop.Libraries.cs @@ -0,0 +1,30 @@ +/* +* Copyright (c) 2019 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"; + internal const string VoiceControlManager = "libvc_manager.so"; + } +} diff --git a/src/Tizen.Uix.VoiceControlManager/Interop/Interop.Manager.cs b/src/Tizen.Uix.VoiceControlManager/Interop/Interop.Manager.cs new file mode 100755 index 0000000..4421916 --- /dev/null +++ b/src/Tizen.Uix.VoiceControlManager/Interop/Interop.Manager.cs @@ -0,0 +1,278 @@ +// Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved +// +// This software is the confidential and proprietary information +// of Samsung Electronics, Inc. ("Confidential Information"). You +// shall not disclose such Confidential Information and shall use +// it only in accordance with the terms of the license agreement +// you entered into with Samsung. + +using System; +using System.Runtime.InteropServices; +using static Interop.VoiceControlCommand; +using Tizen.Uix.VoiceControlManager; + +internal static partial class Interop +{ + internal static partial class VoiceControlManager + { + internal static string LogTag = "Tizen.Uix.VoiceControlManager"; + + 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) */ + NotSupportedFeature = ErrorVoiceControl | 0x022 /* Not supported feature of current engine (Since 4.0) */ + }; + + [DllImport(Libraries.VoiceControlManager, EntryPoint = "vc_mgr_initialize")] + internal static extern ErrorCode VcMgrInitialize(); + + [DllImport(Libraries.VoiceControlManager, EntryPoint = "vc_mgr_deinitialize")] + internal static extern ErrorCode VcMgrDeinitialize(); + + [DllImport(Libraries.VoiceControlManager, EntryPoint = "vc_mgr_prepare")] + internal static extern ErrorCode VcMgrPrepare(); + + [DllImport(Libraries.VoiceControlManager, EntryPoint = "vc_mgr_unprepare")] + internal static extern ErrorCode VcMgrUnprepare(); + + [DllImport(Libraries.VoiceControlManager, EntryPoint = "vc_mgr_foreach_supported_languages")] + internal static extern ErrorCode VcMgrForeachSupportedLanguages(VcMgrSupportedLanguageCallback callback, IntPtr userData); + + [DllImport(Libraries.VoiceControlManager, EntryPoint = "vc_mgr_get_current_language")] + internal static extern ErrorCode VcMgrGetCurrentLanguage(out string language); + + [DllImport(Libraries.VoiceControlManager, EntryPoint = "vc_mgr_get_state")] + internal static extern ErrorCode VcMgrGetState(out State state); + + [DllImport(Libraries.VoiceControlManager, EntryPoint = "vc_mgr_get_service_state")] + internal static extern ErrorCode VcMgrGetServiceState(out ServiceState state); + + [DllImport(Libraries.VoiceControlManager, EntryPoint = "vc_mgr_is_command_format_supported")] + internal static extern ErrorCode VcMgrIsCommandFormatSupported(CommandFormat format, out bool support); + + [DllImport(Libraries.VoiceControlManager, EntryPoint = "vc_mgr_set_command_list")] + internal static extern ErrorCode VcMgrSetCommandList(SafeCommandListHandle vcCmdList); + + [DllImport(Libraries.VoiceControlManager, EntryPoint = "vc_mgr_unset_command_list")] + internal static extern ErrorCode VcMgrUnsetCommandList(); + + [DllImport(Libraries.VoiceControlManager, EntryPoint = "vc_mgr_set_command_list_from_file")] + internal static extern ErrorCode VcMgrSetCommandListFromFile(string filePath, CommandType type); + + [DllImport(Libraries.VoiceControlManager, EntryPoint = "vc_mgr_get_current_commands")] + internal static extern ErrorCode VcMgrGetCurrentCommands(out IntPtr vcCmdList); + + [DllImport(Libraries.VoiceControlManager, EntryPoint = "vc_mgr_set_audio_type")] + internal static extern ErrorCode VcMgrSetAudioType(string audioId); + + [DllImport(Libraries.VoiceControlManager, EntryPoint = "vc_mgr_get_audio_type")] + internal static extern ErrorCode VcMgrGetAudioType(out string audioId); + + [DllImport(Libraries.VoiceControlManager, EntryPoint = "vc_mgr_set_recognition_mode")] + internal static extern ErrorCode VcMgrSetRecognitionMode(RecognitionModeType mode); + + [DllImport(Libraries.VoiceControlManager, EntryPoint = "vc_mgr_get_recognition_mode")] + internal static extern ErrorCode VcMgrGetRecognitionMode(out RecognitionModeType mode); + + [DllImport(Libraries.VoiceControlManager, EntryPoint = "vc_mgr_set_private_data")] + internal static extern ErrorCode VcMgrSetPrivateData(string key, string data); + + [DllImport(Libraries.VoiceControlManager, EntryPoint = "vc_mgr_get_private_data")] + internal static extern ErrorCode VcMgrGetPrivateData(string key, out string data); + + [DllImport(Libraries.VoiceControlManager, EntryPoint = "vc_mgr_do_action")] + internal static extern ErrorCode VcMgrDoAction(SendEventType type, string sendEvent); + + [DllImport(Libraries.VoiceControlManager, EntryPoint = "vc_mgr_send_specific_engine_request")] + internal static extern ErrorCode VcMgrSendSpecificEngineRequest(string engineAppId, string evt, string request); + + [DllImport(Libraries.VoiceControlManager, EntryPoint = "vc_mgr_start")] + internal static extern ErrorCode VcMgrStart(bool exclusiveCommandOption); + + [DllImport(Libraries.VoiceControlManager, EntryPoint = "vc_mgr_stop")] + internal static extern ErrorCode VcMgrStop(); + + [DllImport(Libraries.VoiceControlManager, EntryPoint = "vc_mgr_cancel")] + internal static extern ErrorCode VcMgrCancel(); + + [DllImport(Libraries.VoiceControlManager, EntryPoint = "vc_mgr_get_recording_volume")] + internal static extern ErrorCode VcMgrGetRecordingVolume(out float volume); + + [DllImport(Libraries.VoiceControlManager, EntryPoint = "vc_mgr_set_selected_results")] + internal static extern ErrorCode VcMgrSetSelectedResults(SafeCommandListHandle vcCmdList); + + [DllImport(Libraries.VoiceControlManager, EntryPoint = "vc_mgr_set_all_result_cb")] + internal static extern ErrorCode VcMgrSetAllResultCb(VcMgrAllResultCallback callback, IntPtr userData); + + [DllImport(Libraries.VoiceControlManager, EntryPoint = "vc_mgr_unset_all_result_cb")] + internal static extern ErrorCode VcMgrUnsetAllResultCb(); + + [DllImport(Libraries.VoiceControlManager, EntryPoint = "vc_mgr_set_pre_result_cb")] + internal static extern ErrorCode VcMgrSetPreResultCb(VcMgrPreResultCallback callback, IntPtr userData); + + [DllImport(Libraries.VoiceControlManager, EntryPoint = "vc_mgr_unset_pre_result_cb")] + internal static extern ErrorCode VcMgrUnsetPreResultCb(); + + [DllImport(Libraries.VoiceControlManager, EntryPoint = "vc_mgr_set_specific_engine_result_cb")] + internal static extern ErrorCode VcMgrSetSpecificEngineResultCb(VcMgrSpecificEngineResultCallback callback, IntPtr userData); + + [DllImport(Libraries.VoiceControlManager, EntryPoint = "vc_mgr_unset_specific_engine_result_cb")] + internal static extern ErrorCode VcMgrUnsetSpecificEngineResultCb(); + + [DllImport(Libraries.VoiceControlManager, EntryPoint = "vc_mgr_set_result_cb")] + internal static extern ErrorCode VcMgrSetResultCb(VcMgrResultCallback callback, IntPtr userData); + + [DllImport(Libraries.VoiceControlManager, EntryPoint = "vc_mgr_unset_result_cb")] + internal static extern ErrorCode VcMgrUnsetResultCb(); + + [DllImport(Libraries.VoiceControlManager, EntryPoint = "vc_mgr_set_state_changed_cb")] + internal static extern ErrorCode VcMgrSetStateChangedCb(VcMgrStateChangedCallback callback, IntPtr userData); + + [DllImport(Libraries.VoiceControlManager, EntryPoint = "vc_mgr_unset_state_changed_cb")] + internal static extern ErrorCode VcMgrUnsetStateChangedCb(); + + [DllImport(Libraries.VoiceControlManager, EntryPoint = "vc_mgr_set_service_state_changed_cb")] + internal static extern ErrorCode VcMgrSetServiceStateChangedCb(VcMgrServiceStateChangedCallback callback, IntPtr userData); + + [DllImport(Libraries.VoiceControlManager, EntryPoint = "vc_mgr_unset_service_state_changed_cb")] + internal static extern ErrorCode VcMgrUnsetServiceStateChangedCb(); + + [DllImport(Libraries.VoiceControlManager, EntryPoint = "vc_mgr_set_speech_detected_cb")] + internal static extern ErrorCode VcMgrSetSpeechDetectedCb(VcMgrBeginSpeechDetectedCallback callback, IntPtr userData); + + [DllImport(Libraries.VoiceControlManager, EntryPoint = "vc_mgr_unset_speech_detected_cb")] + internal static extern ErrorCode VcMgrUnsetSpeechDetectedCb(); + + [DllImport(Libraries.VoiceControlManager, EntryPoint = "vc_mgr_set_current_language_changed_cb")] + internal static extern ErrorCode VcMgrSetCurrentLanguageChangedCb(VcMgrCurrentLanguageChangedCallback callback, IntPtr userData); + + [DllImport(Libraries.VoiceControlManager, EntryPoint = "vc_mgr_unset_current_language_changed_cb")] + internal static extern ErrorCode VcMgrUnsetCurrentLanguageChangedCb(); + + [DllImport(Libraries.VoiceControlManager, EntryPoint = "vc_mgr_get_error_message")] + internal static extern ErrorCode VcMgrGetErrorMessage(out string errMsg); + + [DllImport(Libraries.VoiceControlManager, EntryPoint = "vc_mgr_set_error_cb")] + internal static extern ErrorCode VcMgrSetErrorCb(VcMgrErrorCallback callback, IntPtr userData); + + [DllImport(Libraries.VoiceControlManager, EntryPoint = "vc_mgr_unset_error_cb")] + internal static extern ErrorCode VcMgrUnsetErrorCb(); + + [DllImport(Libraries.VoiceControlManager, EntryPoint = "vc_mgr_set_dialog_request_cb")] + internal static extern ErrorCode VcMgrSetDialogRequestCb(VcMgrDialogRequestCallback callback, IntPtr userData); + + [DllImport(Libraries.VoiceControlManager, EntryPoint = "vc_mgr_unset_dialog_request_cb")] + internal static extern ErrorCode VcMgrUnsetDialogRequestCb(); + + [DllImport(Libraries.VoiceControlManager, EntryPoint = "vc_mgr_enable_command_type")] + internal static extern ErrorCode VcMgrEnableCommandType(CommandType cmdType); + + [DllImport(Libraries.VoiceControlManager, EntryPoint = "vc_mgr_disable_command_type")] + internal static extern ErrorCode VcMgrDisableCommandType(CommandType cmdType); + + [DllImport(Libraries.VoiceControlManager, EntryPoint = "vc_mgr_set_private_data_set_cb")] + internal static extern ErrorCode VcMgrSetPrivateDataSetCb(VcMgrPrivateDataSetCallback callback, IntPtr userData); + + [DllImport(Libraries.VoiceControlManager, EntryPoint = "vc_mgr_unset_private_data_set_cb")] + internal static extern ErrorCode VcMgrUnsetPrivateDataSetCb(); + + [DllImport(Libraries.VoiceControlManager, EntryPoint = "vc_mgr_set_private_data_requested_cb")] + internal static extern ErrorCode VcMgrSetPrivateDataRequestedCb(VcMgrPrivateDataRequestedCallback callback, IntPtr userData = default(IntPtr)); + + [DllImport(Libraries.VoiceControlManager, EntryPoint = "vc_mgr_unset_private_data_requested_cb")] + internal static extern ErrorCode VcMgrUnsetPrivateDataRequestedCb(); + + [DllImport(Libraries.VoiceControlManager, EntryPoint = "vc_mgr_set_feedback_audio_format_cb")] + internal static extern ErrorCode VcMgrSetFeedbackAudioFormatCb(VcMgrFeedbackAudioFormatCallback callback, IntPtr userData); + + [DllImport(Libraries.VoiceControlManager, EntryPoint = "vc_mgr_unset_feedback_audio_format_cb")] + internal static extern ErrorCode VcMgrUnsetFeedbackAudioFormatCb(); + + [DllImport(Libraries.VoiceControlManager, EntryPoint = "vc_mgr_set_feedback_streaming_cb")] + internal static extern ErrorCode VcMgrSetFeedbackStreamingCb(VcMgrFeedbackStreamingCallback callback, IntPtr userData); + + [DllImport(Libraries.VoiceControlManager, EntryPoint = "vc_mgr_unset_feedback_streaming_cb")] + internal static extern ErrorCode VcMgrUnsetFeedbackStreamingCb(); + + [DllImport(Libraries.VoiceControlManager, EntryPoint = "vc_mgr_start_feedback")] + internal static extern ErrorCode VcMgrStartFeedback(); + + [DllImport(Libraries.VoiceControlManager, EntryPoint = "vc_mgr_stop_feedback")] + internal static extern ErrorCode VcMgrStopFeedback(); + + [DllImport(Libraries.VoiceControlManager, EntryPoint = "vc_mgr_set_vc_tts_streaming_cb")] + internal static extern ErrorCode VcMgrSetVcTtsStreamingCb(VcMgrVcTtsStreamingCallback callback, IntPtr userData); + + [DllImport(Libraries.VoiceControlManager, EntryPoint = "vc_mgr_unset_vc_tts_streaming_cb")] + internal static extern ErrorCode VcMgrUnsetVcTtsStreamingCb(); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate bool VcMgrAllResultCallback(RecognizedResult result, IntPtr vcCmdList, IntPtr recognizedText, IntPtr msg, IntPtr userData); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void VcMgrPreResultCallback(PreResultEventType evt, IntPtr result, IntPtr userData); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void VcMgrSpecificEngineResultCallback(IntPtr engineAppId, IntPtr evt, IntPtr result, IntPtr userData); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void VcMgrBeginSpeechDetectedCallback(IntPtr userData); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void VcMgrDialogRequestCallback(int pid, IntPtr dispText, IntPtr uttText, bool continuous, IntPtr userData); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate int VcMgrPrivateDataSetCallback(IntPtr key, IntPtr data, IntPtr userData); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate VoiceError VcMgrPrivateDataRequestedCallback(string key, out string data, IntPtr userData); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void VcMgrFeedbackAudioFormatCallback(int rate, AudioChanelType channel, AudioType audioType, IntPtr userData); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void VcMgrFeedbackStreamingCallback(FeedbackType type, IntPtr buffer, int len, IntPtr userData); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void VcMgrVcTtsStreamingCallback(int pid, int uttId, FeedbackType type, IntPtr buffer, int len, IntPtr userData); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void VcMgrResultCallback(RecognizedResult result, IntPtr cmdList, IntPtr recognizedText, IntPtr userData); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void VcMgrCurrentLanguageChangedCallback(IntPtr previous, IntPtr current, IntPtr userData); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate bool VcMgrSupportedLanguageCallback(IntPtr language, IntPtr userData); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void VcMgrStateChangedCallback(State previous, State current, IntPtr userData); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void VcMgrServiceStateChangedCallback(ServiceState previous, ServiceState current, IntPtr userData); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void VcMgrErrorCallback(ErrorCode reason, IntPtr userData); + + } +} diff --git a/src/Tizen.Uix.VoiceControlManager/Interop/Interop.VoiceControlCommand.cs b/src/Tizen.Uix.VoiceControlManager/Interop/Interop.VoiceControlCommand.cs new file mode 100755 index 0000000..5783fca --- /dev/null +++ b/src/Tizen.Uix.VoiceControlManager/Interop/Interop.VoiceControlCommand.cs @@ -0,0 +1,160 @@ +/* +* Copyright (c) 2019 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.VoiceControlManager; +using static Interop.VoiceControlManager; + +/// +/// 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.VoiceControlManager.ErrorCode VcCmdListCreate(out SafeCommandListHandle cmdList); + + [DllImport(Libraries.VoiceControl, EntryPoint = "vc_cmd_list_destroy")] + internal static extern Interop.VoiceControlManager.ErrorCode VcCmdListDestroy(IntPtr cmdList, bool freeCommand); + + [DllImport(Libraries.VoiceControl, EntryPoint = "vc_cmd_list_get_count")] + internal static extern Interop.VoiceControlManager.ErrorCode VcCmdListGetCount(SafeCommandListHandle cmdList, out int count); + + [DllImport(Libraries.VoiceControl, EntryPoint = "vc_cmd_list_add")] + internal static extern Interop.VoiceControlManager.ErrorCode VcCmdListAdd(SafeCommandListHandle cmdList, SafeCommandHandle vcCommand); + + [DllImport(Libraries.VoiceControl, EntryPoint = "vc_cmd_list_remove")] + internal static extern Interop.VoiceControlManager.ErrorCode VcCmdListRemove(SafeCommandListHandle cmdList, SafeCommandHandle vcCommand); + + [DllImport(Libraries.VoiceControl, EntryPoint = "vc_cmd_list_foreach_commands")] + internal static extern Interop.VoiceControlManager.ErrorCode VcCmdListForeachCommands(SafeCommandListHandle cmdList, VcCmdListCb callback, IntPtr userData); + + [DllImport(Libraries.VoiceControl, EntryPoint = "vc_cmd_list_first")] + internal static extern Interop.VoiceControlManager.ErrorCode VcCmdListFirst(SafeCommandListHandle cmdList); + + [DllImport(Libraries.VoiceControl, EntryPoint = "vc_cmd_list_last")] + internal static extern Interop.VoiceControlManager.ErrorCode VcCmdListLast(SafeCommandListHandle cmdList); + + [DllImport(Libraries.VoiceControl, EntryPoint = "vc_cmd_list_next")] + internal static extern Interop.VoiceControlManager.ErrorCode VcCmdListNext(SafeCommandListHandle cmdList); + + [DllImport(Libraries.VoiceControl, EntryPoint = "vc_cmd_list_prev")] + internal static extern Interop.VoiceControlManager.ErrorCode VcCmdListPrev(SafeCommandListHandle cmdList); + + [DllImport(Libraries.VoiceControl, EntryPoint = "vc_cmd_list_get_current")] + internal static extern Interop.VoiceControlManager.ErrorCode VcCmdListGetCurrent(SafeCommandListHandle cmdList, out SafeCommandHandle vcCommand); + + [DllImport(Libraries.VoiceControl, EntryPoint = "vc_cmd_create")] + internal static extern Interop.VoiceControlManager.ErrorCode VcCmdCreate(out SafeCommandHandle vcCommand); + + [DllImport(Libraries.VoiceControl, EntryPoint = "vc_cmd_destroy")] + internal static extern Interop.VoiceControlManager.ErrorCode VcCmdDestroy(IntPtr vcCommand); + + [DllImport(Libraries.VoiceControl, EntryPoint = "vc_cmd_set_command")] + internal static extern Interop.VoiceControlManager.ErrorCode VcCmdSetCommand(SafeCommandHandle vcCommand, string command); + + [DllImport(Libraries.VoiceControl, EntryPoint = "vc_cmd_get_command")] + internal static extern Interop.VoiceControlManager.ErrorCode VcCmdGetCommand(SafeCommandHandle vcCommand, out string command); + + [DllImport(Libraries.VoiceControl, EntryPoint = "vc_cmd_get_unfixed_command")] + internal static extern Interop.VoiceControlManager.ErrorCode VcCmdGetUnfixedCommand(SafeCommandHandle vcCommand, out string command); + + [DllImport(Libraries.VoiceControl, EntryPoint = "vc_cmd_set_type")] + internal static extern Interop.VoiceControlManager.ErrorCode VcCmdSetType(SafeCommandHandle vcCommand, CommandType type); + + [DllImport(Libraries.VoiceControl, EntryPoint = "vc_cmd_get_type")] + internal static extern Interop.VoiceControlManager.ErrorCode VcCmdGetType(SafeCommandHandle vcCommand, out int type); + + [DllImport(Libraries.VoiceControl, EntryPoint = "vc_cmd_set_format")] + internal static extern Interop.VoiceControlManager.ErrorCode VcCmdSetFormat(SafeCommandHandle vcCommand, CommandFormat format); + + [DllImport(Libraries.VoiceControl, EntryPoint = "vc_cmd_get_format")] + internal static extern Interop.VoiceControlManager.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.VoiceControlManager.ErrorCode error = VcCmdListDestroy(this.handle, false); + if (error != Interop.VoiceControlManager.ErrorCode.None) + { + Log.Error(VoiceControlManager.LogTag, "Destroy Failed with error " + error); + } + } + this.SetHandle(IntPtr.Zero); + return true; + } + } + + internal sealed class SafeCommandHandle : SafeHandle + { + public SafeCommandHandle(IntPtr handle) + : base(handle, true) + { + } + public SafeCommandHandle() + : base(IntPtr.Zero, true) + { + } + + public override bool IsInvalid + { + get { return this.handle == IntPtr.Zero; } + } + + protected override bool ReleaseHandle() + { + Interop.VoiceControlManager.ErrorCode error = VoiceControlManager.ErrorCode.None; + if (!IsInvalid) + { + error = VcCmdDestroy(this.handle); + if (error != Interop.VoiceControlManager.ErrorCode.None) + { + Log.Error(VoiceControlManager.LogTag, "Destroy Failed with error " + error); + } + } + this.SetHandle(IntPtr.Zero); + return true; + } + } + } +} \ No newline at end of file diff --git a/src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager.csproj b/src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager.csproj new file mode 100644 index 0000000..24b16bb --- /dev/null +++ b/src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager.csproj @@ -0,0 +1,20 @@ + + + + netstandard2.0 + + + + + + + + + + + all + runtime; build; native; contentfiles; analyzers + + + + diff --git a/src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager.sln b/src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager.sln new file mode 100755 index 0000000..b5e0983 --- /dev/null +++ b/src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager.sln @@ -0,0 +1,42 @@ +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.26430.12 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tizen.Uix.VoiceControlManager", "Tizen.Uix.VoiceControlManager.csproj", "{AC360AFA-F9E0-418A-BFFE-F88CABCE419D}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tizen", "..\Tizen\Tizen.csproj", "{90B368FB-387B-4822-9161-854A59FCF749}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tizen.Log", "..\Tizen.Log\Tizen.Log.csproj", "{44082C95-BC74-48AE-B7C3-F6F6DB759D15}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tizen.Applications.Common", "..\Tizen.Applications.Common\Tizen.Applications.Common.csproj", "{C38800D6-AB85-4D6E-9C3F-F79C7C3ED4EB}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {AC360AFA-F9E0-418A-BFFE-F88CABCE419D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AC360AFA-F9E0-418A-BFFE-F88CABCE419D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AC360AFA-F9E0-418A-BFFE-F88CABCE419D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AC360AFA-F9E0-418A-BFFE-F88CABCE419D}.Release|Any CPU.Build.0 = Release|Any CPU + {90B368FB-387B-4822-9161-854A59FCF749}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {90B368FB-387B-4822-9161-854A59FCF749}.Debug|Any CPU.Build.0 = Debug|Any CPU + {90B368FB-387B-4822-9161-854A59FCF749}.Release|Any CPU.ActiveCfg = Release|Any CPU + {90B368FB-387B-4822-9161-854A59FCF749}.Release|Any CPU.Build.0 = Release|Any CPU + {44082C95-BC74-48AE-B7C3-F6F6DB759D15}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {44082C95-BC74-48AE-B7C3-F6F6DB759D15}.Debug|Any CPU.Build.0 = Debug|Any CPU + {44082C95-BC74-48AE-B7C3-F6F6DB759D15}.Release|Any CPU.ActiveCfg = Release|Any CPU + {44082C95-BC74-48AE-B7C3-F6F6DB759D15}.Release|Any CPU.Build.0 = Release|Any CPU + {C38800D6-AB85-4D6E-9C3F-F79C7C3ED4EB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C38800D6-AB85-4D6E-9C3F-F79C7C3ED4EB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C38800D6-AB85-4D6E-9C3F-F79C7C3ED4EB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C38800D6-AB85-4D6E-9C3F-F79C7C3ED4EB}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {9AD281F1-4BFA-49BB-A9FA-5839075C4DBE} + EndGlobalSection +EndGlobal diff --git a/src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager/AllRecognitionResultEventArgs.cs b/src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager/AllRecognitionResultEventArgs.cs new file mode 100755 index 0000000..dc9db22 --- /dev/null +++ b/src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager/AllRecognitionResultEventArgs.cs @@ -0,0 +1,55 @@ +/* +* Copyright (c) 2019 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; + +namespace Tizen.Uix.VoiceControlManager +{ + /// + /// This class contains the all recognition results from vc-daemon. + /// + /// 6 + public class AllRecognitionResultEventArgs : EventArgs + { + internal AllRecognitionResultEventArgs(RecognizedResult result, string recognizedText, string msg) + { + Result = result; + RecognizedText = recognizedText; + Message = msg; + } + + /// + /// The result of recognizing a VoiceCommand. + /// + /// 6 + public RecognizedResult Result { get; } + + /// + /// The recognized text. + /// + /// 6 + public string RecognizedText { get; } + + /// + /// Engine message, it can be one of the below: + /// 1. "vc.result.message.none" + /// 2. "vc.result.message.asr.result.consumed" + /// 3. "vc.result.message.error.too.loud" + /// + /// 6 + public string Message { get; } + } +} diff --git a/src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager/ConversationRequestedEventArgs.cs b/src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager/ConversationRequestedEventArgs.cs new file mode 100755 index 0000000..aefbad4 --- /dev/null +++ b/src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager/ConversationRequestedEventArgs.cs @@ -0,0 +1,74 @@ +/* +* Copyright (c) 2019 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; + +namespace Tizen.Uix.VoiceControlManager +{ + /// + /// This Class contains the requests conversation from vc-daemon. + /// + public class ConversationRequestedEventArgs : EventArgs + { + internal ConversationRequestedEventArgs(string appId, string dispTextString, string uttTextString, bool continuous) + { + AppId = appId; + DisplayText = dispTextString; + UtterenceText = uttTextString; + IsContinuous = continuous; + } + + /// + /// The application id of VC client to request dialog + /// + /// 6 + public string AppId + { + get; + private set; + } + + /// + /// The display text requested to be displayed + /// + /// 6 + public string DisplayText + { + get; + private set; + } + + /// + /// The utterence text requested to be spoken + /// + /// 6 + public string UtterenceText + { + get; + private set; + } + + /// + /// If true, VoiceControlManager still has a conversation to deal with. And Start() should be called again. + /// + /// 6 + public bool IsContinuous + { + get; + private set; + } + } +} \ No newline at end of file diff --git a/src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager/CurrentLanguageChangedEventArgs.cs b/src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager/CurrentLanguageChangedEventArgs.cs new file mode 100755 index 0000000..f2e2405 --- /dev/null +++ b/src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager/CurrentLanguageChangedEventArgs.cs @@ -0,0 +1,53 @@ +/* +* Copyright (c) 2019 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; + +namespace Tizen.Uix.VoiceControlManager +{ + /// + /// This class holds information about the CurrentLanguageChanged event. + /// + /// 6 + public class CurrentLanguageChangedEventArgs : EventArgs + { + internal CurrentLanguageChangedEventArgs(string previous, string current) + { + PreviousLanguage = previous; + CurrentLanguage = current; + } + + /// + /// The previous language. + /// + /// 6 + public string PreviousLanguage + { + get; + set; + } + + /// + /// The current language. + /// + /// 6 + public string CurrentLanguage + { + get; + private set; + } + } +} \ No newline at end of file diff --git a/src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager/ErrorOccurerdEventArgs.cs b/src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager/ErrorOccurerdEventArgs.cs new file mode 100755 index 0000000..9f6950c --- /dev/null +++ b/src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager/ErrorOccurerdEventArgs.cs @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2019 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.VoiceControlManager; + +namespace Tizen.Uix.VoiceControlManager +{ + /// + /// This class holds information related to the VoiceControl ErrorOccurred event. + /// + /// 6 + public class ErrorOccurredEventArgs : EventArgs + { + internal ErrorOccurredEventArgs(Exception error) + { + Why = error; + } + + /// + /// The VoiceControlManager exception. + /// + /// 6 + public Exception Why { + get; + private set; + } + } +} diff --git a/src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager/ExceptionFactory.cs b/src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager/ExceptionFactory.cs new file mode 100755 index 0000000..95a557d --- /dev/null +++ b/src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager/ExceptionFactory.cs @@ -0,0 +1,86 @@ +/* +* Copyright (c) 2019 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.VoiceControlManager; + +namespace Tizen.Uix.VoiceControlManager +{ + internal static class ExceptionFactory + { + internal static Exception CreateException(ErrorCode err) + { + Tizen.Log.Error(LogTag, "Error " + err); + switch (err) + { + case ErrorCode.OutOfMemory: + return new InvalidOperationException("Out Of Memory"); + + case ErrorCode.IoError: + return new InvalidOperationException("I/O Error Occurred"); + + case ErrorCode.InvalidParameter: + return new ArgumentException("Invalid Parameters Provided"); + + case ErrorCode.TimedOut: + return new TimeoutException("No answer from service"); + + case ErrorCode.RecorderBusy: + return new InvalidOperationException("Recorder is Busy "); + + case ErrorCode.PermissionDenied: + return new UnauthorizedAccessException("Permission Denied"); + + case ErrorCode.NotSupported: + return new NotSupportedException("VC NOT supported"); + + case ErrorCode.InvalidState: + return new InvalidOperationException("Invalid state"); + + case ErrorCode.InvalidLanguage: + return new InvalidOperationException("Invalid language"); + + case ErrorCode.EngineNotFound: + return new InvalidOperationException("No available engine"); + + case ErrorCode.OperationFailed: + return new InvalidOperationException("Operation Failed"); + + case ErrorCode.OperationRejected: + return new InvalidOperationException("Operation Rejected"); + + case ErrorCode.IterationEnd: + return new InvalidOperationException("List Reached End"); + + case ErrorCode.Empty: + return new InvalidOperationException("List Empty"); + + case ErrorCode.InProgressToReady: + return new InvalidOperationException("Progress to ready is not finished"); + + case ErrorCode.InProgressToRecording: + return new InvalidOperationException("Progress to recording is not finished"); + + case ErrorCode.InProgressToProcessing: + return new InvalidOperationException("Progress to processing is not finished"); + + case ErrorCode.ServiceReset: + return new InvalidOperationException("Service reset"); + } + return new InvalidOperationException("Unknown error : {err.ToString()}"); + } + } +} diff --git a/src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager/FeedbackAudioFormatEventArgs.cs b/src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager/FeedbackAudioFormatEventArgs.cs new file mode 100755 index 0000000..22dad15 --- /dev/null +++ b/src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager/FeedbackAudioFormatEventArgs.cs @@ -0,0 +1,63 @@ +/* +* Copyright (c) 2019 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; + +namespace Tizen.Uix.VoiceControlManager +{ + /// + /// This Class contains audio formats necessary for playing TTS feedback. + /// + public class FeedbackAudioFormatEventArgs : EventArgs + { + internal FeedbackAudioFormatEventArgs(int rate, AudioChanelType channel, AudioType audioType) + { + Rate = rate; + Channel = channel; + Audio = audioType; + } + + /// + /// Audio sampling rate + /// + /// 6 + public int Rate + { + get; + private set; + } + + /// + /// Audio channel + /// + /// 6 + public AudioChanelType Channel + { + get; + private set; + } + + /// + /// Audio type + /// + /// 6 + public AudioType Audio + { + get; + private set; + } + } +} \ No newline at end of file diff --git a/src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager/FeedbackStreamingEventArgs.cs b/src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager/FeedbackStreamingEventArgs.cs new file mode 100755 index 0000000..cf57ed1 --- /dev/null +++ b/src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager/FeedbackStreamingEventArgs.cs @@ -0,0 +1,52 @@ +/* +* Copyright (c) 2019 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; + +namespace Tizen.Uix.VoiceControlManager +{ + /// + /// This Class contains the pre recognition results(partial ASR) from vc-daemon. + /// + public class FeedbackStreamingEventArgs : EventArgs + { + internal FeedbackStreamingEventArgs(FeedbackType type, byte[] buffer) + { + FeedbackType = type; + Buffer = buffer; + } + + /// + /// TTS feedback type + /// + /// 6 + public FeedbackType FeedbackType + { + get; + private set; + } + + /// + /// Audio streaming data + /// + /// 6 + public byte[] Buffer + { + get; + private set; + } + } +} \ No newline at end of file diff --git a/src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager/PreRecognitionResultUpdatedEventArgs.cs b/src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager/PreRecognitionResultUpdatedEventArgs.cs new file mode 100755 index 0000000..2d4af85 --- /dev/null +++ b/src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager/PreRecognitionResultUpdatedEventArgs.cs @@ -0,0 +1,52 @@ +/* +* Copyright (c) 2019 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; + +namespace Tizen.Uix.VoiceControlManager +{ + /// + /// This Class contains the pre recognition results(partial ASR) from vc-daemon. + /// + public class PreRecognitionResultUpdatedEventArgs : EventArgs + { + internal PreRecognitionResultUpdatedEventArgs(PreResultEventType evt, string resultString) + { + ResultEvent = evt; + Result = resultString; + } + + /// + /// The pre result event + /// + /// 6 + public PreResultEventType ResultEvent + { + get; + private set; + } + + /// + /// Result ASR text + /// + /// 6 + public string Result + { + get; + private set; + } + } +} diff --git a/src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager/PrivateDataUpdatedEventArgs.cs b/src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager/PrivateDataUpdatedEventArgs.cs new file mode 100755 index 0000000..d80150c --- /dev/null +++ b/src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager/PrivateDataUpdatedEventArgs.cs @@ -0,0 +1,52 @@ +/* +* Copyright (c) 2019 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; + +namespace Tizen.Uix.VoiceControlManager +{ + /// + /// This Class contains sets private data to manager client. + /// + public class PrivateDataUpdatedEventArgs : EventArgs + { + internal PrivateDataUpdatedEventArgs(string key, string data) + { + Key = key; + Data = data; + } + + /// + /// Private key + /// + /// 6 + public string Key + { + get; + private set; + } + + /// + /// Private data + /// + /// 6 + public string Data + { + get; + private set; + } + } +} \ No newline at end of file diff --git a/src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager/RecognitionResultUpdatedEventArgs.cs b/src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager/RecognitionResultUpdatedEventArgs.cs new file mode 100755 index 0000000..8683381 --- /dev/null +++ b/src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager/RecognitionResultUpdatedEventArgs.cs @@ -0,0 +1,122 @@ +/* +* Copyright (c) 2019 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.VoiceControlManager; +using static Interop.VoiceControlCommand; + +namespace Tizen.Uix.VoiceControlManager +{ + /// + /// The recognition result from the engine. + /// If the duplicated commands are recognized, the event(e.g. Result.Rejected) of a command may be rejected + /// for selecting the command as a priority. If you set similar or same commands, or the recognized results are multi-results, the CommandList has multi commands. + /// + /// 6 + public class RecognitionResultUpdatedEventArgs : IDisposable + { + private RecognizedResult _result; + private IEnumerable _command; + private string _recognizedText; + private bool _disposed = false; + + internal RecognitionResultUpdatedEventArgs(RecognizedResult result, IntPtr cmdList, IntPtr recognizedText) + { + _result = result; + SafeCommandListHandle handle = new SafeCommandListHandle(cmdList); + VoiceCommandsGroup _list = new VoiceCommandsGroup(handle); + _command = _list.Commands; + _recognizedText = Marshal.PtrToStringAnsi(recognizedText); + } + + /// + /// The destructor of the RecognitionResultEventArgs class. + /// + /// 6 + ~RecognitionResultUpdatedEventArgs() + { + Dispose(false); + } + + /// + /// The result of recognizing a VoiceCommand. + /// + /// 6 + public RecognizedResult Result + { + get + { + return _result; + } + } + + /// + /// The recognized text. + /// + /// 6 + public string RecognizedText + { + get + { + return _recognizedText; + } + } + + /// + /// The recognized command list. + /// + /// 6 + public IEnumerable Commands + { + get + { + return _command; + } + } + + /// + /// Release any unmanaged resources used by this object. + /// + /// 6 + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + /// + /// Release any unmanaged resources used by this object. + /// + /// + /// If true, disposes any disposable objects. If false, does not dispose disposable objects. + /// + /// 6 + protected virtual void Dispose(bool disposing) + { + if (_disposed) + return; + + if (disposing) + { + // Free managed objects + } + + _disposed = true; + } + } +} diff --git a/src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager/ServiceStateChangedEventArgs.cs b/src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager/ServiceStateChangedEventArgs.cs new file mode 100755 index 0000000..4e3c0f9 --- /dev/null +++ b/src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager/ServiceStateChangedEventArgs.cs @@ -0,0 +1,53 @@ +/* +* Copyright (c) 2019 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; + +namespace Tizen.Uix.VoiceControlManager +{ + /// + /// This class holds information related to the VoiceControl service ServiceStateChanged event. + /// + /// 6 + public class ServiceStateChangedEventArgs : EventArgs + { + internal ServiceStateChangedEventArgs(ServiceState previous, ServiceState current) + { + Previous = previous; + Current = current; + } + + /// + /// The previous state. + /// + /// 6 + public ServiceState Previous + { + get; + private set; + } + + /// + /// The current state. + /// + /// 6 + public ServiceState Current + { + get; + private set; + } + } +} diff --git a/src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager/SpecificEngineResultEventArgs.cs b/src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager/SpecificEngineResultEventArgs.cs new file mode 100755 index 0000000..ab3bb84 --- /dev/null +++ b/src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager/SpecificEngineResultEventArgs.cs @@ -0,0 +1,68 @@ +/* +* Copyright (c) 2019 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.VoiceControlManager; +using static Interop.VoiceControlCommand; + +namespace Tizen.Uix.VoiceControlManager +{ + /// + /// This Class contains the gets specific engine's result from vc-service. + /// + /// 6 + public class SpecificEngineResultEventArgs : EventArgs + { + internal SpecificEngineResultEventArgs(string engineAppId, string evt, string result) + { + EngineAppId = engineAppId; + EngineEventType = evt; + Result = result; + } + + /// + /// The specific engine's app id + /// + /// 6 + public string EngineAppId + { + get; + private set; + } + + /// + /// The specific engine event type + /// + /// 6 + public string EngineEventType + { + get; + private set; + } + + /// + /// The specific engine result + /// + /// 6 + public string Result + { + get; + private set; + } + } +} diff --git a/src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager/StateChangedEventArgs.cs b/src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager/StateChangedEventArgs.cs new file mode 100755 index 0000000..b7cf1a1 --- /dev/null +++ b/src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager/StateChangedEventArgs.cs @@ -0,0 +1,53 @@ +/* +* Copyright (c) 2019 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; + +namespace Tizen.Uix.VoiceControlManager +{ + /// + /// This class holds information related to the VoiceControl client StateChanged event. + /// + /// 6 + public class StateChangedEventArgs : EventArgs + { + internal StateChangedEventArgs(State previous, State current) + { + Previous = previous; + Current = current; + } + + /// + /// The previous state. + /// + /// 6 + public State Previous + { + get; + private set; + } + + /// + /// The current state. + /// + /// 6 + public State Current + { + get; + private set; + } + } +} diff --git a/src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager/VcTtsStreamingEventArgs.cs b/src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager/VcTtsStreamingEventArgs.cs new file mode 100755 index 0000000..6ba571e --- /dev/null +++ b/src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager/VcTtsStreamingEventArgs.cs @@ -0,0 +1,74 @@ +/* +* Copyright (c) 2019 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; + +namespace Tizen.Uix.VoiceControlManager +{ + /// + /// This Class contains the vc client sends audio streaming for TTS feedback. + /// + public class VcTtsStreamingEventArgs : EventArgs + { + internal VcTtsStreamingEventArgs(string appId, int uttId, FeedbackType type, byte[] buffer) + { + AppId = appId; + UtteranceId = uttId; + FeedbackType = type; + Buffer = buffer; + } + + /// + /// The application id of the vc client + /// + /// 6 + public string AppId + { + get; + private set; + } + + /// + /// The utterance id + /// + /// 6 + public int UtteranceId + { + get; + private set; + } + + /// + /// TTS feedback event which knows current status, app should receive until finish events comes up. + /// + /// 6 + public FeedbackType FeedbackType + { + get; + private set; + } + + /// + /// Audio streaming data + /// + /// 6 + public byte[] Buffer + { + get; + private set; + } + } +} diff --git a/src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager/VoiceCommand.cs b/src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager/VoiceCommand.cs new file mode 100755 index 0000000..0774c9e --- /dev/null +++ b/src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager/VoiceCommand.cs @@ -0,0 +1,261 @@ +/* +* Copyright (c) 2019 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.VoiceControlManager; +using static Interop.VoiceControlCommand; + +namespace Tizen.Uix.VoiceControlManager +{ + /// + /// Enumeration for the command format. + /// + /// 6 + public enum CommandFormat + { + /// + /// The fixed command format. + /// + Fixed = 0, + /// + /// The fixed and variable fixed command format. + /// + FixedAndVFixed = 1, + /// + /// The variable fixed and fixed command format. + /// + VFixedAndFixed = 2, + /// + /// The fixed and non-fixed command format. + /// + FixedAndNonFixed = 3, + /// + /// The non-fixed and fixed command format. + /// + NonFixedAndFixed = 4, + /// + /// The action command + /// + Action = 5, + /// + /// The partial matched command + /// + Partial = 6, + /// + /// Undefined + /// + Undefined = -1 + }; + + /// + /// This class represents a voice command. + /// + /// 6 + public class VoiceCommand : IDisposable + { + internal SafeCommandHandle _handle; + private bool _disposed = false; + + /// + /// The public constructor. + /// + /// 6 + /// + /// This can occur due to the following reasons: + /// 1) This exception can be due to an invalid state. + /// 2) This exception can be due to out of memory. + /// + /// This exception can be due to permission denied. + /// The required feature is not supported. + 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; + } + + /// + /// The destructor of the VoiceCommand class. + /// + /// 6 + ~VoiceCommand() + { + Dispose(false); + } + + /// + /// Gets the unfixed command. + /// This property should be used for commands which have non-fixed format. + /// An empty string will be returned in case of some internal error. + /// + /// 6 + public string UnfixedCommand + { + get + { + string unfixedCommand; + ErrorCode error = VcCmdGetUnfixedCommand(_handle, out unfixedCommand); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "UnfixedCommand Failed with error " + error); + return string.Empty; + } + + return unfixedCommand; + } + } + + /// + /// Gets or sets the command type. + /// + /// 6 + /// If you do not set the command type, the default value is undefined. You should set the type if the command is valid. + /// This exception can be due to permission denied. + /// The required feature is not supported. + public CommandType CommandType + { + 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 or sets the command format. + /// + /// 6 + /// The default format is Fixed. + /// This exception can be due to permission denied. + /// The required feature is 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 or sets the command. + /// A get empty string will be returned in case of some internal error. + /// + /// 6 + /// This exception can be due to permission denied. + /// The required feature is 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 string.Empty; + } + + return command; + } + set + { + ErrorCode error = VcCmdSetCommand(_handle, value); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "SetCommand Failed with error " + error); + } + } + } + + /// + /// Release any unmanaged resources used by this object. + /// + /// 6 + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + /// + /// Release any unmanaged resources used by this object. + /// + /// + /// If true, disposes any disposable objects. If false, does not dispose disposable objects. + /// + /// 6 + protected virtual void Dispose(bool disposing) + { + if (_disposed) + return; + + if (disposing) + { + _handle?.Dispose(); + _handle = null; + } + + _disposed = true; + } + } +} diff --git a/src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager/VoiceCommandsGroup.cs b/src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager/VoiceCommandsGroup.cs new file mode 100755 index 0000000..b2ff135 --- /dev/null +++ b/src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager/VoiceCommandsGroup.cs @@ -0,0 +1,158 @@ +/* +* Copyright (c) 2019 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.Collections.ObjectModel; +using static Interop.VoiceControlManager; +using static Interop.VoiceControlCommand; +using System.Collections.Specialized; + +namespace Tizen.Uix.VoiceControlManager +{ + /// + /// This class represents a list of the voice commands. + /// + /// 6 + public class VoiceCommandsGroup : IDisposable + { + ObservableCollection _commands = new ObservableCollection(); + internal SafeCommandListHandle _handle; + private bool _disposed = false; + + /// + /// The public constructor. + /// + /// 6 + /// This exception can be due to out of memory. + /// This exception can be due to an invalid parameter. + /// This exception can be due to permission denied. + /// The required feature is not supported. + public VoiceCommandsGroup() + { + SafeCommandListHandle handle; + ErrorCode error = VcCmdListCreate(out handle); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "Create Failed with error " + error); + throw ExceptionFactory.CreateException(error); + } + _handle = handle; + _commands.CollectionChanged += OnCollectionChanged; + } + + internal VoiceCommandsGroup(SafeCommandListHandle handle) + { + _handle = handle; + + VcCmdListCb _callback = (IntPtr vcCommand, IntPtr userData) => + { + SafeCommandHandle cmdHandle = new SafeCommandHandle(vcCommand); + _commands.Add(new VoiceCommand(cmdHandle)); + 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); + } + _commands.CollectionChanged += OnCollectionChanged; + } + + /// + /// The destructor of the VoiceCommandList class. + /// + /// 6 + ~VoiceCommandsGroup() + { + Dispose(false); + } + + /// + /// Gets the command list. + /// + /// 6 + public IList Commands { get => _commands; } + + /// + /// Release any unmanaged resources used by this object. + /// + /// 6 + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + /// + /// Release any unmanaged resources used by this object. + /// + /// + /// If true, disposes any disposable objects. If false, does not dispose disposable objects. + /// + /// 6 + protected virtual void Dispose(bool disposing) + { + if (_disposed) + return; + + if (disposing) + { + _handle?.Dispose(); + _handle = null; + _commands.CollectionChanged -= OnCollectionChanged; + _commands.Clear(); + } + + _disposed = true; + } + + private void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) + { + if (e.Action == NotifyCollectionChangedAction.Add) + { + foreach (VoiceCommand item in e.NewItems) + Add(item); + } + else if (e.Action == NotifyCollectionChangedAction.Remove) + { + foreach (VoiceCommand item in e.OldItems) + Remove(item); + } + } + + 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); + } + } + + 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); + } + } + } +} diff --git a/src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager/VoiceControlManagerClient.cs b/src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager/VoiceControlManagerClient.cs new file mode 100755 index 0000000..21e7c4b --- /dev/null +++ b/src/Tizen.Uix.VoiceControlManager/Tizen.Uix.VoiceControlManager/VoiceControlManagerClient.cs @@ -0,0 +1,1990 @@ +/* +* Copyright (c) 2019 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 Tizen.Applications; +using static Interop.VoiceControlManager; +using static Interop.VoiceControlCommand; +using System.Text; + +namespace Tizen.Uix.VoiceControlManager +{ + /// + /// Enumeration for the error values that can occur. + /// + /// 6 + public enum VoiceError + { + /// + /// 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, + /// + /// Not supported feature of current engine. + /// + NotSupportedFeature + }; + + /// + /// Enumeration for the client state. + /// + /// 6 + public enum State + { + /// + /// 'None' state. + /// + None = 0, + /// + /// 'Initialized' state. + /// + Initialized = 1, + /// + /// 'Ready' state. + /// + Ready = 2, + /// + /// The state cannot be determined. + /// + Unavailable = -1 + }; + + /// + /// Enumeration for the service state. + /// + /// 6 + public enum ServiceState + { + /// + /// 'None' state. + /// + None = 0, + /// + /// 'Ready' state. + /// + Ready = 1, + /// + /// 'Recording' state. + /// + Recording = 2, + /// + /// 'Processing' state. + /// + Processing = 3, + /// + /// The state cannot be determined. + /// + Unavailable = -1 + }; + + /// + /// Enumeration for the result of recognizing a VoiceCommand + /// + /// 6 + public enum RecognizedResult + { + /// + /// Normal result. + /// + Success = 0, + /// + /// Rejected result. + /// + Rejected = 1 + }; + + /// + /// Enumeration for the command type. + /// + /// 6 + public enum CommandType + { + /// + /// foreground command type + /// + Foreground = 1, + /// + /// background command type + /// + Background = 2, + /// + /// widget command type + /// + Widget = 3, + /// + /// system command type + /// + System = 4, + /// + /// system background command type + /// + SystemBackground = 5, + /// + /// exclusive command type + /// + Exclusive = 6, + /// + /// Undefined command + /// + Undefined = -1 + }; + + /// + /// Enumerations of recognition mode + /// + /// 6 + public enum RecognitionModeType + { + /// + /// Default mode + /// + StopBySilence, + /// + /// Restart recognition after rejected result + /// + RestartAfterReject, + /// + /// Continuously restart recognition - not support yet + /// + RestartContinuously, + /// + /// Start and stop manually without silence + /// + Manual, + /// + /// Undefined + /// + Undefined = -1 + } + + /// + /// Enumerations of send event type + /// + /// 6 + public enum SendEventType + { + /// + /// Send text event to vc engine + /// + Text, + /// + /// Send list event to vc engine + /// + ListEvent, + /// + /// Send haptic event to vc engine + /// + HapticEvent, + } + + /// + /// Enumerations for audio channels + /// + /// 6 + public enum AudioChanelType + { + /// + /// 1 channel, mono + /// + Mono = 0, + /// + /// 2 channels, stereo + /// + Stereo + } + + /// + /// Enumerations of audio types + /// + /// 6 + public enum AudioType + { + /// + /// Signed 16bit audio type, Little endian + /// + PcmS16Le = 0, + /// + /// Unsigned 8bit audio type + /// + PcmU8 + } + + /// + /// Enumeration for TTS feedback type + /// + /// 6 + public enum FeedbackType + { + /// + /// Failed + /// + Fail = -1, + /// + /// Start event + /// + Start = 1, + /// + /// Continue event + /// + Continue = 2, + /// + /// Finish event + /// + Finish = 3 + } + + /// + /// Enumerations of pre result event + /// + /// 6 + public enum PreResultEventType + { + /// + /// Final result + /// + FinalResult = 0, + /// + /// Partial Result + /// + PartialResult, + /// + /// Error + /// + Error, + } + + /// + /// Voice Control Manager Class + /// + /// 6 + public static class VoiceControlManagerClient + { + private static event EventHandler _preResult; + private static event EventHandler _specificEngineResult; + private static event EventHandler _speechDetected; + private static event EventHandler _conversationRequested; + private static event EventHandler _privateDataSet; + private static event EventHandler _feedbackAudioFormat; + private static event EventHandler _feedbackStreaming; + private static event EventHandler _vcTtsStreaming; + private static event EventHandler _recognitionResult; + private static event EventHandler _currentLanguageChanged; + private static event EventHandler _stateChanged; + private static event EventHandler _serviceStateChanged; + private static event EventHandler _errorOccurred; + private static event EventHandler _allRecognitionResult; + private static VcMgrPreResultCallback _preResultDelegate; + private static VcMgrSpecificEngineResultCallback _specificEngineResultDelegate; + private static VcMgrBeginSpeechDetectedCallback _beginSpeechDetectedDelegate; + private static VcMgrDialogRequestCallback _conversationRequestDelegate; + private static VcMgrPrivateDataSetCallback _privateDataSetDelegate; + private static VcMgrPrivateDataRequestedCallback _privateDataRequestedDelegate; + private static VcMgrFeedbackAudioFormatCallback _feedbackAudioFormatDelegate; + private static VcMgrFeedbackStreamingCallback _feedbackStreamingDelegate; + private static VcMgrVcTtsStreamingCallback _vcTtsStreamingDelegate; + private static VcMgrResultCallback s_resultDelegate; + private static VcMgrCurrentLanguageChangedCallback _languageDelegate; + private static VcMgrStateChangedCallback _stateDelegate; + private static VcMgrServiceStateChangedCallback _serviceStateDelegate; + private static VcMgrErrorCallback _errorDelegate; + private static SelectRecognizedCommandsDelegate _recognizedCommandsDelegate; + + private static VcMgrAllResultCallback _recognizedCommandsSelectionCallback = (RecognizedResult result, IntPtr vcCmdList, IntPtr recognizedText, IntPtr msg, IntPtr userData) => + { + string recognizedString = Marshal.PtrToStringAnsi(recognizedText); + string msgString = Marshal.PtrToStringAnsi(msg); + + if (_allRecognitionResult != null) + { + AllRecognitionResultEventArgs args = new AllRecognitionResultEventArgs(result, recognizedString, msgString); + _allRecognitionResult?.Invoke(null, args); + if (result == RecognizedResult.Rejected) + return true; + } + + if (_recognizedCommandsDelegate != null && result == RecognizedResult.Success) + { + VoiceCommandsGroup cmdList = new VoiceCommandsGroup(new SafeCommandListHandle(vcCmdList)); + IEnumerable selectedList = _recognizedCommandsDelegate.Invoke(cmdList.Commands, recognizedString, msgString); + if (selectedList == null) + return true; + + VoiceCommandsGroup resultList = new VoiceCommandsGroup(); + foreach (VoiceCommand command in selectedList) + { + resultList.Commands.Add(command); + } + ErrorCode error = VcMgrSetSelectedResults(resultList._handle); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "SetSelectedResults Failed with error " + error); + } + return false; + } + return true; + }; + + /// + /// The delegate is invoked when engine requests private data is needed. + /// + /// Private key + /// Private data + /// 6 + public delegate string PrivateDataProvider(string key); + + /// + /// The delegate is invoked when the sentence match, client selects valid commands from all commands. + /// + /// Command list + /// The Recognized text + /// Engine message + /// + public delegate IEnumerable SelectRecognizedCommandsDelegate(IEnumerable commands, string recognizedText, string message); + + /// + /// Initialize voice control manager. + /// + /// 6 + /// http://tizen.org/privilege/voicecontrol.manager + /// http://tizen.org/privilege/recorder + /// public + /// http://tizen.org/feature/speech.control + /// http://tizen.org/feature/microphone + /// This exception can be due to operation failed. + /// The required feature is not supported. + /// + /// The State will be Initialized. + /// + public static void Initialize() + { + ErrorCode error = VcMgrInitialize(); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "Initialize Failed with error " + error); + throw ExceptionFactory.CreateException(error); + } + } + + /// + /// Deinitialize the voice control manager. + /// + /// 6 + /// http://tizen.org/privilege/voicecontrol.manager + /// public + /// http://tizen.org/feature/speech.control + /// http://tizen.org/feature/microphone + /// This exception can be due to an invalid state. + /// The required feature is not supported. + /// + /// The State will be None. + /// + public static void Deinitialize() + { + ErrorCode error = VcMgrDeinitialize(); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "Deinitialize Failed with error " + error); + throw ExceptionFactory.CreateException(error); + } + } + + /// + /// Connects the voice control service. + /// + /// 6 + /// http://tizen.org/privilege/voicecontrol.manager + /// public + /// http://tizen.org/feature/speech.control + /// http://tizen.org/feature/microphone + /// + /// This can occur due to the following reasons: + /// 1) This exception can be due to an invalid state. + /// 2) This exception can be due to operation failed. + /// + /// This exception can be due to permission denied. + /// The required feature is not supported. + ///
+        /// The state must be initialized.
+        /// 
+ /// + /// The state must be ready. + /// + public static void Prepare() + { + ErrorCode error = VcMgrPrepare(); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "Prepare Failed with error " + error); + throw ExceptionFactory.CreateException(error); + } + } + + /// + /// Disconnects the voice control service. + /// + /// 6 + /// http://tizen.org/privilege/voicecontrol.manager + /// public + /// http://tizen.org/feature/speech.control + /// http://tizen.org/feature/microphone + /// This exception can be due to an invalid state. + /// This exception can be due to permission denied. + /// The required feature is not supported. + ///
+        /// The state must be ready.
+        /// 
+ /// + /// The state must be initialized. + /// + public static void Unprepare() + { + ErrorCode error = VcMgrUnprepare(); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "Unprepare Failed with error " + error); + throw ExceptionFactory.CreateException(error); + } + } + + /// + /// Retrieves all the 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. + /// + /// 6 + /// http://tizen.org/privilege/voicecontrol.manager + /// public + /// + /// List of strings for supported languages. + /// + /// http://tizen.org/feature/speech.control + /// http://tizen.org/feature/microphone + /// + /// This can occur due to the following reasons: + /// 1) This exception can be due to an invalid state. + /// 2) This exception can be due to operation failed. + /// + /// This exception can be due to permission denied. + /// The required feature is not supported. + ///
+        /// The state must be ready or initialized.
+        /// 
+ public static IEnumerable GetSupportedLanguages() + { + List supportedLanguages = new List(); + VcMgrSupportedLanguageCallback supportedLanguagesDelegate = (IntPtr language, IntPtr userData) => + { + string languageStr = Marshal.PtrToStringAnsi(language); + supportedLanguages.Add(languageStr); + return true; + }; + ErrorCode error = VcMgrForeachSupportedLanguages(supportedLanguagesDelegate, IntPtr.Zero); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "GetSupportedLanguages Failed with error " + error); + throw ExceptionFactory.CreateException(error); + } + + return supportedLanguages; + } + + /// + /// Gets the 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. + /// An empty string is returned in case of some internal error. + /// + /// 6 + /// http://tizen.org/privilege/voicecontrol.manager + /// public + /// http://tizen.org/feature/speech.control + /// http://tizen.org/feature/microphone + /// The current language in voice control. + /// The required feature is not supported. + ///
+        /// The state must be initialized or ready.
+        /// 
+ public static string CurrentLanguage + { + get + { + string currentLanguage; + + ErrorCode error = VcMgrGetCurrentLanguage(out currentLanguage); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "CurrentLanaguge Failed with error " + error); + return string.Empty; + } + + return currentLanguage; + } + } + + /// + /// Gets the current state of the voice control client. + /// + /// 6 + /// http://tizen.org/privilege/voicecontrol.manager + /// public + /// http://tizen.org/feature/speech.control + /// http://tizen.org/feature/microphone + /// The current state of the voice control client. + /// The required feature is not supported. + ///
+        /// The state must be initialized or ready.
+        /// 
+ public static State State + { + get + { + State state; + + ErrorCode error = VcMgrGetState(out state); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "State Failed with error " + error); + return State.Unavailable; + } + + return state; + } + } + + /// + /// Gets the current state of the voice control service. + /// + /// 6 + /// http://tizen.org/privilege/voicecontrol.manager + /// public + /// http://tizen.org/feature/speech.control + /// http://tizen.org/feature/microphone + /// The current state of the voice control service. + /// The required feature is not supported. + ///
+        /// The state must be ready.
+        /// 
+ public static ServiceState ServiceState + { + get + { + ServiceState state; + + ErrorCode error = VcMgrGetServiceState(out state); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "ServiceState Failed with error " + error); + return ServiceState.Unavailable; + } + + return state; + } + } + + /// + /// Checks whether the command format is supported. + /// + /// 6 + /// http://tizen.org/privilege/voicecontrol.manager + /// public + /// http://tizen.org/feature/speech.control + /// http://tizen.org/feature/microphone + /// The command format + /// The result status, true if supported + /// This exception can be due to an invalid state. + /// This exception can be due to an invalid parameter. + /// The required feature is not supported. + ///
+        /// The State must be Ready.
+        /// 
+ public static bool IsSupportedCommandFormat(CommandFormat format) + { + bool supported = false; + ErrorCode error = VcMgrIsCommandFormatSupported(format, out supported); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "IsSupportedCommandFormat Failed with error " + error); + throw ExceptionFactory.CreateException(error); + } + return supported; + } + + /// + /// Sets system or exclusive commands. + /// + /// 6 + /// http://tizen.org/privilege/voicecontrol.manager + /// public + /// http://tizen.org/feature/speech.control + /// http://tizen.org/feature/microphone + /// Command list + /// This exception can be due to invalid state. + /// This exception can be due to an invalid parameter. + /// The required feature is not supported. + ///
+        /// The State should be Ready
+        /// 
+ public static void SetCommands(VoiceCommandsGroup commands) + { + if (commands == null) + throw new ArgumentException("Parameter is null"); + + ErrorCode error = VcMgrSetCommandList(commands._handle); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "SetCommands Failed with error " + error); + throw ExceptionFactory.CreateException(error); + } + } + + /// + /// Clears commands. + /// + /// 6 + /// http://tizen.org/privilege/voicecontrol.manager + /// public + /// http://tizen.org/feature/speech.control + /// http://tizen.org/feature/microphone + /// This exception can be due to invalid state. + /// The required feature is not supported. + ///
+        /// The State should be Ready
+        /// 
+ public static void ClearCommands() + { + ErrorCode error = VcMgrUnsetCommandList(); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "ClearCommands Failed with error " + error); + throw ExceptionFactory.CreateException(error); + } + } + + /// + /// Sets commands from file. + /// + /// 6 + /// http://tizen.org/privilege/voicecontrol.manager + /// public + /// http://tizen.org/feature/speech.control + /// http://tizen.org/feature/microphone + /// File Path + /// Command type + /// + /// This can occur due to the following reasons: + /// 1) This exception can be due to an invalid state. + /// 2) This exception can be due to operation failed. + /// + /// This exception can be due to an invalid parameter. + /// The required feature is not supported. + ///
+        /// The State should be Ready
+        /// 
+ public static void SetCommandsFromFile(string path, CommandType type) + { + ErrorCode error = VcMgrSetCommandListFromFile(path, type); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "SetCommandsFromFile Failed with error " + error); + throw ExceptionFactory.CreateException(error); + } + } + + /// + /// Retrieves all available commands. + /// + /// 6 + /// http://tizen.org/privilege/voicecontrol.manager + /// public + /// http://tizen.org/feature/speech.control + /// http://tizen.org/feature/microphone> + /// + /// The Command List else null in case of no System Commands + /// + /// + /// This can occur due to the following reasons: + /// 1) This exception can be due to an invalid state. + /// 2) This exception can be due to operation failed. + /// + /// This exception can be due to an invalid parameter. + /// The required feature is not supported. + ///
+        /// The State should be Ready
+        /// 
+ public static IEnumerable GetCurrentCommands() + { + IntPtr handle = IntPtr.Zero; + ErrorCode error = VcMgrGetCurrentCommands(out handle); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "GetCurrentCommands Failed with error " + error); + throw ExceptionFactory.CreateException(error); + } + + if (handle == IntPtr.Zero) + { + Log.Error(LogTag, "GetCurrentCommands handle is null"); + return null; + } + + SafeCommandListHandle list = new SafeCommandListHandle(handle); + VoiceCommandsGroup cmdList = new VoiceCommandsGroup(list); + return cmdList.Commands; + } + + /// + /// Sets or Gets the Audio In Type + /// the Values of the strings can be "VC_AUDIO_ID_BLUETOOTH" or "VC_AUDIO_ID_MSF" + /// + /// 6 + /// http://tizen.org/privilege/voicecontrol.manager + /// public + /// http://tizen.org/feature/speech.control + /// http://tizen.org/feature/microphone + /// + /// This can occur due to the following reasons: + /// 1) This exception can be due to an invalid state. + /// 2) This exception can be due to operation failed. + /// + /// This exception can be due to an invalid parameter. + /// The required feature is not supported. + ///
+        /// The State must be Ready.
+        /// 
+ public static string AudioType + { + get + { + string type; + + ErrorCode error = VcMgrGetAudioType(out type); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "GetAudioType Failed with error " + error); + return string.Empty; + } + + return type; + } + set + { + ErrorCode error = VcMgrSetAudioType(value); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "SetAudioType Failed with error " + error); + throw ExceptionFactory.CreateException(error); + } + } + } + + /// + /// Sets or Gets the recognition mode. + /// + /// 6 + /// http://tizen.org/privilege/voicecontrol.manager + /// public + /// http://tizen.org/feature/speech.control + /// http://tizen.org/feature/microphone + /// This exception can be due to an invalid state. + /// This exception can be due to an invalid parameter. + /// The required feature is not supported. + ///
+        /// The State must be Ready.
+        /// 
+ public static RecognitionModeType RecognitionMode + { + get + { + RecognitionModeType mode; + + ErrorCode error = VcMgrGetRecognitionMode(out mode); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "GetRecognitionMode Failed with error " + error); + return RecognitionModeType.Undefined; + } + + return mode; + } + set + { + ErrorCode error = VcMgrSetRecognitionMode(value); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "SetRecognitionMode Failed with error " + error); + throw ExceptionFactory.CreateException(error); + } + } + } + + /// + /// Sets private data between app and engine. + /// + /// 6 + /// http://tizen.org/privilege/voicecontrol.manager + /// public + /// http://tizen.org/feature/speech.control + /// http://tizen.org/feature/microphone + /// Private key + /// Private data + /// + /// This can occur due to the following reasons: + /// 1) This exception can be due to an invalid state. + /// 2) This exception can be due to operation failed. + /// 3) This exception can be due to out of memory. + /// + /// The required feature is not supported. + ///
+        /// The State must be Ready.
+        /// 
+ public static void SetPrivateData(string key, string data) + { + ErrorCode error = VcMgrSetPrivateData(key, data); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "SetPrivateData Failed with error " + error); + throw ExceptionFactory.CreateException(error); + } + } + + /// + /// Gets private data between app and engine. + /// + /// 6 + /// http://tizen.org/privilege/voicecontrol.manager + /// public + /// http://tizen.org/feature/speech.control + /// http://tizen.org/feature/microphone + /// Private key + /// Private data + /// + /// This can occur due to the following reasons: + /// 1) This exception can be due to an invalid state. + /// 2) This exception can be due to operation failed. + /// 3) This exception can be due to out of memory. + /// + /// The required feature is not supported. + ///
+        /// The State must be Ready.
+        /// 
+ public static string GetPrivateData(string key) + { + string data; + ErrorCode error = VcMgrGetPrivateData(key, out data); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "GetPrivateData Failed with error " + error); + throw ExceptionFactory.CreateException(error); + } + return data; + } + + /// + /// Request to do action as if utterence is spoken. + /// + /// 6 + /// http://tizen.org/privilege/voicecontrol.manager + /// public + /// http://tizen.org/feature/speech.control + /// http://tizen.org/feature/microphone + /// Event type + /// The string for send event + /// + /// This can occur due to the following reasons: + /// 1) This exception can be due to an invalid state. + /// 2) This exception can be due to operation failed. + /// 3) This exception can be due to out of memory. + /// + /// The required feature is not supported. + ///
+        /// The State must be Ready.
+        /// 
+ public static void DoAction(SendEventType type, string sendEvent) + { + ErrorCode error = VcMgrDoAction(type, sendEvent); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "DoAction Failed with error " + error); + throw ExceptionFactory.CreateException(error); + } + } + + /// + /// Sends the specific engine request to the vc-service. + /// + /// 6 + /// http://tizen.org/privilege/voicecontrol.manager + /// public + /// http://tizen.org/feature/speech.control + /// http://tizen.org/feature/microphone + /// A specific engine's app id + /// A engine service user request event + /// A engine service user request text + /// + /// This can occur due to the following reasons: + /// 1) This exception can be due to an invalid state. + /// 2) This exception can be due to operation failed. + /// + /// This exception can be due to permission denied. + /// The required feature is not supported. + public static void SendSpecificEngineRequest(string engineAppId, string evt, string request) + { + ErrorCode error = VcMgrSendSpecificEngineRequest(engineAppId, evt, request); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "SendSpecificEngineRequest Failed with error " + error); + throw ExceptionFactory.CreateException(error); + } + } + + /// + /// Starts recognition. + /// + /// 6 + /// http://tizen.org/privilege/voicecontrol.manager + /// public + /// http://tizen.org/feature/speech.control + /// http://tizen.org/feature/microphone + /// Exclusive command option + /// + /// This can occur due to the following reasons: + /// 1) This exception can be due to an invalid state. + /// 2) This exception can be due to operation failed. + /// 3) This exception can be due to out of memory. + /// + /// The required feature is not supported. + ///
+        /// The State must be Ready.
+        /// 
+ /// + /// The Service State will become Recording. + /// + public static void Start(bool exclusiveCommandOption) + { + ErrorCode error = VcMgrStart(exclusiveCommandOption); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "Start Failed with error " + error); + throw ExceptionFactory.CreateException(error); + } + } + + /// + /// Stop recognition. + /// + /// 6 + /// http://tizen.org/privilege/voicecontrol.manager + /// public + /// http://tizen.org/feature/speech.control + /// http://tizen.org/feature/microphone + /// + /// This can occur due to the following reasons: + /// 1) This exception can be due to an invalid state. + /// 2) This exception can be due to operation failed. + /// + /// The required feature is not supported. + ///
+        /// The State must be Recording.
+        /// 
+ /// + /// The Service State will become Processing. + /// + public static void Stop() + { + ErrorCode error = VcMgrStop(); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "Stop Failed with error " + error); + throw ExceptionFactory.CreateException(error); + } + } + + /// + /// Cancels recognition. + /// + /// 6 + /// http://tizen.org/privilege/voicecontrol.manager + /// public + /// http://tizen.org/feature/speech.control + /// http://tizen.org/feature/microphone + /// + /// This can occur due to the following reasons: + /// 1) This exception can be due to an invalid state. + /// 2) This exception can be due to operation failed. + /// 3) This exception can be due to out of memory. + /// + /// The required feature is not supported. + ///
+        /// The State must be Recording or Processing.
+        /// 
+ /// + /// The Service State will become Ready. + /// + public static void Cancel() + { + ErrorCode error = VcMgrCancel(); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "Cancel Failed with error " + error); + throw ExceptionFactory.CreateException(error); + } + } + + /// + /// Gets the microphone volume during recording. + /// + /// 6 + /// http://tizen.org/privilege/voicecontrol.manager + /// public + /// http://tizen.org/feature/speech.control + /// http://tizen.org/feature/microphone + /// The required feature is not supported. + ///
+        /// The Service State must be Recording.
+        /// 
+ public static float RecordingVolume + { + get + { + float volume; + + ErrorCode error = VcMgrGetRecordingVolume(out volume); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "RecordingVolume Failed with error " + error); + return 0; + } + + return volume; + } + } + + /// + /// Sets the delegate for setting valid commands. + /// + /// 6 + /// http://tizen.org/privilege/voicecontrol.manager + /// public + /// http://tizen.org/feature/speech.control + /// http://tizen.org/feature/microphone + /// The delegate for setting valid commands. + /// This exception can be due to an invalid parameter. + /// This exception can be due to an invalid state. + /// This exception can be due to permission denied. + /// The required feature is not supported. + public static void SetRecognizedCommandsSelectionDelegate(SelectRecognizedCommandsDelegate recognizedCommandsDelegate) + { + ErrorCode error = ErrorCode.None; + if (recognizedCommandsDelegate == null && _allRecognitionResult == null) + { + _recognizedCommandsDelegate = null; + error = VcMgrUnsetAllResultCb(); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "Remove SetAllResult Failed with error " + error); + } + return; + } + + if (_allRecognitionResult == null && _recognizedCommandsDelegate == null) + { + error = VcMgrSetAllResultCb(_recognizedCommandsSelectionCallback, IntPtr.Zero); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "Add SetRecognizedCommandsSelectionDelegate Failed with error " + error); + throw ExceptionFactory.CreateException(error); + } + } + _recognizedCommandsDelegate = recognizedCommandsDelegate; + } + + /// + /// Called when client gets the all recognition results from vc-daemon. + /// + /// 6 + /// http://tizen.org/privilege/voicecontrol.manager + /// public + /// http://tizen.org/feature/speech.control + /// http://tizen.org/feature/microphone + /// The required feature is not supported. + ///
+        /// The State should be Initialized
+        /// 
+ public static event EventHandler AllRecognitionResultReceived + { + add + { + if (_allRecognitionResult == null && _recognizedCommandsDelegate == null) + { + ErrorCode error = VcMgrSetAllResultCb(_recognizedCommandsSelectionCallback, IntPtr.Zero); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "Add AllRecognitionResult Failed with error " + error); + } + } + _allRecognitionResult += value; + } + + remove + { + _allRecognitionResult -= value; + if (_allRecognitionResult == null && _recognizedCommandsDelegate == null) + { + ErrorCode error = VcMgrUnsetAllResultCb(); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "Remove SetAllResult Failed with error " + error); + } + } + } + } + + /// + /// Called when client gets the pre recognition results(partial ASR) from vc-daemon. + /// + /// 6 + /// http://tizen.org/privilege/voicecontrol.manager + /// public + /// http://tizen.org/feature/speech.control + /// http://tizen.org/feature/microphone + /// The required feature is not supported. + ///
+        /// The State should be Initialized
+        /// 
+ public static event EventHandler PreRecognitionResultUpdated + { + add + { + if (_preResult == null) + { + _preResultDelegate = (PreResultEventType result, IntPtr recognizedText, IntPtr userData) => + { + string recognizedString = Marshal.PtrToStringAnsi(recognizedText); + PreRecognitionResultUpdatedEventArgs args = new PreRecognitionResultUpdatedEventArgs(result, recognizedString); + _preResult?.Invoke(null, args); + }; + ErrorCode error = VcMgrSetPreResultCb(_preResultDelegate, IntPtr.Zero); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "Add PreRecognitionResultUpdated Failed with error " + error); + } + } + _preResult += value; + } + + remove + { + _preResult -= value; + if (_preResult == null) + { + ErrorCode error = VcMgrUnsetPreResultCb(); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "Remove PreRecognitionResultUpdated Failed with error " + error); + } + } + } + } + + /// + /// Called when client gets the specific engine's result from vc-service. + /// + /// 6 + /// http://tizen.org/privilege/voicecontrol.manager + /// public + /// http://tizen.org/feature/speech.control + /// http://tizen.org/feature/microphone + /// The required feature is not supported. + ///
+        /// The State should be Initialized
+        /// 
+ public static event EventHandler SpecificEngineResult + { + add + { + if (_specificEngineResult == null) + { + _specificEngineResultDelegate = (IntPtr engineAppId, IntPtr evt, IntPtr result, IntPtr userData) => + { + string engineAppIdString = Marshal.PtrToStringAnsi(engineAppId); + string eventString = Marshal.PtrToStringAnsi(evt); + string resultString = Marshal.PtrToStringAnsi(result); + SpecificEngineResultEventArgs args = new SpecificEngineResultEventArgs(engineAppIdString, eventString, resultString); + _specificEngineResult?.Invoke(null, args); + }; + ErrorCode error = VcMgrSetSpecificEngineResultCb(_specificEngineResultDelegate, IntPtr.Zero); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "Add SpecificEngineResult Failed with error " + error); + } + } + _specificEngineResult += value; + } + + remove + { + _specificEngineResult -= value; + if (_specificEngineResult == null) + { + ErrorCode error = VcMgrUnsetSpecificEngineResultCb(); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "Remove SpecificEngineResult Failed with error " + error); + } + } + } + } + + /// + /// Event to be invoked when the recognition is done. + /// + /// 6 + /// http://tizen.org/privilege/voicecontrol.manager + /// public + /// http://tizen.org/feature/speech.control + /// http://tizen.org/feature/microphone + /// The required feature is not supported. + ///
+        /// The State should be Initialized
+        /// 
+ public static event EventHandler RecognitionResultUpdated + { + add + { + if (_recognitionResult == null) + { + s_resultDelegate = (RecognizedResult result, IntPtr cmdList, IntPtr recognizedText, IntPtr userData) => + { + Log.Info(LogTag, "Recognition Result Updated Event Triggered"); + if ((cmdList != null) && (recognizedText != null)) + { + RecognitionResultUpdatedEventArgs args = new RecognitionResultUpdatedEventArgs(result, cmdList, recognizedText); + _recognitionResult?.Invoke(null, args); + } + else + { + Log.Info(LogTag, "Recognition Result Updated Event null received"); + } + }; + ErrorCode error = VcMgrSetResultCb(s_resultDelegate, IntPtr.Zero); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "Add RecognitionResultUpdated Failed with error " + error); + } + } + _recognitionResult += value; + } + + remove + { + _recognitionResult -= value; + if (_recognitionResult == null) + { + ErrorCode error = VcMgrUnsetResultCb(); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "Remove RecognitionResultUpdated Failed with error " + error); + } + } + } + } + + /// + /// Event to be invoked when the VoiceControl client state changes. + /// + /// 6 + /// http://tizen.org/privilege/voicecontrol.manager + /// public + /// http://tizen.org/feature/speech.control + /// http://tizen.org/feature/microphone + /// The required feature is not supported. + ///
+        /// The state must be initialized.
+        /// 
+ public static event EventHandler StateChanged + { + add + { + if (_stateChanged == null) + { + _stateDelegate = (State previous, State current, IntPtr userData) => + { + StateChangedEventArgs args = new StateChangedEventArgs(previous, current); + _stateChanged?.Invoke(null, args); + }; + ErrorCode error = VcMgrSetStateChangedCb(_stateDelegate, IntPtr.Zero); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "Add StateChanged Failed with error " + error); + } + } + _stateChanged += value; + } + + remove + { + _stateChanged -= value; + if (_stateChanged == null) + { + ErrorCode error = VcMgrUnsetStateChangedCb(); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "Remove StateChanged Failed with error " + error); + } + } + } + } + + /// + /// Event to be invoked when the VoiceControl service state changes. + /// + /// 6 + /// http://tizen.org/privilege/voicecontrol.manager + /// public + /// http://tizen.org/feature/speech.control + /// http://tizen.org/feature/microphone + /// The required feature is not supported. + ///
+        /// The state must be initialized.
+        /// 
+ public static event EventHandler ServiceStateChanged + { + add + { + if (_serviceStateChanged == null) + { + _serviceStateDelegate = (ServiceState previous, ServiceState current, IntPtr userData) => + { + ServiceStateChangedEventArgs args = new ServiceStateChangedEventArgs(previous, current); + _serviceStateChanged?.Invoke(null, args); + }; + ErrorCode error = VcMgrSetServiceStateChangedCb(_serviceStateDelegate, IntPtr.Zero); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "Add ServiceStateChanged Failed with error " + error); + } + } + _serviceStateChanged += value; + } + + remove + { + _serviceStateChanged -= value; + if (_serviceStateChanged == null) + { + ErrorCode error = VcMgrUnsetServiceStateChangedCb(); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "Remove ServiceStateChanged Failed with error " + error); + } + } + } + } + + /// + /// Called when user speaking is detected. + /// + /// 6 + /// http://tizen.org/privilege/voicecontrol.manager + /// public + /// http://tizen.org/feature/speech.control + /// http://tizen.org/feature/microphone + /// The required feature is not supported. + ///
+        /// The State should be Initialized
+        /// 
+ public static event EventHandler SpeechDetected + { + add + { + if (_speechDetected == null) + { + _beginSpeechDetectedDelegate = (IntPtr userData) => + { + _speechDetected?.Invoke(null, EventArgs.Empty); + }; + ErrorCode error = VcMgrSetSpeechDetectedCb(_beginSpeechDetectedDelegate, IntPtr.Zero); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "Add SpeechDetected Failed with error " + error); + } + } + _speechDetected += value; + } + + remove + { + _speechDetected -= value; + if (_speechDetected == null) + { + ErrorCode error = VcMgrUnsetSpeechDetectedCb(); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "Remove SpeechDetected Failed with error " + error); + } + } + } + } + + /// + /// Event to be invoked when the default language changes. + /// + /// 6 + /// http://tizen.org/privilege/voicecontrol.manager + /// public + /// http://tizen.org/feature/speech.control + /// http://tizen.org/feature/microphone + /// The required feature is not supported. + ///
+        /// The state must be initialized.
+        /// 
+ public static event EventHandler CurrentLanguageChanged + { + add + { + if (_currentLanguageChanged == null) + { + _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 = VcMgrSetCurrentLanguageChangedCb(_languageDelegate, IntPtr.Zero); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "Add CurrentLanguageChanged Failed with error " + error); + } + } + _currentLanguageChanged += value; + } + + remove + { + _currentLanguageChanged -= value; + if (_currentLanguageChanged == null) + { + ErrorCode error = VcMgrUnsetCurrentLanguageChangedCb(); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "Remove CurrentLanguageChanged Failed with error " + error); + } + } + } + } + + /// + /// Event to be invoked when an error occurs. + /// + /// 6 + /// http://tizen.org/privilege/voicecontrol.manager + /// public + /// http://tizen.org/feature/speech.control + /// http://tizen.org/feature/microphone + /// The required feature is not supported. + ///
+        /// The state must be initialized.
+        /// 
+ public static event EventHandler ErrorOccurred + { + add + { + if (_errorOccurred == null) + { + _errorDelegate = (ErrorCode reason, IntPtr userData) => + { + ErrorOccurredEventArgs args = new ErrorOccurredEventArgs(ExceptionFactory.CreateException(reason)); + _errorOccurred?.Invoke(null, args); + }; + ErrorCode error = VcMgrSetErrorCb(_errorDelegate, IntPtr.Zero); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "Add ErrorOccurred Failed with error " + error); + } + } + _errorOccurred += value; + } + + remove + { + _errorOccurred -= value; + if (_errorOccurred == null) + { + ErrorCode error = VcMgrUnsetErrorCb(); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "Remove ErrorOccurred Failed with error " + error); + } + } + } + } + + /// + /// Event to be called when conversation requests. + /// + /// 6 + /// http://tizen.org/privilege/voicecontrol.manager + /// public + /// http://tizen.org/feature/speech.control + /// http://tizen.org/feature/microphone + /// The required feature is not supported. + ///
+        /// The State should be Initialized
+        /// 
+ public static event EventHandler ConversationRequested + { + add + { + if (_conversationRequested == null) + { + _conversationRequestDelegate = (int pid, IntPtr dispText, IntPtr uttText, bool continuous, IntPtr userData) => + { + string dispTextString = Marshal.PtrToStringAnsi(dispText); + string uttTextString = Marshal.PtrToStringAnsi(uttText); + ConversationRequestedEventArgs args = new ConversationRequestedEventArgs(ApplicationManager.GetAppId(pid), dispTextString, uttTextString, continuous); + _conversationRequested?.Invoke(null, args); + }; + ErrorCode error = VcMgrSetDialogRequestCb(_conversationRequestDelegate, IntPtr.Zero); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "Add ConversationRequested Failed with error " + error); + } + } + _conversationRequested += value; + } + + remove + { + _conversationRequested -= value; + if (_conversationRequested == null) + { + ErrorCode error = VcMgrUnsetDialogRequestCb(); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "Remove ConversationRequested Failed with error " + error); + } + } + } + } + + /// + /// Enable command type as candidate command. + /// + /// 6 + /// http://tizen.org/privilege/voicecontrol.manager + /// public + /// http://tizen.org/feature/speech.control + /// http://tizen.org/feature/microphone + /// Command Type + /// This exception can be due to invalid state. + /// The required feature is not supported. + ///
+        /// The State should be Ready
+        /// 
+ public static void EnableCommandType(CommandType cmdType) + { + ErrorCode error = VcMgrEnableCommandType(cmdType); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "EnableCommandType Failed with error " + error); + throw ExceptionFactory.CreateException(error); + } + } + + /// + /// Disable command type as candidate command. + /// + /// 6 + /// http://tizen.org/privilege/voicecontrol.manager + /// public + /// http://tizen.org/feature/speech.control + /// http://tizen.org/feature/microphone + /// Command Type + /// This exception can be due to invalid state. + /// The required feature is not supported. + ///
+        /// The State should be Ready
+        /// 
+ public static void DisableCommandType(CommandType cmdType) + { + ErrorCode error = VcMgrDisableCommandType(cmdType); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "DisableCommandType Failed with error " + error); + throw ExceptionFactory.CreateException(error); + } + } + + /// + /// Called when engine sets private data to manager client. + /// + /// 6 + /// http://tizen.org/privilege/voicecontrol.manager + /// public + /// http://tizen.org/feature/speech.control + /// http://tizen.org/feature/microphone + /// The required feature is not supported. + ///
+        /// The State should be Initialized
+        /// 
+ public static event EventHandler PrivateDataUpdated + { + add + { + if (_privateDataSet == null) + { + _privateDataSetDelegate = (IntPtr key, IntPtr data, IntPtr userData) => + { + string keyString = Marshal.PtrToStringAnsi(key); + string dataString = Marshal.PtrToStringAnsi(data); + PrivateDataUpdatedEventArgs args = new PrivateDataUpdatedEventArgs(keyString, dataString); + _privateDataSet?.Invoke(null, args); + return 0; + }; + ErrorCode error = VcMgrSetPrivateDataSetCb(_privateDataSetDelegate, IntPtr.Zero); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "Add PrivateDataUpdated Failed with error " + error); + } + } + _privateDataSet += value; + } + + remove + { + _privateDataSet -= value; + if (_privateDataSet == null) + { + ErrorCode error = VcMgrUnsetPrivateDataSetCb(); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "Remove PrivateDataUpdated Failed with error " + error); + } + } + } + } + + /// + /// Sets the delegate for setting private data. + /// + /// 6 + /// http://tizen.org/privilege/voicecontrol.manager + /// public + /// http://tizen.org/feature/speech.control + /// http://tizen.org/feature/microphone + /// The delegate for setting private data + /// This exception can be due to an invalid parameter. + /// This exception can be due to an invalid state. + /// This exception can be due to permission denied. + /// The required feature is not supported. + public static void SetPrivateDataProviderDelegate(PrivateDataProvider privateDataDelegate) + { + if (privateDataDelegate == null) + { + Log.Error(LogTag, "callback is null"); + throw ExceptionFactory.CreateException(ErrorCode.InvalidParameter); + } + _privateDataRequestedDelegate = (string key, out string data, IntPtr userData) => + { + data = privateDataDelegate.Invoke(key); + if (data == null) + return VoiceError.InvalidParameter; + return VoiceError.None; + }; + ErrorCode error = VcMgrSetPrivateDataRequestedCb(_privateDataRequestedDelegate); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "Add SetPrivateDataProviderDelegate Failed with error " + error); + throw ExceptionFactory.CreateException(error); + } + } + + /// + /// Called when engine sends audio formats necessary for playing TTS feedback. + /// + /// 6 + /// http://tizen.org/privilege/voicecontrol.manager + /// public + /// http://tizen.org/feature/speech.control + /// http://tizen.org/feature/microphone + /// The required feature is not supported. + ///
+        /// The State should be Initialized
+        /// 
+ public static event EventHandler FeedbackAudioFormatChanged + { + add + { + if (_feedbackAudioFormat == null) + { + _feedbackAudioFormatDelegate = (int rate, AudioChanelType channel, AudioType audiotype, IntPtr userData) => + { + FeedbackAudioFormatEventArgs args = new FeedbackAudioFormatEventArgs(rate, channel, audiotype); + _feedbackAudioFormat?.Invoke(null, args); + }; + ErrorCode error = VcMgrSetFeedbackAudioFormatCb(_feedbackAudioFormatDelegate, IntPtr.Zero); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "Add FeedbackStreaming Failed with error " + error); + } + } + _feedbackAudioFormat += value; + } + + remove + { + _feedbackAudioFormat -= value; + if (_feedbackAudioFormat == null) + { + ErrorCode error = VcMgrUnsetFeedbackAudioFormatCb(); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "Remove FeedbackAudioFormat Failed with error " + error); + } + } + } + } + + /// + /// Called when engine sends audio streaming for TTS feedback. + /// + /// 6 + /// http://tizen.org/privilege/voicecontrol.manager + /// public + /// http://tizen.org/feature/speech.control + /// http://tizen.org/feature/microphone + /// The required feature is not supported. + ///
+        /// The State should be Initialized
+        /// 
+ public static event EventHandler FeedbackStreaming + { + add + { + if (_feedbackStreaming == null) + { + _feedbackStreamingDelegate = (FeedbackType type, IntPtr buffer, int len, IntPtr userData) => + { + byte[] byteBuffer = new byte[len]; + Marshal.Copy(buffer, byteBuffer, 0, len); + FeedbackStreamingEventArgs args = new FeedbackStreamingEventArgs(type, byteBuffer); + _feedbackStreaming?.Invoke(null, args); + }; + ErrorCode error = VcMgrSetFeedbackStreamingCb(_feedbackStreamingDelegate, IntPtr.Zero); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "Add FeedbackStreaming Failed with error " + error); + } + } + _feedbackStreaming += value; + } + + remove + { + _feedbackStreaming -= value; + if (_feedbackStreaming == null) + { + ErrorCode error = VcMgrUnsetFeedbackStreamingCb(); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "Remove FeedbackStreaming Failed with error " + error); + } + } + } + } + + /// + /// Starts getting TTS feedback streaming data from the buffer. + /// + /// 6 + /// http://tizen.org/privilege/voicecontrol.manager + /// public + /// http://tizen.org/feature/speech.control + /// http://tizen.org/feature/microphone + /// + /// This can occur due to the following reasons: + /// 1) This exception can be due to an invalid state. + /// 2) This exception can be due to operation failed. + /// + /// This exception can be due to permission denied. + /// The required feature is not supported. + ///
+        /// The State should be Ready
+        /// 
+ public static void StartFeedback() + { + ErrorCode error = VcMgrStartFeedback(); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "StartFeedback Failed with error " + error); + throw ExceptionFactory.CreateException(error); + } + } + + /// + /// Stops getting and removes TTS feedback streaming data from the buffer. + /// + /// 6 + /// http://tizen.org/privilege/voicecontrol.manager + /// public + /// http://tizen.org/feature/speech.control + /// http://tizen.org/feature/microphone + /// + /// This can occur due to the following reasons: + /// 1) This exception can be due to an invalid state. + /// 2) This exception can be due to operation failed. + /// + /// This exception can be due to permission denied. + /// The required feature is not supported. + ///
+        /// The State should be Ready
+        /// 
+ public static void StopFeedback() + { + ErrorCode error = VcMgrStopFeedback(); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "StopFeedback Failed with error " + error); + throw ExceptionFactory.CreateException(error); + } + } + + /// + /// Called when the vc client sends audio streaming for TTS feedback. + /// + /// 6 + /// http://tizen.org/privilege/voicecontrol.manager + /// public + /// http://tizen.org/feature/speech.control + /// http://tizen.org/feature/microphone + /// The required feature is not supported. + ///
+        /// The State should be Initialized
+        /// 
+ public static event EventHandler VcTtsStreaming + { + add + { + if (_vcTtsStreaming == null) + { + _vcTtsStreamingDelegate = (int pid, int uttId, FeedbackType type, IntPtr buffer, int len, IntPtr userData) => + { + byte[] byteBuffer = new byte[len]; + Marshal.Copy(buffer, byteBuffer, 0, len); + VcTtsStreamingEventArgs args = new VcTtsStreamingEventArgs(ApplicationManager.GetAppId(pid), uttId, type, byteBuffer); + _vcTtsStreaming?.Invoke(null, args); + }; + ErrorCode error = VcMgrSetVcTtsStreamingCb(_vcTtsStreamingDelegate, IntPtr.Zero); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "Add VcTtsStreaming Failed with error " + error); + } + } + _vcTtsStreaming += value; + } + + remove + { + _vcTtsStreaming -= value; + if (_vcTtsStreaming == null) + { + ErrorCode error = VcMgrUnsetVcTtsStreamingCb(); + if (error != ErrorCode.None) + { + Log.Error(LogTag, "Remove VcTtsStreaming Failed with error " + error); + } + } + } + } + } +} -- 2.7.4