Release 4.0.0-preview1-00051
[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 (swigCPtr.Handle != global::System.IntPtr.Zero)
58             {
59                 if (swigCMemOwn)
60                 {
61                     swigCMemOwn = false;
62                     NDalicManualPINVOKE.delete_TtsPlayer(swigCPtr);
63                 }
64                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
65             }
66
67             base.Dispose(type);
68         }
69
70         internal TTSPlayer() : this(NDalicManualPINVOKE.new_TtsPlayer__SWIG_0(), true)
71         {
72             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
73         }
74
75         /// <summary>
76         /// Gets the singleton of the TtsPlayer for the given mode.
77         /// </summary>
78         /// <param name="mode"> The mode of tts-player. </param>
79         /// <returns> A handle of the Ttsplayer for the given mode. </returns>
80         public static TTSPlayer Get(TTSMode mode)
81         {
82             TTSPlayer ret = new TTSPlayer(NDalicManualPINVOKE.TtsPlayer_Get__SWIG_0((int)mode), true);
83             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
84             return ret;
85         }
86
87         /// <summary>
88         /// Gets the singleton of the TtsPlayer for the default mode..
89         /// </summary>
90         /// <returns> A handle of the Ttsplayer for the default mode. </returns>
91         public static TTSPlayer Get()
92         {
93             TTSPlayer ret = new TTSPlayer(NDalicManualPINVOKE.TtsPlayer_Get__SWIG_1(), true);
94             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
95             return ret;
96         }
97
98         internal TTSPlayer(TTSPlayer handle) : this(NDalicManualPINVOKE.new_TtsPlayer__SWIG_1(TTSPlayer.getCPtr(handle)), true)
99         {
100             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
101         }
102
103         internal TTSPlayer Assign(TTSPlayer rhs)
104         {
105             TTSPlayer ret = new TTSPlayer(NDalicManualPINVOKE.TtsPlayer_Assign(swigCPtr, TTSPlayer.getCPtr(rhs)), false);
106             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
107             return ret;
108         }
109
110         /// <summary>
111         /// Starts playing the audio data synthesized from the specified text.
112         /// </summary>
113         /// <param name="text"> The text to play. </param>
114         /// <remarks>The TtsPlayer needs to be initialized.</remarks>
115         public void Play(string text)
116         {
117             NDalicManualPINVOKE.TtsPlayer_Play(swigCPtr, text);
118             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
119         }
120
121         /// <summary>
122         /// Stops playing the utterance.
123         /// </summary>
124         /// <remarks>The TtsPlayer needs to be initialized.</remarks>
125         public void Stop()
126         {
127             NDalicManualPINVOKE.TtsPlayer_Stop(swigCPtr);
128             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
129         }
130
131         /// <summary>
132         /// Pauses the currently playing utterance.
133         /// </summary>
134         /// <remarks>The TtsPlayer needs to be initialized.</remarks>
135         public void Pause()
136         {
137             NDalicManualPINVOKE.TtsPlayer_Pause(swigCPtr);
138             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
139         }
140
141         /// <summary>
142         /// Resumes the previously paused utterance.
143         /// </summary>
144         /// <remarks>The TtsPlayer needs to be initialized.</remarks>
145         public void Resume()
146         {
147             NDalicManualPINVOKE.TtsPlayer_Resume(swigCPtr);
148             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
149         }
150
151         /// <summary>
152         /// Gets the current state of the player.
153         /// </summary>
154         /// <returns> The current TTS state. </returns>
155         /// <remarks>The TtsPlayer needs to be initialized.</remarks>
156         public TTSState GetState()
157         {
158             TTSState ret = (TTSState)NDalicManualPINVOKE.TtsPlayer_GetState(swigCPtr);
159             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
160             return ret;
161         }
162
163         /// <summary>
164         /// State changed argument.
165         /// </summary>
166         public class StateChangedEventArgs : EventArgs
167         {
168             public TTSState PrevState
169             {
170                 get;
171                 set;
172             }
173
174             public TTSState NextState
175             {
176                 get;
177                 set;
178             }
179         }
180
181         private StateChangedEventCallbackType _stateChangedEventCallback;
182         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
183         private delegate void StateChangedEventCallbackType(TTSState prevState, TTSState nextState);
184         private event EventHandler<StateChangedEventArgs> _stateChangedEventHandler;
185
186         /// <summary>
187         /// State changed event.
188         /// </summary>
189         public event EventHandler<StateChangedEventArgs> StateChanged
190         {
191             add
192             {
193                 if (_stateChangedEventHandler == null)
194                 {
195                     _stateChangedEventCallback = OnStateChanged;
196                     StateChangedSignal().Connect(_stateChangedEventCallback);
197                 }
198
199                 _stateChangedEventHandler += value;
200             }
201             remove
202             {
203                 _stateChangedEventHandler -= value;
204
205                 if (_stateChangedEventHandler == null && StateChangedSignal().Empty() == false && _stateChangedEventCallback != null)
206                 {
207                     StateChangedSignal().Disconnect(_stateChangedEventCallback);
208                 }
209             }
210         }
211
212         private void OnStateChanged(TTSState prevState, TTSState nextState)
213         {
214             StateChangedEventArgs e = new StateChangedEventArgs();
215
216             e.PrevState = prevState;
217             e.NextState = nextState;
218
219             if (_stateChangedEventHandler != null)
220             {
221                 _stateChangedEventHandler(this, e);
222             }
223         }
224
225         internal StateChangedSignalType StateChangedSignal()
226         {
227             StateChangedSignalType ret = new StateChangedSignalType(NDalicManualPINVOKE.TtsPlayer_StateChangedSignal(swigCPtr), false);
228             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
229             return ret;
230         }
231
232         /// <summary>
233         /// Enumeration for the instance of TTS mode.
234         /// </summary>
235         public enum TTSMode
236         {
237             /// <summary>
238             /// Default mode for normal application.
239             /// </summary>
240             Default = 0,
241             /// <summary>
242             /// Notification mode, such as playing utterance is started or completed.
243             /// </summary>
244             Notification,
245             /// <summary>
246             /// Screen reader mode. <br>
247             /// To help visually impaired users interact with their devices, <br>
248             /// screen reader reads text or graphic elements on the screen using the TTS engine.
249             /// </summary>
250             ScreenReader,
251             /// <summary>
252             /// Number of Mode.
253             /// </summary>
254             ModeNum
255         }
256
257         /// <summary>
258         /// Enumeration for the instance of TTS state.
259         /// </summary>
260         public enum TTSState
261         {
262             /// <summary>
263             /// Player is not available.
264             /// </summary>
265             Unavailable = 0,
266             /// <summary>
267             /// Player is ready to play.
268             /// </summary>
269             Ready,
270             /// <summary>
271             /// Player is playing.
272             /// </summary>
273             Playing,
274             /// <summary>
275             /// Player is paused.
276             /// </summary>
277             Paused
278         }
279
280     }
281
282 }