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