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 static readonly TTSPlayer instance = TTSPlayer.Get();
31 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
32 private StateChangedEventCallbackType _stateChangedEventCallback;
34 internal TTSPlayer(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.TtsPlayer.TtsPlayer_SWIGUpcast(cPtr), cMemoryOwn)
36 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
39 internal TTSPlayer() : this(Interop.TtsPlayer.new_TtsPlayer__SWIG_0(), true)
41 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
44 internal TTSPlayer(TTSPlayer handle) : this(Interop.TtsPlayer.new_TtsPlayer__SWIG_1(TTSPlayer.getCPtr(handle)), true)
46 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
49 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
50 private delegate void StateChangedEventCallbackType(TTSState prevState, TTSState nextState);
51 private event EventHandler<StateChangedEventArgs> _stateChangedEventHandler;
54 /// State changed event.
56 /// <since_tizen> 3 </since_tizen>
57 public event EventHandler<StateChangedEventArgs> StateChanged
61 if (_stateChangedEventHandler == null)
63 _stateChangedEventCallback = OnStateChanged;
64 StateChangedSignal().Connect(_stateChangedEventCallback);
67 _stateChangedEventHandler += value;
71 _stateChangedEventHandler -= value;
73 if (_stateChangedEventHandler == null && StateChangedSignal().Empty() == false && _stateChangedEventCallback != null)
75 StateChangedSignal().Disconnect(_stateChangedEventCallback);
81 /// Enumeration for the instance of TTS mode.
83 /// <since_tizen> 3 </since_tizen>
87 /// Default mode for normal application.
91 /// Notification mode, such as playing utterance is started or completed.
95 /// Screen reader mode. <br />
96 /// To help visually impaired users interact with their devices,<br />
97 /// screen reader reads text or graphic elements on the screen using the TTS engine.
107 /// Enumeration for the instance of TTS state.
109 /// <since_tizen> 3 </since_tizen>
113 /// Player is not available.
117 /// Player is ready to play.
121 /// Player is playing.
125 /// Player is paused.
131 /// Gets the singleton of the TTSPlayer object.
133 /// <since_tizen> 5 </since_tizen>
134 public static TTSPlayer Instance
143 /// Gets the singleton of the TTS player for the given mode.
145 /// <param name="mode"> The mode of TTS player.</param>
146 /// <returns> A handle of the TTS player for the given mode.</returns>
147 /// <since_tizen> 3 </since_tizen>
148 public static TTSPlayer Get(TTSMode mode)
150 TTSPlayer ret = new TTSPlayer(Interop.TtsPlayer.TtsPlayer_Get__SWIG_0((int)mode), true);
151 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
156 /// Gets the singleton of the TTS player for the default mode.
158 /// <returns> A handle of the TTS player for the default mode.</returns>
159 /// <since_tizen> 3 </since_tizen>
160 public static TTSPlayer Get()
162 TTSPlayer ret = new TTSPlayer(Interop.TtsPlayer.TtsPlayer_Get__SWIG_1(), true);
163 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
168 /// Starts playing the audio data synthesized from the specified text.
170 /// <param name="text"> The text to play.</param>
171 /// <remarks>The TTS player needs to be initialized.</remarks>
172 /// <since_tizen> 3 </since_tizen>
173 public void Play(string text)
175 Interop.TtsPlayer.TtsPlayer_Play(swigCPtr, text);
176 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
180 /// Stops playing the utterance.
182 /// <remarks>The TTS player needs to be initialized.</remarks>
183 /// <since_tizen> 3 </since_tizen>
186 Interop.TtsPlayer.TtsPlayer_Stop(swigCPtr);
187 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
191 /// Pauses the currently playing utterance.
193 /// <remarks>The TTS player needs to be initialized.</remarks>
194 /// <since_tizen> 3 </since_tizen>
197 Interop.TtsPlayer.TtsPlayer_Pause(swigCPtr);
198 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
202 /// Resumes the previously paused utterance.
204 /// <remarks>The TTS player needs to be initialized.</remarks>
205 /// <since_tizen> 3 </since_tizen>
208 Interop.TtsPlayer.TtsPlayer_Resume(swigCPtr);
209 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
213 /// Gets the current state of the player.
215 /// <returns> The current TTS state. </returns>
216 /// <remarks>The TTS player needs to be initialized.</remarks>
217 /// <since_tizen> 3 </since_tizen>
218 public TTSState GetState()
220 TTSState ret = (TTSState)Interop.TtsPlayer.TtsPlayer_GetState(swigCPtr);
221 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
225 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(TTSPlayer obj)
227 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
230 internal StateChangedSignalType StateChangedSignal()
232 StateChangedSignalType ret = new StateChangedSignalType(Interop.TtsPlayer.TtsPlayer_StateChangedSignal(swigCPtr), false);
233 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
237 internal TTSPlayer Assign(TTSPlayer rhs)
239 TTSPlayer ret = new TTSPlayer(Interop.TtsPlayer.TtsPlayer_Assign(swigCPtr, TTSPlayer.getCPtr(rhs)), false);
240 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
244 private void OnStateChanged(TTSState prevState, TTSState nextState)
246 StateChangedEventArgs e = new StateChangedEventArgs();
248 e.PrevState = prevState;
249 e.NextState = nextState;
251 if (_stateChangedEventHandler != null)
253 _stateChangedEventHandler(this, e);
258 /// State changed argument.
260 /// <since_tizen> 3 </since_tizen>
261 public class StateChangedEventArgs : EventArgs
266 /// <since_tizen> 3 </since_tizen>
267 public TTSState PrevState
276 /// <since_tizen> 3 </since_tizen>
277 public TTSState NextState