/* * Copyright(c) 2017 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 System.Runtime.InteropServices; using System.ComponentModel; namespace Tizen.NUI { /// /// The Text-to-speech (TTS) player. /// /// 3 public class TTSPlayer : BaseHandle { private static readonly TTSPlayer instance = TTSPlayer.Get(); private StateChangedEventCallbackType _stateChangedEventCallback; internal TTSPlayer(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.TtsPlayer.Upcast(cPtr), cMemoryOwn) { } internal TTSPlayer() : this(Interop.TtsPlayer.NewTtsPlayer(), true) { if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } internal TTSPlayer(TTSPlayer handle) : this(Interop.TtsPlayer.NewTtsPlayer(TTSPlayer.getCPtr(handle)), true) { if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } [UnmanagedFunctionPointer(CallingConvention.StdCall)] private delegate void StateChangedEventCallbackType(TTSState prevState, TTSState nextState); private event EventHandler _stateChangedEventHandler; /// /// State changed event. /// /// 3 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); } } } /// /// Enumeration for the instance of TTS mode. /// /// 3 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. /// /// 3 public enum TTSState { /// /// Player is not available. /// Unavailable = 0, /// /// Player is ready to play. /// Ready, /// /// Player is playing. /// Playing, /// /// Player is paused. /// Paused } /// /// Gets the singleton of the TTSPlayer object. /// /// 5 public static TTSPlayer Instance { get { return instance; } } /// /// Gets the singleton of the TTS player for the given mode. /// /// The mode of TTS player. /// A handle of the TTS player for the given mode. /// 3 public static TTSPlayer Get(TTSMode mode) { TTSPlayer ret = new TTSPlayer(Interop.TtsPlayer.Get((int)mode), true); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// Gets the singleton of the TTS player for the default mode. /// /// A handle of the TTS player for the default mode. /// 3 public static TTSPlayer Get() { TTSPlayer ret = new TTSPlayer(Interop.TtsPlayer.Get(), true); 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 TTS player needs to be initialized. /// 3 public void Play(string text) { Interop.TtsPlayer.Play(swigCPtr, text); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } /// /// Stops playing the utterance. /// /// The TTS player needs to be initialized. /// 3 public void Stop() { Interop.TtsPlayer.Stop(swigCPtr); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } /// /// Pauses the currently playing utterance. /// /// The TTS player needs to be initialized. /// 3 public void Pause() { Interop.TtsPlayer.Pause(swigCPtr); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } /// /// Resumes the previously paused utterance. /// /// The TTS player needs to be initialized. /// 3 public void Resume() { Interop.TtsPlayer.Resume(swigCPtr); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } /// /// Gets the current state of the player. /// /// The current TTS state. /// The TTS player needs to be initialized. /// 3 public TTSState GetState() { TTSState ret = (TTSState)Interop.TtsPlayer.GetState(swigCPtr); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } 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; } internal StateChangedSignalType StateChangedSignal() { StateChangedSignalType ret = new StateChangedSignalType(Interop.TtsPlayer.StateChangedSignal(swigCPtr), false); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } internal TTSPlayer Assign(TTSPlayer rhs) { TTSPlayer ret = new TTSPlayer(Interop.TtsPlayer.Assign(swigCPtr, TTSPlayer.getCPtr(rhs)), false); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } private void OnStateChanged(TTSState prevState, TTSState nextState) { StateChangedEventArgs e = new StateChangedEventArgs(); e.PrevState = prevState; e.NextState = nextState; if (_stateChangedEventHandler != null) { _stateChangedEventHandler(this, e); } } /// /// State changed argument. /// /// 3 public class StateChangedEventArgs : EventArgs { /// /// PrevState. /// /// 3 public TTSState PrevState { get; set; } /// /// NextState. /// /// 3 public TTSState NextState { get; set; } } } }