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 StateChangedEventCallbackType _stateChangedEventCallback;
33 internal TTSPlayer(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.TtsPlayer.Upcast(cPtr), cMemoryOwn)
37 internal TTSPlayer() : this(Interop.TtsPlayer.NewTtsPlayer(), true)
39 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
42 internal TTSPlayer(TTSPlayer handle) : this(Interop.TtsPlayer.NewTtsPlayer(TTSPlayer.getCPtr(handle)), true)
44 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
47 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
48 private delegate void StateChangedEventCallbackType(TTSState prevState, TTSState nextState);
49 private event EventHandler<StateChangedEventArgs> _stateChangedEventHandler;
52 /// State changed event.
54 /// <since_tizen> 3 </since_tizen>
55 public event EventHandler<StateChangedEventArgs> StateChanged
59 if (_stateChangedEventHandler == null)
61 _stateChangedEventCallback = OnStateChanged;
62 StateChangedSignal().Connect(_stateChangedEventCallback);
65 _stateChangedEventHandler += value;
69 _stateChangedEventHandler -= value;
71 if (_stateChangedEventHandler == null && StateChangedSignal().Empty() == false && _stateChangedEventCallback != null)
73 StateChangedSignal().Disconnect(_stateChangedEventCallback);
79 /// Enumeration for the instance of TTS mode.
81 /// <since_tizen> 3 </since_tizen>
85 /// Default mode for normal application.
89 /// Notification mode, such as playing utterance is started or completed.
93 /// Screen reader mode. <br />
94 /// To help visually impaired users interact with their devices,<br />
95 /// screen reader reads text or graphic elements on the screen using the TTS engine.
105 /// Enumeration for the instance of TTS state.
107 /// <since_tizen> 3 </since_tizen>
111 /// Player is not available.
115 /// Player is ready to play.
119 /// Player is playing.
123 /// Player is paused.
129 /// Gets the singleton of the TTSPlayer object.
131 /// <since_tizen> 5 </since_tizen>
132 public static TTSPlayer Instance
141 /// Gets the singleton of the TTS player for the given mode.
143 /// <param name="mode"> The mode of TTS player.</param>
144 /// <returns> A handle of the TTS player for the given mode.</returns>
145 /// <since_tizen> 3 </since_tizen>
146 public static TTSPlayer Get(TTSMode mode)
148 TTSPlayer ret = new TTSPlayer(Interop.TtsPlayer.Get((int)mode), true);
149 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
154 /// Gets the singleton of the TTS player for the default mode.
156 /// <returns> A handle of the TTS player for the default mode.</returns>
157 /// <since_tizen> 3 </since_tizen>
158 public static TTSPlayer Get()
160 TTSPlayer ret = new TTSPlayer(Interop.TtsPlayer.Get(), true);
161 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
166 /// Starts playing the audio data synthesized from the specified text.
168 /// <param name="text"> The text to play.</param>
169 /// <remarks>The TTS player needs to be initialized.</remarks>
170 /// <since_tizen> 3 </since_tizen>
171 public void Play(string text)
173 Interop.TtsPlayer.Play(SwigCPtr, text);
174 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
178 /// Stops playing the utterance.
180 /// <remarks>The TTS player needs to be initialized.</remarks>
181 /// <since_tizen> 3 </since_tizen>
184 Interop.TtsPlayer.Stop(SwigCPtr);
185 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
189 /// Pauses the currently playing utterance.
191 /// <remarks>The TTS player needs to be initialized.</remarks>
192 /// <since_tizen> 3 </since_tizen>
195 Interop.TtsPlayer.Pause(SwigCPtr);
196 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
200 /// Resumes the previously paused utterance.
202 /// <remarks>The TTS player needs to be initialized.</remarks>
203 /// <since_tizen> 3 </since_tizen>
206 Interop.TtsPlayer.Resume(SwigCPtr);
207 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
211 /// Gets the current state of the player.
213 /// <returns> The current TTS state. </returns>
214 /// <remarks>The TTS player needs to be initialized.</remarks>
215 /// <since_tizen> 3 </since_tizen>
216 public TTSState GetState()
218 TTSState ret = (TTSState)Interop.TtsPlayer.GetState(SwigCPtr);
219 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
223 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(TTSPlayer obj)
225 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.SwigCPtr;
228 internal StateChangedSignalType StateChangedSignal()
230 StateChangedSignalType ret = new StateChangedSignalType(Interop.TtsPlayer.StateChangedSignal(SwigCPtr), false);
231 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
235 internal TTSPlayer Assign(TTSPlayer rhs)
237 TTSPlayer ret = new TTSPlayer(Interop.TtsPlayer.Assign(SwigCPtr, TTSPlayer.getCPtr(rhs)), false);
238 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
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);
256 /// State changed argument.
258 /// <since_tizen> 3 </since_tizen>
259 public class StateChangedEventArgs : EventArgs
264 /// <since_tizen> 3 </since_tizen>
265 public TTSState PrevState
274 /// <since_tizen> 3 </since_tizen>
275 public TTSState NextState