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