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