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