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 /// This will be released at Tizen.NET API Level 5, so currently this would be used as inhouse API.
49 [EditorBrowsable(EditorBrowsableState.Never)]
50 public static TTSPlayer Instance
61 /// <param name="type">The dispose type</param>
62 /// <since_tizen> 3 </since_tizen>
63 /// Please DO NOT use! This will be deprecated!
64 /// Dispose() method in Singletone classes (ex: FocusManager, StyleManager, VisualFactory, IMFManager, TtsPlayer, Window) is not required.
65 /// Because it is Sigletone, so it is alive for one thread until the NUI is terminated, so it never be disposed.
66 [Obsolete("Please do not use! This will be deprecated!")]
67 [EditorBrowsable(EditorBrowsableState.Never)]
68 protected override void Dispose(DisposeTypes type)
75 if (type == DisposeTypes.Explicit)
78 //Release your own managed resources here.
79 //You should release all of your own disposable objects here.
82 //Release your own unmanaged resources here.
83 //You should not access any managed member here except static instance.
84 //because the execution order of Finalizes is non-deterministic.
86 if (_stateChangedEventCallback != null)
88 StateChangedSignal().Disconnect(_stateChangedEventCallback);
91 if (swigCPtr.Handle != global::System.IntPtr.Zero)
96 NDalicManualPINVOKE.delete_TtsPlayer(swigCPtr);
98 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
104 internal TTSPlayer() : this(NDalicManualPINVOKE.new_TtsPlayer__SWIG_0(), true)
106 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
110 /// Gets the singleton of the TTS player for the given mode.
112 /// <param name="mode"> The mode of TTS player.</param>
113 /// <returns> A handle of the TTS player for the given mode.</returns>
114 /// <since_tizen> 3 </since_tizen>
115 public static TTSPlayer Get(TTSMode mode)
117 TTSPlayer ret = new TTSPlayer(NDalicManualPINVOKE.TtsPlayer_Get__SWIG_0((int)mode), true);
118 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
123 /// Gets the singleton of the TTS player for the default mode.
125 /// <returns> A handle of the TTS player for the default mode.</returns>
126 /// <since_tizen> 3 </since_tizen>
127 public static TTSPlayer Get()
129 TTSPlayer ret = new TTSPlayer(NDalicManualPINVOKE.TtsPlayer_Get__SWIG_1(), true);
130 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
134 internal TTSPlayer(TTSPlayer handle) : this(NDalicManualPINVOKE.new_TtsPlayer__SWIG_1(TTSPlayer.getCPtr(handle)), true)
136 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
139 internal TTSPlayer Assign(TTSPlayer rhs)
141 TTSPlayer ret = new TTSPlayer(NDalicManualPINVOKE.TtsPlayer_Assign(swigCPtr, TTSPlayer.getCPtr(rhs)), false);
142 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
147 /// Starts playing the audio data synthesized from the specified text.
149 /// <param name="text"> The text to play.</param>
150 /// <remarks>The TTS player needs to be initialized.</remarks>
151 /// <since_tizen> 3 </since_tizen>
152 public void Play(string text)
154 NDalicManualPINVOKE.TtsPlayer_Play(swigCPtr, text);
155 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
159 /// Stops playing the utterance.
161 /// <remarks>The TTS player needs to be initialized.</remarks>
162 /// <since_tizen> 3 </since_tizen>
165 NDalicManualPINVOKE.TtsPlayer_Stop(swigCPtr);
166 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
170 /// Pauses the currently playing utterance.
172 /// <remarks>The TTS player needs to be initialized.</remarks>
173 /// <since_tizen> 3 </since_tizen>
176 NDalicManualPINVOKE.TtsPlayer_Pause(swigCPtr);
177 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
181 /// Resumes the previously paused utterance.
183 /// <remarks>The TTS player needs to be initialized.</remarks>
184 /// <since_tizen> 3 </since_tizen>
187 NDalicManualPINVOKE.TtsPlayer_Resume(swigCPtr);
188 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
192 /// Gets the current state of the player.
194 /// <returns> The current TTS state. </returns>
195 /// <remarks>The TTS player needs to be initialized.</remarks>
196 /// <since_tizen> 3 </since_tizen>
197 public TTSState GetState()
199 TTSState ret = (TTSState)NDalicManualPINVOKE.TtsPlayer_GetState(swigCPtr);
200 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
205 /// State changed argument.
207 /// <since_tizen> 3 </since_tizen>
208 public class StateChangedEventArgs : EventArgs
213 /// <since_tizen> 3 </since_tizen>
214 public TTSState PrevState
223 /// <since_tizen> 3 </since_tizen>
224 public TTSState NextState
231 private StateChangedEventCallbackType _stateChangedEventCallback;
232 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
233 private delegate void StateChangedEventCallbackType(TTSState prevState, TTSState nextState);
234 private event EventHandler<StateChangedEventArgs> _stateChangedEventHandler;
237 /// State changed event.
239 /// <since_tizen> 3 </since_tizen>
240 public event EventHandler<StateChangedEventArgs> StateChanged
244 if (_stateChangedEventHandler == null)
246 _stateChangedEventCallback = OnStateChanged;
247 StateChangedSignal().Connect(_stateChangedEventCallback);
250 _stateChangedEventHandler += value;
254 _stateChangedEventHandler -= value;
256 if (_stateChangedEventHandler == null && StateChangedSignal().Empty() == false && _stateChangedEventCallback != null)
258 StateChangedSignal().Disconnect(_stateChangedEventCallback);
263 private void OnStateChanged(TTSState prevState, TTSState nextState)
265 StateChangedEventArgs e = new StateChangedEventArgs();
267 e.PrevState = prevState;
268 e.NextState = nextState;
270 if (_stateChangedEventHandler != null)
272 _stateChangedEventHandler(this, e);
276 internal StateChangedSignalType StateChangedSignal()
278 StateChangedSignalType ret = new StateChangedSignalType(NDalicManualPINVOKE.TtsPlayer_StateChangedSignal(swigCPtr), false);
279 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
284 /// Enumeration for the instance of TTS mode.
286 /// <since_tizen> 3 </since_tizen>
290 /// Default mode for normal application.
294 /// Notification mode, such as playing utterance is started or completed.
298 /// Screen reader mode. <br />
299 /// To help visually impaired users interact with their devices,<br />
300 /// screen reader reads text or graphic elements on the screen using the TTS engine.
310 /// Enumeration for the instance of TTS state.
312 /// <since_tizen> 3 </since_tizen>
316 /// Player is not available.
320 /// Player is ready to play.
324 /// Player is playing.
328 /// Player is paused.