[NUI] Fix the build error message
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / TTSPlayer.cs
1 /*
2  * Copyright(c) 2017 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 using System;
19 using System.Runtime.InteropServices;
20 using System.ComponentModel;
21
22 namespace Tizen.NUI
23 {
24     /// <summary>
25     /// The Text-to-speech (TTS) player.
26     /// </summary>
27     public class TTSPlayer : BaseHandle
28     {
29         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
30
31         internal TTSPlayer(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicManualPINVOKE.TtsPlayer_SWIGUpcast(cPtr), cMemoryOwn)
32         {
33             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
34         }
35
36         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(TTSPlayer obj)
37         {
38             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
39         }
40
41         /// <summary>
42         /// Dispose.
43         /// </summary>
44         /// <param name="type">The dispose type</param>
45         /// <since_tizen> 3 </since_tizen>
46         /// Please DO NOT use! This will be deprecated!
47         /// Dispose() method in Singletone classes (ex: FocusManager, StyleManager, VisualFactory, IMFManager, TtsPlayer, Window) is not required.
48         /// Because it is Sigletone, so it is alive for one thread until the NUI is terminated, so it never be disposed.
49         [EditorBrowsable(EditorBrowsableState.Never)]
50         protected override void Dispose(DisposeTypes type)
51         {
52             if (disposed)
53             {
54                 return;
55             }
56
57             if (type == DisposeTypes.Explicit)
58             {
59                 //Called by User
60                 //Release your own managed resources here.
61                 //You should release all of your own disposable objects here.
62             }
63
64             //Release your own unmanaged resources here.
65             //You should not access any managed member here except static instance.
66             //because the execution order of Finalizes is non-deterministic.
67
68             if (_stateChangedEventCallback != null)
69             {
70                 StateChangedSignal().Disconnect(_stateChangedEventCallback);
71             }
72
73             if (swigCPtr.Handle != global::System.IntPtr.Zero)
74             {
75                 if (swigCMemOwn)
76                 {
77                     swigCMemOwn = false;
78                     NDalicManualPINVOKE.delete_TtsPlayer(swigCPtr);
79                 }
80                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
81             }
82
83             base.Dispose(type);
84         }
85
86         internal TTSPlayer() : this(NDalicManualPINVOKE.new_TtsPlayer__SWIG_0(), true)
87         {
88             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
89         }
90
91         /// <summary>
92         /// Gets the singleton of the TTS player for the given mode.
93         /// </summary>
94         /// <param name="mode"> The mode of TTS player.</param>
95         /// <returns> A handle of the TTS player for the given mode.</returns>
96         /// <since_tizen> 3 </since_tizen>
97         public static TTSPlayer Get(TTSMode mode)
98         {
99             TTSPlayer ret = new TTSPlayer(NDalicManualPINVOKE.TtsPlayer_Get__SWIG_0((int)mode), true);
100             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
101             return ret;
102         }
103
104         /// <summary>
105         /// Gets the singleton of the TTS player for the default mode.
106         /// </summary>
107         /// <returns> A handle of the TTS player for the default mode.</returns>
108         /// <since_tizen> 3 </since_tizen>
109         public static TTSPlayer Get()
110         {
111             TTSPlayer ret = new TTSPlayer(NDalicManualPINVOKE.TtsPlayer_Get__SWIG_1(), true);
112             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
113             return ret;
114         }
115
116         internal TTSPlayer(TTSPlayer handle) : this(NDalicManualPINVOKE.new_TtsPlayer__SWIG_1(TTSPlayer.getCPtr(handle)), true)
117         {
118             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
119         }
120
121         internal TTSPlayer Assign(TTSPlayer rhs)
122         {
123             TTSPlayer ret = new TTSPlayer(NDalicManualPINVOKE.TtsPlayer_Assign(swigCPtr, TTSPlayer.getCPtr(rhs)), false);
124             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
125             return ret;
126         }
127
128         /// <summary>
129         /// Starts playing the audio data synthesized from the specified text.
130         /// </summary>
131         /// <param name="text"> The text to play.</param>
132         /// <remarks>The TTS player needs to be initialized.</remarks>
133         /// <since_tizen> 3 </since_tizen>
134         public void Play(string text)
135         {
136             NDalicManualPINVOKE.TtsPlayer_Play(swigCPtr, text);
137             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
138         }
139
140         /// <summary>
141         /// Stops playing the utterance.
142         /// </summary>
143         /// <remarks>The TTS player needs to be initialized.</remarks>
144         /// <since_tizen> 3 </since_tizen>
145         public void Stop()
146         {
147             NDalicManualPINVOKE.TtsPlayer_Stop(swigCPtr);
148             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
149         }
150
151         /// <summary>
152         /// Pauses the currently playing utterance.
153         /// </summary>
154         /// <remarks>The TTS player needs to be initialized.</remarks>
155         /// <since_tizen> 3 </since_tizen>
156         public void Pause()
157         {
158             NDalicManualPINVOKE.TtsPlayer_Pause(swigCPtr);
159             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
160         }
161
162         /// <summary>
163         /// Resumes the previously paused utterance.
164         /// </summary>
165         /// <remarks>The TTS player needs to be initialized.</remarks>
166         /// <since_tizen> 3 </since_tizen>
167         public void Resume()
168         {
169             NDalicManualPINVOKE.TtsPlayer_Resume(swigCPtr);
170             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
171         }
172
173         /// <summary>
174         /// Gets the current state of the player.
175         /// </summary>
176         /// <returns> The current TTS state. </returns>
177         /// <remarks>The TTS player needs to be initialized.</remarks>
178         /// <since_tizen> 3 </since_tizen>
179         public TTSState GetState()
180         {
181             TTSState ret = (TTSState)NDalicManualPINVOKE.TtsPlayer_GetState(swigCPtr);
182             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
183             return ret;
184         }
185
186         /// <summary>
187         /// State changed argument.
188         /// </summary>
189         public class StateChangedEventArgs : EventArgs
190         {
191             /// <summary>
192             /// PrevState.
193             /// </summary>
194             public TTSState PrevState
195             {
196                 get;
197                 set;
198             }
199
200             /// <summary>
201             /// NextState.
202             /// </summary>
203             public TTSState NextState
204             {
205                 get;
206                 set;
207             }
208         }
209
210         private StateChangedEventCallbackType _stateChangedEventCallback;
211         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
212         private delegate void StateChangedEventCallbackType(TTSState prevState, TTSState nextState);
213         private event EventHandler<StateChangedEventArgs> _stateChangedEventHandler;
214
215         /// <summary>
216         /// State changed event.
217         /// </summary>
218         /// <since_tizen> 3 </since_tizen>
219         public event EventHandler<StateChangedEventArgs> StateChanged
220         {
221             add
222             {
223                 if (_stateChangedEventHandler == null)
224                 {
225                     _stateChangedEventCallback = OnStateChanged;
226                     StateChangedSignal().Connect(_stateChangedEventCallback);
227                 }
228
229                 _stateChangedEventHandler += value;
230             }
231             remove
232             {
233                 _stateChangedEventHandler -= value;
234
235                 if (_stateChangedEventHandler == null && StateChangedSignal().Empty() == false && _stateChangedEventCallback != null)
236                 {
237                     StateChangedSignal().Disconnect(_stateChangedEventCallback);
238                 }
239             }
240         }
241
242         private void OnStateChanged(TTSState prevState, TTSState nextState)
243         {
244             StateChangedEventArgs e = new StateChangedEventArgs();
245
246             e.PrevState = prevState;
247             e.NextState = nextState;
248
249             if (_stateChangedEventHandler != null)
250             {
251                 _stateChangedEventHandler(this, e);
252             }
253         }
254
255         internal StateChangedSignalType StateChangedSignal()
256         {
257             StateChangedSignalType ret = new StateChangedSignalType(NDalicManualPINVOKE.TtsPlayer_StateChangedSignal(swigCPtr), false);
258             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
259             return ret;
260         }
261
262         /// <summary>
263         /// Enumeration for the instance of TTS mode.
264         /// </summary>
265         /// <since_tizen> 3 </since_tizen>
266         public enum TTSMode
267         {
268             /// <summary>
269             /// Default mode for normal application.
270             /// </summary>
271             Default = 0,
272             /// <summary>
273             /// Notification mode, such as playing utterance is started or completed.
274             /// </summary>
275             Notification,
276             /// <summary>
277             /// Screen reader mode. <br />
278             /// To help visually impaired users interact with their devices,<br />
279             /// screen reader reads text or graphic elements on the screen using the TTS engine.
280             /// </summary>
281             ScreenReader,
282             /// <summary>
283             /// Number of mode.
284             /// </summary>
285             ModeNum
286         }
287
288         /// <summary>
289         /// Enumeration for the instance of TTS state.
290         /// </summary>
291         /// <since_tizen> 3 </since_tizen>
292         public enum TTSState
293         {
294             /// <summary>
295             /// Player is not available.
296             /// </summary>
297             Unavailable = 0,
298             /// <summary>
299             /// Player is ready to play.
300             /// </summary>
301             Ready,
302             /// <summary>
303             /// Player is playing.
304             /// </summary>
305             Playing,
306             /// <summary>
307             /// Player is paused.
308             /// </summary>
309             Paused
310         }
311
312     }
313
314 }