/** 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.
*
*/
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
}
}
}