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 [Obsolete("Please do not use! This will be deprecated!")]
65 [EditorBrowsable(EditorBrowsableState.Never)]
66 protected override void Dispose(DisposeTypes type)
73 if (type == DisposeTypes.Explicit)
76 //Release your own managed resources here.
77 //You should release all of your own disposable objects here.
80 //Release your own unmanaged resources here.
81 //You should not access any managed member here except static instance.
82 //because the execution order of Finalizes is non-deterministic.
84 if (_stateChangedEventCallback != null)
86 StateChangedSignal().Disconnect(_stateChangedEventCallback);
89 if (swigCPtr.Handle != global::System.IntPtr.Zero)
94 NDalicManualPINVOKE.delete_TtsPlayer(swigCPtr);
96 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
102 internal TTSPlayer() : this(NDalicManualPINVOKE.new_TtsPlayer__SWIG_0(), true)
104 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
108 /// Gets the singleton of the TTS player for the given mode.
110 /// <param name="mode"> The mode of TTS player.</param>
111 /// <returns> A handle of the TTS player for the given mode.</returns>
112 /// <since_tizen> 3 </since_tizen>
113 public static TTSPlayer Get(TTSMode mode)
115 TTSPlayer ret = new TTSPlayer(NDalicManualPINVOKE.TtsPlayer_Get__SWIG_0((int)mode), true);
116 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
121 /// Gets the singleton of the TTS player for the default mode.
123 /// <returns> A handle of the TTS player for the default mode.</returns>
124 /// <since_tizen> 3 </since_tizen>
125 public static TTSPlayer Get()
127 TTSPlayer ret = new TTSPlayer(NDalicManualPINVOKE.TtsPlayer_Get__SWIG_1(), true);
128 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
132 internal TTSPlayer(TTSPlayer handle) : this(NDalicManualPINVOKE.new_TtsPlayer__SWIG_1(TTSPlayer.getCPtr(handle)), true)
134 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
137 internal TTSPlayer Assign(TTSPlayer rhs)
139 TTSPlayer ret = new TTSPlayer(NDalicManualPINVOKE.TtsPlayer_Assign(swigCPtr, TTSPlayer.getCPtr(rhs)), false);
140 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
145 /// Starts playing the audio data synthesized from the specified text.
147 /// <param name="text"> The text to play.</param>
148 /// <remarks>The TTS player needs to be initialized.</remarks>
149 /// <since_tizen> 3 </since_tizen>
150 public void Play(string text)
152 NDalicManualPINVOKE.TtsPlayer_Play(swigCPtr, text);
153 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
157 /// Stops playing the utterance.
159 /// <remarks>The TTS player needs to be initialized.</remarks>
160 /// <since_tizen> 3 </since_tizen>
163 NDalicManualPINVOKE.TtsPlayer_Stop(swigCPtr);
164 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
168 /// Pauses the currently playing utterance.
170 /// <remarks>The TTS player needs to be initialized.</remarks>
171 /// <since_tizen> 3 </since_tizen>
174 NDalicManualPINVOKE.TtsPlayer_Pause(swigCPtr);
175 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
179 /// Resumes the previously paused utterance.
181 /// <remarks>The TTS player needs to be initialized.</remarks>
182 /// <since_tizen> 3 </since_tizen>
185 NDalicManualPINVOKE.TtsPlayer_Resume(swigCPtr);
186 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
190 /// Gets the current state of the player.
192 /// <returns> The current TTS state. </returns>
193 /// <remarks>The TTS player needs to be initialized.</remarks>
194 /// <since_tizen> 3 </since_tizen>
195 public TTSState GetState()
197 TTSState ret = (TTSState)NDalicManualPINVOKE.TtsPlayer_GetState(swigCPtr);
198 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
203 /// State changed argument.
205 /// <since_tizen> 3 </since_tizen>
206 public class StateChangedEventArgs : EventArgs
211 /// <since_tizen> 3 </since_tizen>
212 public TTSState PrevState
221 /// <since_tizen> 3 </since_tizen>
222 public TTSState NextState
229 private StateChangedEventCallbackType _stateChangedEventCallback;
230 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
231 private delegate void StateChangedEventCallbackType(TTSState prevState, TTSState nextState);
232 private event EventHandler<StateChangedEventArgs> _stateChangedEventHandler;
235 /// State changed event.
237 /// <since_tizen> 3 </since_tizen>
238 public event EventHandler<StateChangedEventArgs> StateChanged
242 if (_stateChangedEventHandler == null)
244 _stateChangedEventCallback = OnStateChanged;
245 StateChangedSignal().Connect(_stateChangedEventCallback);
248 _stateChangedEventHandler += value;
252 _stateChangedEventHandler -= value;
254 if (_stateChangedEventHandler == null && StateChangedSignal().Empty() == false && _stateChangedEventCallback != null)
256 StateChangedSignal().Disconnect(_stateChangedEventCallback);
261 private void OnStateChanged(TTSState prevState, TTSState nextState)
263 StateChangedEventArgs e = new StateChangedEventArgs();
265 e.PrevState = prevState;
266 e.NextState = nextState;
268 if (_stateChangedEventHandler != null)
270 _stateChangedEventHandler(this, e);
274 internal StateChangedSignalType StateChangedSignal()
276 StateChangedSignalType ret = new StateChangedSignalType(NDalicManualPINVOKE.TtsPlayer_StateChangedSignal(swigCPtr), false);
277 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
282 /// Enumeration for the instance of TTS mode.
284 /// <since_tizen> 3 </since_tizen>
288 /// Default mode for normal application.
292 /// Notification mode, such as playing utterance is started or completed.
296 /// Screen reader mode. <br />
297 /// To help visually impaired users interact with their devices,<br />
298 /// screen reader reads text or graphic elements on the screen using the TTS engine.
308 /// Enumeration for the instance of TTS state.
310 /// <since_tizen> 3 </since_tizen>
314 /// Player is not available.
318 /// Player is ready to play.
322 /// Player is playing.
326 /// Player is paused.