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 public static TTSPlayer Instance
56 internal TTSPlayer() : this(NDalicManualPINVOKE.new_TtsPlayer__SWIG_0(), true)
58 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
62 /// Gets the singleton of the TTS player for the given mode.
64 /// <param name="mode"> The mode of TTS player.</param>
65 /// <returns> A handle of the TTS player for the given mode.</returns>
66 /// <since_tizen> 3 </since_tizen>
67 public static TTSPlayer Get(TTSMode mode)
69 TTSPlayer ret = new TTSPlayer(NDalicManualPINVOKE.TtsPlayer_Get__SWIG_0((int)mode), true);
70 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
75 /// Gets the singleton of the TTS player for the default mode.
77 /// <returns> A handle of the TTS player for the default mode.</returns>
78 /// <since_tizen> 3 </since_tizen>
79 public static TTSPlayer Get()
81 TTSPlayer ret = new TTSPlayer(NDalicManualPINVOKE.TtsPlayer_Get__SWIG_1(), true);
82 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
86 internal TTSPlayer(TTSPlayer handle) : this(NDalicManualPINVOKE.new_TtsPlayer__SWIG_1(TTSPlayer.getCPtr(handle)), true)
88 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
91 internal TTSPlayer Assign(TTSPlayer rhs)
93 TTSPlayer ret = new TTSPlayer(NDalicManualPINVOKE.TtsPlayer_Assign(swigCPtr, TTSPlayer.getCPtr(rhs)), false);
94 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
99 /// Starts playing the audio data synthesized from the specified text.
101 /// <param name="text"> The text to play.</param>
102 /// <remarks>The TTS player needs to be initialized.</remarks>
103 /// <since_tizen> 3 </since_tizen>
104 public void Play(string text)
106 NDalicManualPINVOKE.TtsPlayer_Play(swigCPtr, text);
107 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
111 /// Stops playing the utterance.
113 /// <remarks>The TTS player needs to be initialized.</remarks>
114 /// <since_tizen> 3 </since_tizen>
117 NDalicManualPINVOKE.TtsPlayer_Stop(swigCPtr);
118 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
122 /// Pauses the currently playing utterance.
124 /// <remarks>The TTS player needs to be initialized.</remarks>
125 /// <since_tizen> 3 </since_tizen>
128 NDalicManualPINVOKE.TtsPlayer_Pause(swigCPtr);
129 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
133 /// Resumes the previously paused utterance.
135 /// <remarks>The TTS player needs to be initialized.</remarks>
136 /// <since_tizen> 3 </since_tizen>
139 NDalicManualPINVOKE.TtsPlayer_Resume(swigCPtr);
140 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
144 /// Gets the current state of the player.
146 /// <returns> The current TTS state. </returns>
147 /// <remarks>The TTS player needs to be initialized.</remarks>
148 /// <since_tizen> 3 </since_tizen>
149 public TTSState GetState()
151 TTSState ret = (TTSState)NDalicManualPINVOKE.TtsPlayer_GetState(swigCPtr);
152 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
157 /// State changed argument.
159 /// <since_tizen> 3 </since_tizen>
160 public class StateChangedEventArgs : EventArgs
165 /// <since_tizen> 3 </since_tizen>
166 public TTSState PrevState
175 /// <since_tizen> 3 </since_tizen>
176 public TTSState NextState
183 private StateChangedEventCallbackType _stateChangedEventCallback;
184 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
185 private delegate void StateChangedEventCallbackType(TTSState prevState, TTSState nextState);
186 private event EventHandler<StateChangedEventArgs> _stateChangedEventHandler;
189 /// State changed event.
191 /// <since_tizen> 3 </since_tizen>
192 public event EventHandler<StateChangedEventArgs> StateChanged
196 if (_stateChangedEventHandler == null)
198 _stateChangedEventCallback = OnStateChanged;
199 StateChangedSignal().Connect(_stateChangedEventCallback);
202 _stateChangedEventHandler += value;
206 _stateChangedEventHandler -= value;
208 if (_stateChangedEventHandler == null && StateChangedSignal().Empty() == false && _stateChangedEventCallback != null)
210 StateChangedSignal().Disconnect(_stateChangedEventCallback);
215 private void OnStateChanged(TTSState prevState, TTSState nextState)
217 StateChangedEventArgs e = new StateChangedEventArgs();
219 e.PrevState = prevState;
220 e.NextState = nextState;
222 if (_stateChangedEventHandler != null)
224 _stateChangedEventHandler(this, e);
228 internal StateChangedSignalType StateChangedSignal()
230 StateChangedSignalType ret = new StateChangedSignalType(NDalicManualPINVOKE.TtsPlayer_StateChangedSignal(swigCPtr), false);
231 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
236 /// Enumeration for the instance of TTS mode.
238 /// <since_tizen> 3 </since_tizen>
242 /// Default mode for normal application.
246 /// Notification mode, such as playing utterance is started or completed.
250 /// Screen reader mode. <br />
251 /// To help visually impaired users interact with their devices,<br />
252 /// screen reader reads text or graphic elements on the screen using the TTS engine.
262 /// Enumeration for the instance of TTS state.
264 /// <since_tizen> 3 </since_tizen>
268 /// Player is not available.
272 /// Player is ready to play.
276 /// Player is playing.
280 /// Player is paused.