2 * Copyright(c) 2017 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 using System.Runtime.InteropServices;
20 using System.ComponentModel;
25 /// The Text-to-speech (TTS) player.
27 /// <since_tizen> 3 </since_tizen>
28 public class TTSPlayer : BaseHandle
30 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
32 internal TTSPlayer(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicManualPINVOKE.TtsPlayer_SWIGUpcast(cPtr), cMemoryOwn)
34 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
37 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(TTSPlayer obj)
39 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
42 private static readonly TTSPlayer instance = TTSPlayer.Get();
45 /// Gets the singleton of the TTSPlayer object.
47 /// <since_tizen> 5 </since_tizen>
48 public static TTSPlayer Instance
59 /// <param name="type">The dispose type</param>
60 /// <since_tizen> 3 </since_tizen>
61 /// Please DO NOT use! This will be deprecated!
62 /// Dispose() method in Singletone classes (ex: FocusManager, StyleManager, VisualFactory, IMFManager, TtsPlayer, Window) is not required.
63 /// Because it is Sigletone, so it is alive for one thread until the NUI is terminated, so it never be disposed.
64 [EditorBrowsable(EditorBrowsableState.Never)]
65 protected override void Dispose(DisposeTypes type)
72 if (type == DisposeTypes.Explicit)
75 //Release your own managed resources here.
76 //You should release all of your own disposable objects here.
79 //Release your own unmanaged resources here.
80 //You should not access any managed member here except static instance.
81 //because the execution order of Finalizes is non-deterministic.
83 if (_stateChangedEventCallback != null)
85 StateChangedSignal().Disconnect(_stateChangedEventCallback);
88 if (swigCPtr.Handle != global::System.IntPtr.Zero)
93 NDalicManualPINVOKE.delete_TtsPlayer(swigCPtr);
95 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
101 internal TTSPlayer() : this(NDalicManualPINVOKE.new_TtsPlayer__SWIG_0(), true)
103 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
107 /// Gets the singleton of the TTS player for the given mode.
109 /// <param name="mode"> The mode of TTS player.</param>
110 /// <returns> A handle of the TTS player for the given mode.</returns>
111 /// <since_tizen> 3 </since_tizen>
112 public static TTSPlayer Get(TTSMode mode)
114 TTSPlayer ret = new TTSPlayer(NDalicManualPINVOKE.TtsPlayer_Get__SWIG_0((int)mode), true);
115 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
120 /// Gets the singleton of the TTS player for the default mode.
122 /// <returns> A handle of the TTS player for the default mode.</returns>
123 /// <since_tizen> 3 </since_tizen>
124 public static TTSPlayer Get()
126 TTSPlayer ret = new TTSPlayer(NDalicManualPINVOKE.TtsPlayer_Get__SWIG_1(), true);
127 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
131 internal TTSPlayer(TTSPlayer handle) : this(NDalicManualPINVOKE.new_TtsPlayer__SWIG_1(TTSPlayer.getCPtr(handle)), true)
133 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
136 internal TTSPlayer Assign(TTSPlayer rhs)
138 TTSPlayer ret = new TTSPlayer(NDalicManualPINVOKE.TtsPlayer_Assign(swigCPtr, TTSPlayer.getCPtr(rhs)), false);
139 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
144 /// Starts playing the audio data synthesized from the specified text.
146 /// <param name="text"> The text to play.</param>
147 /// <remarks>The TTS player needs to be initialized.</remarks>
148 /// <since_tizen> 3 </since_tizen>
149 public void Play(string text)
151 NDalicManualPINVOKE.TtsPlayer_Play(swigCPtr, text);
152 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
156 /// Stops playing the utterance.
158 /// <remarks>The TTS player needs to be initialized.</remarks>
159 /// <since_tizen> 3 </since_tizen>
162 NDalicManualPINVOKE.TtsPlayer_Stop(swigCPtr);
163 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
167 /// Pauses the currently playing utterance.
169 /// <remarks>The TTS player needs to be initialized.</remarks>
170 /// <since_tizen> 3 </since_tizen>
173 NDalicManualPINVOKE.TtsPlayer_Pause(swigCPtr);
174 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
178 /// Resumes the previously paused utterance.
180 /// <remarks>The TTS player needs to be initialized.</remarks>
181 /// <since_tizen> 3 </since_tizen>
184 NDalicManualPINVOKE.TtsPlayer_Resume(swigCPtr);
185 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
189 /// Gets the current state of the player.
191 /// <returns> The current TTS state. </returns>
192 /// <remarks>The TTS player needs to be initialized.</remarks>
193 /// <since_tizen> 3 </since_tizen>
194 public TTSState GetState()
196 TTSState ret = (TTSState)NDalicManualPINVOKE.TtsPlayer_GetState(swigCPtr);
197 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
202 /// State changed argument.
204 /// <since_tizen> 3 </since_tizen>
205 public class StateChangedEventArgs : EventArgs
210 /// <since_tizen> 3 </since_tizen>
211 public TTSState PrevState
220 /// <since_tizen> 3 </since_tizen>
221 public TTSState NextState
228 private StateChangedEventCallbackType _stateChangedEventCallback;
229 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
230 private delegate void StateChangedEventCallbackType(TTSState prevState, TTSState nextState);
231 private event EventHandler<StateChangedEventArgs> _stateChangedEventHandler;
234 /// State changed event.
236 /// <since_tizen> 3 </since_tizen>
237 public event EventHandler<StateChangedEventArgs> StateChanged
241 if (_stateChangedEventHandler == null)
243 _stateChangedEventCallback = OnStateChanged;
244 StateChangedSignal().Connect(_stateChangedEventCallback);
247 _stateChangedEventHandler += value;
251 _stateChangedEventHandler -= value;
253 if (_stateChangedEventHandler == null && StateChangedSignal().Empty() == false && _stateChangedEventCallback != null)
255 StateChangedSignal().Disconnect(_stateChangedEventCallback);
260 private void OnStateChanged(TTSState prevState, TTSState nextState)
262 StateChangedEventArgs e = new StateChangedEventArgs();
264 e.PrevState = prevState;
265 e.NextState = nextState;
267 if (_stateChangedEventHandler != null)
269 _stateChangedEventHandler(this, e);
273 internal StateChangedSignalType StateChangedSignal()
275 StateChangedSignalType ret = new StateChangedSignalType(NDalicManualPINVOKE.TtsPlayer_StateChangedSignal(swigCPtr), false);
276 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
281 /// Enumeration for the instance of TTS mode.
283 /// <since_tizen> 3 </since_tizen>
287 /// Default mode for normal application.
291 /// Notification mode, such as playing utterance is started or completed.
295 /// Screen reader mode. <br />
296 /// To help visually impaired users interact with their devices,<br />
297 /// screen reader reads text or graphic elements on the screen using the TTS engine.
307 /// Enumeration for the instance of TTS state.
309 /// <since_tizen> 3 </since_tizen>
313 /// Player is not available.
317 /// Player is ready to play.
321 /// Player is playing.
325 /// Player is paused.