From aa78a8955a4d49cf1dab3d9897ce2e1151995738 Mon Sep 17 00:00:00 2001 From: "xb.teng" Date: Thu, 25 May 2017 22:55:18 +0800 Subject: [PATCH] manual bind tts player for nui Change-Id: Ie98e3833967adfdf98067ffc5e36634283fdc89a --- .../NUISamples.TizenTV/NUISamples.TizenTV.csproj | 1 + .../NUISamples.TizenTV/examples/ttsplayer-test.cs | 68 +++++ Tizen.NUI/Tizen.NUI.csproj | 4 +- Tizen.NUI/src/internal/ManualPINVOKE.cs | 60 +++++ Tizen.NUI/src/internal/StateChangedSignalType.cs | 138 +++++++++++ Tizen.NUI/src/public/TTSPlayer.cs | 276 +++++++++++++++++++++ 6 files changed, 546 insertions(+), 1 deletion(-) create mode 100755 NUISamples/NUISamples/NUISamples.TizenTV/examples/ttsplayer-test.cs create mode 100755 Tizen.NUI/src/internal/StateChangedSignalType.cs create mode 100755 Tizen.NUI/src/public/TTSPlayer.cs diff --git a/NUISamples/NUISamples/NUISamples.TizenTV/NUISamples.TizenTV.csproj b/NUISamples/NUISamples/NUISamples.TizenTV/NUISamples.TizenTV.csproj index d389ee3..e0ac162 100755 --- a/NUISamples/NUISamples/NUISamples.TizenTV/NUISamples.TizenTV.csproj +++ b/NUISamples/NUISamples/NUISamples.TizenTV/NUISamples.TizenTV.csproj @@ -72,6 +72,7 @@ + diff --git a/NUISamples/NUISamples/NUISamples.TizenTV/examples/ttsplayer-test.cs b/NUISamples/NUISamples/NUISamples.TizenTV/examples/ttsplayer-test.cs new file mode 100755 index 0000000..dfdb90d --- /dev/null +++ b/NUISamples/NUISamples/NUISamples.TizenTV/examples/ttsplayer-test.cs @@ -0,0 +1,68 @@ +/* +* Copyright (c) 2016 Samsung Electronics Co., Ltd. +* +* 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 Tizen.NUI; + +namespace TTSPlayerTest +{ + class Example : NUIApplication + { + public Example() : base() + { + } + + public Example(string stylesheet) : base(stylesheet) + { + } + + public Example(string stylesheet, WindowMode windowMode) : base(stylesheet, windowMode) + { + } + + protected override void OnCreate() + { + base.OnCreate(); + Initialize(); + } + + public void Initialize() + { + Window window = Window.Instance; + window.BackgroundColor = Color.White; + + TTSPlayer ttsPlayer = TTSPlayer.Get(TTSPlayer.TTSMode.Default); + ttsPlayer.Play("tts player test"); + + ttsPlayer.StateChanged += (s, e) => + { + Tizen.Log.Debug("TTS state changed!!!"); + }; + ttsPlayer.Pause(); + ttsPlayer.Resume(); + ttsPlayer.Stop(); + Tizen.Log.Debug("TTS state: " + ttsPlayer.GetState()); + } + + [STAThread] + static void _Main(string[] args) + { + Example example = new Example(); + example.Run(args); + } + } +} diff --git a/Tizen.NUI/Tizen.NUI.csproj b/Tizen.NUI/Tizen.NUI.csproj index 9680f03..7f90f6a 100755 --- a/Tizen.NUI/Tizen.NUI.csproj +++ b/Tizen.NUI/Tizen.NUI.csproj @@ -203,6 +203,7 @@ + @@ -332,6 +333,7 @@ + @@ -385,4 +387,4 @@ - \ No newline at end of file + diff --git a/Tizen.NUI/src/internal/ManualPINVOKE.cs b/Tizen.NUI/src/internal/ManualPINVOKE.cs index 6cbe612..86da201 100755 --- a/Tizen.NUI/src/internal/ManualPINVOKE.cs +++ b/Tizen.NUI/src/internal/ManualPINVOKE.cs @@ -595,5 +595,65 @@ namespace Tizen.NUI [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint = "CSharp_HIDDENINPUT_PROPERTY_SHOW_DURATION_get")] public static extern int HIDDENINPUT_PROPERTY_SHOW_DURATION_get(); + [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint="CSharp_Dali_TtsPlayer_SWIGUpcast")] + public static extern global::System.IntPtr TtsPlayer_SWIGUpcast(global::System.IntPtr jarg1); + + [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint="CSharp_Dali_new_TtsPlayer__SWIG_0")] + public static extern global::System.IntPtr new_TtsPlayer__SWIG_0(); + + [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint="CSharp_Dali_TtsPlayer_Get__SWIG_0")] + public static extern global::System.IntPtr TtsPlayer_Get__SWIG_0(int jarg1); + + [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint="CSharp_Dali_TtsPlayer_Get__SWIG_1")] + public static extern global::System.IntPtr TtsPlayer_Get__SWIG_1(); + + [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint="CSharp_Dali_delete_TtsPlayer")] + public static extern void delete_TtsPlayer(global::System.Runtime.InteropServices.HandleRef jarg1); + + [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint="CSharp_Dali_new_TtsPlayer__SWIG_1")] + public static extern global::System.IntPtr new_TtsPlayer__SWIG_1(global::System.Runtime.InteropServices.HandleRef jarg1); + + [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint="CSharp_Dali_TtsPlayer_Assign")] + public static extern global::System.IntPtr TtsPlayer_Assign(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2); + + [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint="CSharp_Dali_TtsPlayer_Play")] + public static extern void TtsPlayer_Play(global::System.Runtime.InteropServices.HandleRef jarg1, string jarg2); + + [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint="CSharp_Dali_TtsPlayer_Stop")] + public static extern void TtsPlayer_Stop(global::System.Runtime.InteropServices.HandleRef jarg1); + + [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint="CSharp_Dali_TtsPlayer_Pause")] + public static extern void TtsPlayer_Pause(global::System.Runtime.InteropServices.HandleRef jarg1); + + [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint="CSharp_Dali_TtsPlayer_Resume")] + public static extern void TtsPlayer_Resume(global::System.Runtime.InteropServices.HandleRef jarg1); + + [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint="CSharp_Dali_TtsPlayer_GetState")] + public static extern int TtsPlayer_GetState(global::System.Runtime.InteropServices.HandleRef jarg1); + + [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint="CSharp_Dali_TtsPlayer_StateChangedSignal")] + public static extern global::System.IntPtr TtsPlayer_StateChangedSignal(global::System.Runtime.InteropServices.HandleRef jarg1); + + [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint="CSharp_Dali_StateChangedSignalType_Empty")] + public static extern bool StateChangedSignalType_Empty(global::System.Runtime.InteropServices.HandleRef jarg1); + + [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint="CSharp_Dali_StateChangedSignalType_GetConnectionCount")] + public static extern uint StateChangedSignalType_GetConnectionCount(global::System.Runtime.InteropServices.HandleRef jarg1); + + [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint="CSharp_Dali_StateChangedSignalType_Connect")] + public static extern void StateChangedSignalType_Connect(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2); + + [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint="CSharp_Dali_StateChangedSignalType_Disconnect")] + public static extern void StateChangedSignalType_Disconnect(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2); + + [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint="CSharp_Dali_StateChangedSignalType_Emit")] + public static extern void StateChangedSignalType_Emit(global::System.Runtime.InteropServices.HandleRef jarg1, int jarg2, int jarg3); + + [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint="CSharp_Dali_new_StateChangedSignalType")] + public static extern global::System.IntPtr new_StateChangedSignalType(); + + [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint="CSharp_Dali_delete_StateChangedSignalType")] + public static extern void delete_StateChangedSignalType(global::System.Runtime.InteropServices.HandleRef jarg1); + } } diff --git a/Tizen.NUI/src/internal/StateChangedSignalType.cs b/Tizen.NUI/src/internal/StateChangedSignalType.cs new file mode 100755 index 0000000..eb2ff13 --- /dev/null +++ b/Tizen.NUI/src/internal/StateChangedSignalType.cs @@ -0,0 +1,138 @@ +//------------------------------------------------------------------------------ +// +// +// This file was automatically generated by SWIG (http://www.swig.org). +// Version 3.0.12 +// +// Do not make changes to this file unless you know what you are doing--modify +// the SWIG interface file instead. +//------------------------------------------------------------------------------ + +namespace Tizen.NUI +{ + internal class StateChangedSignalType : global::System.IDisposable + { + private global::System.Runtime.InteropServices.HandleRef swigCPtr; + protected bool swigCMemOwn; + + internal StateChangedSignalType(global::System.IntPtr cPtr, bool cMemoryOwn) + { + swigCMemOwn = cMemoryOwn; + swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); + } + + internal static global::System.Runtime.InteropServices.HandleRef getCPtr(StateChangedSignalType obj) + { + return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr; + } + + //A Flag to check who called Dispose(). (By User or DisposeQueue) + private bool isDisposeQueued = false; + //A Flat to check if it is already disposed. + protected bool disposed = false; + + ~StateChangedSignalType() + { + if (!isDisposeQueued) + { + isDisposeQueued = true; + DisposeQueue.Instance.Add(this); + } + } + + public void Dispose() + { + //Throw excpetion if Dispose() is called in separate thread. + if (!Window.IsInstalled()) + { + throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread."); + } + + if (isDisposeQueued) + { + Dispose(DisposeTypes.Implicit); + } + else + { + Dispose(DisposeTypes.Explicit); + System.GC.SuppressFinalize(this); + } + } + + protected virtual void Dispose(DisposeTypes type) + { + if (disposed) + { + return; + } + + if (type == DisposeTypes.Explicit) + { + //Called by User + //Release your own managed resources here. + //You should release all of your own disposable objects here. + } + + //Release your own unmanaged resources here. + //You should not access any managed member here except static instance. + //because the execution order of Finalizes is non-deterministic. + + if (swigCPtr.Handle != global::System.IntPtr.Zero) + { + if (swigCMemOwn) + { + swigCMemOwn = false; + NDalicManualPINVOKE.delete_StateChangedSignalType(swigCPtr); + } + swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); + } + + disposed = true; + } + + public bool Empty() + { + bool ret = NDalicManualPINVOKE.StateChangedSignalType_Empty(swigCPtr); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + + public uint GetConnectionCount() + { + uint ret = NDalicManualPINVOKE.StateChangedSignalType_GetConnectionCount(swigCPtr); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + + public void Connect(System.Delegate func) + { + System.IntPtr ip = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(func); + { + NDalicManualPINVOKE.StateChangedSignalType_Connect(swigCPtr, new System.Runtime.InteropServices.HandleRef(this, ip)); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + } + + public void Disconnect(System.Delegate func) + { + System.IntPtr ip = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(func); + { + NDalicManualPINVOKE.StateChangedSignalType_Disconnect(swigCPtr, new System.Runtime.InteropServices.HandleRef(this, ip)); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + } + + public void Emit(TTSPlayer.TTSState arg1, TTSPlayer.TTSState arg2) + { + NDalicManualPINVOKE.StateChangedSignalType_Emit(swigCPtr, (int)arg1, (int)arg2); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + + public StateChangedSignalType() : this(NDalicManualPINVOKE.new_StateChangedSignalType(), true) + { + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + + } + +} diff --git a/Tizen.NUI/src/public/TTSPlayer.cs b/Tizen.NUI/src/public/TTSPlayer.cs new file mode 100755 index 0000000..12b1567 --- /dev/null +++ b/Tizen.NUI/src/public/TTSPlayer.cs @@ -0,0 +1,276 @@ +//------------------------------------------------------------------------------ +// +// +// This file was automatically generated by SWIG (http://www.swig.org). +// Version 3.0.12 +// +// Do not make changes to this file unless you know what you are doing--modify +// the SWIG interface file instead. +//------------------------------------------------------------------------------ + +namespace Tizen.NUI +{ + using System; + using System.Runtime.InteropServices; + + /// + /// The Text-to-speech (TTS) Player. + /// + public class TTSPlayer : BaseHandle + { + private global::System.Runtime.InteropServices.HandleRef swigCPtr; + + internal TTSPlayer(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicManualPINVOKE.TtsPlayer_SWIGUpcast(cPtr), cMemoryOwn) + { + swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); + } + + internal static global::System.Runtime.InteropServices.HandleRef getCPtr(TTSPlayer obj) + { + return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr; + } + + protected override void Dispose(DisposeTypes type) + { + if (disposed) + { + return; + } + + if (type == DisposeTypes.Explicit) + { + //Called by User + //Release your own managed resources here. + //You should release all of your own disposable objects here. + } + + //Release your own unmanaged resources here. + //You should not access any managed member here except static instance. + //because the execution order of Finalizes is non-deterministic. + + if (swigCPtr.Handle != global::System.IntPtr.Zero) + { + if (swigCMemOwn) + { + swigCMemOwn = false; + NDalicManualPINVOKE.delete_TtsPlayer(swigCPtr); + } + swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); + } + + base.Dispose(type); + } + + internal TTSPlayer() : this(NDalicManualPINVOKE.new_TtsPlayer__SWIG_0(), true) + { + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + + /// + /// Gets the singleton of the TtsPlayer for the given mode. + /// + /// The mode of tts-player. + /// A handle of the Ttsplayer for the given mode. + public static TTSPlayer Get(TTSMode mode) + { + TTSPlayer ret = new TTSPlayer(NDalicManualPINVOKE.TtsPlayer_Get__SWIG_0((int)mode), true); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + + /// + /// Gets the singleton of the TtsPlayer for the default mode.. + /// + /// A handle of the Ttsplayer for the default mode. + public static TTSPlayer Get() + { + TTSPlayer ret = new TTSPlayer(NDalicManualPINVOKE.TtsPlayer_Get__SWIG_1(), true); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + + internal TTSPlayer(TTSPlayer handle) : this(NDalicManualPINVOKE.new_TtsPlayer__SWIG_1(TTSPlayer.getCPtr(handle)), true) + { + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + + internal TTSPlayer Assign(TTSPlayer rhs) + { + TTSPlayer ret = new TTSPlayer(NDalicManualPINVOKE.TtsPlayer_Assign(swigCPtr, TTSPlayer.getCPtr(rhs)), false); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + + /// + /// Starts playing the audio data synthesized from the specified text. + /// + /// The text to play. + /// The TtsPlayer needs to be initialized. + public void Play(string text) + { + NDalicManualPINVOKE.TtsPlayer_Play(swigCPtr, text); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + + /// + /// Stops playing the utterance. + /// + /// The TtsPlayer needs to be initialized. + public void Stop() + { + NDalicManualPINVOKE.TtsPlayer_Stop(swigCPtr); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + + /// + /// Pauses the currently playing utterance. + /// + /// The TtsPlayer needs to be initialized. + public void Pause() + { + NDalicManualPINVOKE.TtsPlayer_Pause(swigCPtr); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + + /// + /// Resumes the previously paused utterance. + /// + /// The TtsPlayer needs to be initialized. + public void Resume() + { + NDalicManualPINVOKE.TtsPlayer_Resume(swigCPtr); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + + /// + /// Gets the current state of the player. + /// + /// The current TTS state. + /// The TtsPlayer needs to be initialized. + public TTSState GetState() + { + TTSState ret = (TTSState)NDalicManualPINVOKE.TtsPlayer_GetState(swigCPtr); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + + /// + /// State changed argument. + /// + public class StateChangedEventArgs : EventArgs + { + public TTSState PrevState + { + get; + set; + } + + public TTSState NextState + { + get; + set; + } + } + + private StateChangedEventCallbackType _stateChangedEventCallback; + [UnmanagedFunctionPointer(CallingConvention.StdCall)] + private delegate void StateChangedEventCallbackType(TTSState prevState, TTSState nextState); + private event EventHandler _stateChangedEventHandler; + + /// + /// State changed event. + /// + public event EventHandler StateChanged + { + add + { + if (_stateChangedEventHandler == null) + { + _stateChangedEventCallback = OnStateChanged; + StateChangedSignal().Connect(_stateChangedEventCallback); + } + + _stateChangedEventHandler += value; + } + remove + { + _stateChangedEventHandler -= value; + + if (_stateChangedEventHandler == null && StateChangedSignal().Empty() == false && _stateChangedEventCallback != null) + { + StateChangedSignal().Disconnect(_stateChangedEventCallback); + } + } + } + + private void OnStateChanged(TTSState prevState, TTSState nextState) + { + StateChangedEventArgs e = new StateChangedEventArgs(); + + e.PrevState = prevState; + e.NextState = nextState; + + if (_stateChangedEventHandler != null) + { + _stateChangedEventHandler(this, e); + } + } + + internal StateChangedSignalType StateChangedSignal() + { + StateChangedSignalType ret = new StateChangedSignalType(NDalicManualPINVOKE.TtsPlayer_StateChangedSignal(swigCPtr), false); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + return ret; + } + + /// + /// Enumeration for the instance of TTS mode. + /// + public enum TTSMode + { + /// + /// Default mode for normal application. + /// + Default = 0, + /// + /// Notification mode, such as playing utterance is started or completed. + /// + Notification, + /// + /// Screen reader mode.
+ /// To help visually impaired users interact with their devices,
+ /// screen reader reads text or graphic elements on the screen using the TTS engine. + ///
+ ScreenReader, + /// + /// Number of Mode. + /// + ModeNum + } + + /// + /// Enumeration for the instance of TTS state. + /// + public enum TTSState + { + /// + /// Player is not available. + /// + Unavailable = 0, + /// + /// Player is ready to play. + /// + Ready, + /// + /// Player is playing. + /// + Playing, + /// + /// Player is paused. + /// + Paused + } + + } + +} -- 2.7.4