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.Cdecl)]
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 StateChangedSignalType StateChangedSignal()
225 StateChangedSignalType ret = new StateChangedSignalType(Interop.TtsPlayer.StateChangedSignal(SwigCPtr), false);
226 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
230 internal TTSPlayer Assign(TTSPlayer rhs)
232 TTSPlayer ret = new TTSPlayer(Interop.TtsPlayer.Assign(SwigCPtr, TTSPlayer.getCPtr(rhs)), false);
233 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
237 private void OnStateChanged(TTSState prevState, TTSState nextState)
239 if (stateChangedEventHandler != null)
241 StateChangedEventArgs e = new StateChangedEventArgs();
243 e.PrevState = prevState;
244 e.NextState = nextState;
245 stateChangedEventHandler(this, e);
250 /// State changed argument.
252 /// <since_tizen> 3 </since_tizen>
253 public class StateChangedEventArgs : EventArgs
258 /// <since_tizen> 3 </since_tizen>
259 public TTSState PrevState
268 /// <since_tizen> 3 </since_tizen>
269 public TTSState NextState