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.
21 using System.Runtime.InteropServices;
24 /// The Text-to-speech (TTS) player.
26 public class TTSPlayer : BaseHandle
28 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
30 internal TTSPlayer(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicManualPINVOKE.TtsPlayer_SWIGUpcast(cPtr), cMemoryOwn)
32 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
35 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(TTSPlayer obj)
37 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
43 /// <param name="type">The dispose type</param>
44 /// <since_tizen> 3 </since_tizen>
45 protected override void Dispose(DisposeTypes type)
52 if (type == DisposeTypes.Explicit)
55 //Release your own managed resources here.
56 //You should release all of your own disposable objects here.
59 //Release your own unmanaged resources here.
60 //You should not access any managed member here except static instance.
61 //because the execution order of Finalizes is non-deterministic.
63 if (_stateChangedEventCallback != null)
65 StateChangedSignal().Disconnect(_stateChangedEventCallback);
68 if (swigCPtr.Handle != global::System.IntPtr.Zero)
73 NDalicManualPINVOKE.delete_TtsPlayer(swigCPtr);
75 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
81 internal TTSPlayer() : this(NDalicManualPINVOKE.new_TtsPlayer__SWIG_0(), true)
83 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
87 /// Gets the singleton of the TTS player for the given mode.
89 /// <param name="mode"> The mode of TTS player.</param>
90 /// <returns> A handle of the TTS player for the given mode.</returns>
91 /// <since_tizen> 3 </since_tizen>
92 public static TTSPlayer Get(TTSMode mode)
94 TTSPlayer ret = new TTSPlayer(NDalicManualPINVOKE.TtsPlayer_Get__SWIG_0((int)mode), true);
95 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
100 /// Gets the singleton of the TTS player for the default mode.
102 /// <returns> A handle of the TTS player for the default mode.</returns>
103 /// <since_tizen> 3 </since_tizen>
104 public static TTSPlayer Get()
106 TTSPlayer ret = new TTSPlayer(NDalicManualPINVOKE.TtsPlayer_Get__SWIG_1(), true);
107 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
111 internal TTSPlayer(TTSPlayer handle) : this(NDalicManualPINVOKE.new_TtsPlayer__SWIG_1(TTSPlayer.getCPtr(handle)), true)
113 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
116 internal TTSPlayer Assign(TTSPlayer rhs)
118 TTSPlayer ret = new TTSPlayer(NDalicManualPINVOKE.TtsPlayer_Assign(swigCPtr, TTSPlayer.getCPtr(rhs)), false);
119 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
124 /// Starts playing the audio data synthesized from the specified text.
126 /// <param name="text"> The text to play.</param>
127 /// <remarks>The TTS player needs to be initialized.</remarks>
128 /// <since_tizen> 3 </since_tizen>
129 public void Play(string text)
131 NDalicManualPINVOKE.TtsPlayer_Play(swigCPtr, text);
132 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
136 /// Stops playing the utterance.
138 /// <remarks>The TTS player needs to be initialized.</remarks>
139 /// <since_tizen> 3 </since_tizen>
142 NDalicManualPINVOKE.TtsPlayer_Stop(swigCPtr);
143 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
147 /// Pauses the currently playing utterance.
149 /// <remarks>The TTS player needs to be initialized.</remarks>
150 /// <since_tizen> 3 </since_tizen>
153 NDalicManualPINVOKE.TtsPlayer_Pause(swigCPtr);
154 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
158 /// Resumes the previously paused utterance.
160 /// <remarks>The TTS player needs to be initialized.</remarks>
161 /// <since_tizen> 3 </since_tizen>
164 NDalicManualPINVOKE.TtsPlayer_Resume(swigCPtr);
165 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
169 /// Gets the current state of the player.
171 /// <returns> The current TTS state. </returns>
172 /// <remarks>The TTS player needs to be initialized.</remarks>
173 /// <since_tizen> 3 </since_tizen>
174 public TTSState GetState()
176 TTSState ret = (TTSState)NDalicManualPINVOKE.TtsPlayer_GetState(swigCPtr);
177 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
182 /// State changed argument.
184 public class StateChangedEventArgs : EventArgs
189 public TTSState PrevState
198 public TTSState NextState
205 private StateChangedEventCallbackType _stateChangedEventCallback;
206 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
207 private delegate void StateChangedEventCallbackType(TTSState prevState, TTSState nextState);
208 private event EventHandler<StateChangedEventArgs> _stateChangedEventHandler;
211 /// State changed event.
213 /// <since_tizen> 3 </since_tizen>
214 public event EventHandler<StateChangedEventArgs> StateChanged
218 if (_stateChangedEventHandler == null)
220 _stateChangedEventCallback = OnStateChanged;
221 StateChangedSignal().Connect(_stateChangedEventCallback);
224 _stateChangedEventHandler += value;
228 _stateChangedEventHandler -= value;
230 if (_stateChangedEventHandler == null && StateChangedSignal().Empty() == false && _stateChangedEventCallback != null)
232 StateChangedSignal().Disconnect(_stateChangedEventCallback);
237 private void OnStateChanged(TTSState prevState, TTSState nextState)
239 StateChangedEventArgs e = new StateChangedEventArgs();
241 e.PrevState = prevState;
242 e.NextState = nextState;
244 if (_stateChangedEventHandler != null)
246 _stateChangedEventHandler(this, e);
250 internal StateChangedSignalType StateChangedSignal()
252 StateChangedSignalType ret = new StateChangedSignalType(NDalicManualPINVOKE.TtsPlayer_StateChangedSignal(swigCPtr), false);
253 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
258 /// Enumeration for the instance of TTS mode.
260 /// <since_tizen> 3 </since_tizen>
264 /// Default mode for normal application.
268 /// Notification mode, such as playing utterance is started or completed.
272 /// Screen reader mode. <br />
273 /// To help visually impaired users interact with their devices,<br />
274 /// screen reader reads text or graphic elements on the screen using the TTS engine.
284 /// Enumeration for the instance of TTS state.
286 /// <since_tizen> 3 </since_tizen>
290 /// Player is not available.
294 /// Player is ready to play.
298 /// Player is playing.
302 /// Player is paused.