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