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 public class TTSPlayer : BaseHandle
29 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
31 internal TTSPlayer(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicManualPINVOKE.TtsPlayer_SWIGUpcast(cPtr), cMemoryOwn)
33 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
36 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(TTSPlayer obj)
38 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
44 /// <param name="type">The dispose type</param>
45 /// <since_tizen> 3 </since_tizen>
46 /// Please DO NOT use! This will be deprecated!
47 /// Dispose() method in Singletone classes (ex: FocusManager, StyleManager, VisualFactory, IMFManager, TtsPlayer, Window) is not required.
48 /// Because it is Sigletone, so it is alive for one thread until the NUI is terminated, so it never be disposed.
49 [EditorBrowsable(EditorBrowsableState.Never)]
50 protected override void Dispose(DisposeTypes type)
57 if (type == DisposeTypes.Explicit)
60 //Release your own managed resources here.
61 //You should release all of your own disposable objects here.
64 //Release your own unmanaged resources here.
65 //You should not access any managed member here except static instance.
66 //because the execution order of Finalizes is non-deterministic.
68 if (_stateChangedEventCallback != null)
70 StateChangedSignal().Disconnect(_stateChangedEventCallback);
73 if (swigCPtr.Handle != global::System.IntPtr.Zero)
78 NDalicManualPINVOKE.delete_TtsPlayer(swigCPtr);
80 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
86 internal TTSPlayer() : this(NDalicManualPINVOKE.new_TtsPlayer__SWIG_0(), true)
88 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
92 /// Gets the singleton of the TTS player for the given mode.
94 /// <param name="mode"> The mode of TTS player.</param>
95 /// <returns> A handle of the TTS player for the given mode.</returns>
96 /// <since_tizen> 3 </since_tizen>
97 public static TTSPlayer Get(TTSMode mode)
99 TTSPlayer ret = new TTSPlayer(NDalicManualPINVOKE.TtsPlayer_Get__SWIG_0((int)mode), true);
100 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
105 /// Gets the singleton of the TTS player for the default mode.
107 /// <returns> A handle of the TTS player for the default mode.</returns>
108 /// <since_tizen> 3 </since_tizen>
109 public static TTSPlayer Get()
111 TTSPlayer ret = new TTSPlayer(NDalicManualPINVOKE.TtsPlayer_Get__SWIG_1(), true);
112 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
116 internal TTSPlayer(TTSPlayer handle) : this(NDalicManualPINVOKE.new_TtsPlayer__SWIG_1(TTSPlayer.getCPtr(handle)), true)
118 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
121 internal TTSPlayer Assign(TTSPlayer rhs)
123 TTSPlayer ret = new TTSPlayer(NDalicManualPINVOKE.TtsPlayer_Assign(swigCPtr, TTSPlayer.getCPtr(rhs)), false);
124 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
129 /// Starts playing the audio data synthesized from the specified text.
131 /// <param name="text"> The text to play.</param>
132 /// <remarks>The TTS player needs to be initialized.</remarks>
133 /// <since_tizen> 3 </since_tizen>
134 public void Play(string text)
136 NDalicManualPINVOKE.TtsPlayer_Play(swigCPtr, text);
137 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
141 /// Stops playing the utterance.
143 /// <remarks>The TTS player needs to be initialized.</remarks>
144 /// <since_tizen> 3 </since_tizen>
147 NDalicManualPINVOKE.TtsPlayer_Stop(swigCPtr);
148 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
152 /// Pauses the currently playing utterance.
154 /// <remarks>The TTS player needs to be initialized.</remarks>
155 /// <since_tizen> 3 </since_tizen>
158 NDalicManualPINVOKE.TtsPlayer_Pause(swigCPtr);
159 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
163 /// Resumes the previously paused utterance.
165 /// <remarks>The TTS player needs to be initialized.</remarks>
166 /// <since_tizen> 3 </since_tizen>
169 NDalicManualPINVOKE.TtsPlayer_Resume(swigCPtr);
170 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
174 /// Gets the current state of the player.
176 /// <returns> The current TTS state. </returns>
177 /// <remarks>The TTS player needs to be initialized.</remarks>
178 /// <since_tizen> 3 </since_tizen>
179 public TTSState GetState()
181 TTSState ret = (TTSState)NDalicManualPINVOKE.TtsPlayer_GetState(swigCPtr);
182 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
187 /// State changed argument.
189 public class StateChangedEventArgs : EventArgs
194 public TTSState PrevState
203 public TTSState NextState
210 private StateChangedEventCallbackType _stateChangedEventCallback;
211 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
212 private delegate void StateChangedEventCallbackType(TTSState prevState, TTSState nextState);
213 private event EventHandler<StateChangedEventArgs> _stateChangedEventHandler;
216 /// State changed event.
218 /// <since_tizen> 3 </since_tizen>
219 public event EventHandler<StateChangedEventArgs> StateChanged
223 if (_stateChangedEventHandler == null)
225 _stateChangedEventCallback = OnStateChanged;
226 StateChangedSignal().Connect(_stateChangedEventCallback);
229 _stateChangedEventHandler += value;
233 _stateChangedEventHandler -= value;
235 if (_stateChangedEventHandler == null && StateChangedSignal().Empty() == false && _stateChangedEventCallback != null)
237 StateChangedSignal().Disconnect(_stateChangedEventCallback);
242 private void OnStateChanged(TTSState prevState, TTSState nextState)
244 StateChangedEventArgs e = new StateChangedEventArgs();
246 e.PrevState = prevState;
247 e.NextState = nextState;
249 if (_stateChangedEventHandler != null)
251 _stateChangedEventHandler(this, e);
255 internal StateChangedSignalType StateChangedSignal()
257 StateChangedSignalType ret = new StateChangedSignalType(NDalicManualPINVOKE.TtsPlayer_StateChangedSignal(swigCPtr), false);
258 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
263 /// Enumeration for the instance of TTS mode.
265 /// <since_tizen> 3 </since_tizen>
269 /// Default mode for normal application.
273 /// Notification mode, such as playing utterance is started or completed.
277 /// Screen reader mode. <br />
278 /// To help visually impaired users interact with their devices,<br />
279 /// screen reader reads text or graphic elements on the screen using the TTS engine.
289 /// Enumeration for the instance of TTS state.
291 /// <since_tizen> 3 </since_tizen>
295 /// Player is not available.
299 /// Player is ready to play.
303 /// Player is playing.
307 /// Player is paused.