1 /** Copyright (c) 2017 Samsung Electronics Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
20 using System.Runtime.InteropServices;
23 /// The Text-to-speech (TTS) Player.
25 public class TTSPlayer : BaseHandle
27 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
29 internal TTSPlayer(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicManualPINVOKE.TtsPlayer_SWIGUpcast(cPtr), cMemoryOwn)
31 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
34 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(TTSPlayer obj)
36 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
39 protected override void Dispose(DisposeTypes type)
46 if (type == DisposeTypes.Explicit)
49 //Release your own managed resources here.
50 //You should release all of your own disposable objects here.
53 //Release your own unmanaged resources here.
54 //You should not access any managed member here except static instance.
55 //because the execution order of Finalizes is non-deterministic.
57 if (swigCPtr.Handle != global::System.IntPtr.Zero)
63 //Unreference this instance from Registry.
64 Registry.Unregister(this);
66 NDalicManualPINVOKE.delete_TtsPlayer(swigCPtr);
68 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
74 internal TTSPlayer() : this(NDalicManualPINVOKE.new_TtsPlayer__SWIG_0(), true)
76 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
80 /// Gets the singleton of the TtsPlayer for the given mode.
82 /// <param name="mode"> The mode of tts-player. </param>
83 /// <returns> A handle of the Ttsplayer for the given mode. </returns>
84 public static TTSPlayer Get(TTSMode mode)
86 TTSPlayer ret = new TTSPlayer(NDalicManualPINVOKE.TtsPlayer_Get__SWIG_0((int)mode), true);
87 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
92 /// Gets the singleton of the TtsPlayer for the default mode..
94 /// <returns> A handle of the Ttsplayer for the default mode. </returns>
95 public static TTSPlayer Get()
97 TTSPlayer ret = new TTSPlayer(NDalicManualPINVOKE.TtsPlayer_Get__SWIG_1(), true);
98 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
102 internal TTSPlayer(TTSPlayer handle) : this(NDalicManualPINVOKE.new_TtsPlayer__SWIG_1(TTSPlayer.getCPtr(handle)), true)
104 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
107 internal TTSPlayer Assign(TTSPlayer rhs)
109 TTSPlayer ret = new TTSPlayer(NDalicManualPINVOKE.TtsPlayer_Assign(swigCPtr, TTSPlayer.getCPtr(rhs)), false);
110 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
115 /// Starts playing the audio data synthesized from the specified text.
117 /// <param name="text"> The text to play. </param>
118 /// <remarks>The TtsPlayer needs to be initialized.</remarks>
119 public void Play(string text)
121 NDalicManualPINVOKE.TtsPlayer_Play(swigCPtr, text);
122 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
126 /// Stops playing the utterance.
128 /// <remarks>The TtsPlayer needs to be initialized.</remarks>
131 NDalicManualPINVOKE.TtsPlayer_Stop(swigCPtr);
132 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
136 /// Pauses the currently playing utterance.
138 /// <remarks>The TtsPlayer needs to be initialized.</remarks>
141 NDalicManualPINVOKE.TtsPlayer_Pause(swigCPtr);
142 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
146 /// Resumes the previously paused utterance.
148 /// <remarks>The TtsPlayer needs to be initialized.</remarks>
151 NDalicManualPINVOKE.TtsPlayer_Resume(swigCPtr);
152 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
156 /// Gets the current state of the player.
158 /// <returns> The current TTS state. </returns>
159 /// <remarks>The TtsPlayer needs to be initialized.</remarks>
160 public TTSState GetState()
162 TTSState ret = (TTSState)NDalicManualPINVOKE.TtsPlayer_GetState(swigCPtr);
163 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
168 /// State changed argument.
170 public class StateChangedEventArgs : EventArgs
172 public TTSState PrevState
178 public TTSState NextState
185 private StateChangedEventCallbackType _stateChangedEventCallback;
186 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
187 private delegate void StateChangedEventCallbackType(TTSState prevState, TTSState nextState);
188 private event EventHandler<StateChangedEventArgs> _stateChangedEventHandler;
191 /// State changed event.
193 public event EventHandler<StateChangedEventArgs> StateChanged
197 if (_stateChangedEventHandler == null)
199 _stateChangedEventCallback = OnStateChanged;
200 StateChangedSignal().Connect(_stateChangedEventCallback);
203 _stateChangedEventHandler += value;
207 _stateChangedEventHandler -= value;
209 if (_stateChangedEventHandler == null && StateChangedSignal().Empty() == false && _stateChangedEventCallback != null)
211 StateChangedSignal().Disconnect(_stateChangedEventCallback);
216 private void OnStateChanged(TTSState prevState, TTSState nextState)
218 StateChangedEventArgs e = new StateChangedEventArgs();
220 e.PrevState = prevState;
221 e.NextState = nextState;
223 if (_stateChangedEventHandler != null)
225 _stateChangedEventHandler(this, e);
229 internal StateChangedSignalType StateChangedSignal()
231 StateChangedSignalType ret = new StateChangedSignalType(NDalicManualPINVOKE.TtsPlayer_StateChangedSignal(swigCPtr), false);
232 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
237 /// Enumeration for the instance of TTS mode.
242 /// Default mode for normal application.
246 /// Notification mode, such as playing utterance is started or completed.
250 /// Screen reader mode. <br>
251 /// To help visually impaired users interact with their devices, <br>
252 /// screen reader reads text or graphic elements on the screen using the TTS engine.
262 /// Enumeration for the instance of TTS state.
267 /// Player is not available.
271 /// Player is ready to play.
275 /// Player is playing.
279 /// Player is paused.