1 /** Copyright (c) 2017 Samsung Electronics Co., Ltd.
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
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 using System.Runtime.InteropServices;
23 /// The Text-to-speech (TTS) Player.
25 public class TTSPlayer : BaseHandle
27 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
29 internal TTSPlayer(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicManualPINVOKE.TtsPlayer_SWIGUpcast(cPtr), cMemoryOwn)
31 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
34 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(TTSPlayer obj)
36 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
39 protected override void Dispose(DisposeTypes type)
46 if (type == DisposeTypes.Explicit)
49 //Release your own managed resources here.
50 //You should release all of your own disposable objects here.
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.
57 if (_stateChangedEventCallback != null)
59 StateChangedSignal().Disconnect(_stateChangedEventCallback);
62 if (swigCPtr.Handle != global::System.IntPtr.Zero)
67 NDalicManualPINVOKE.delete_TtsPlayer(swigCPtr);
69 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
75 internal TTSPlayer() : this(NDalicManualPINVOKE.new_TtsPlayer__SWIG_0(), true)
77 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
81 /// Gets the singleton of the TtsPlayer for the given mode.
83 /// <param name="mode"> The mode of tts-player. </param>
84 /// <returns> A handle of the Ttsplayer for the given mode. </returns>
85 public static TTSPlayer Get(TTSMode mode)
87 TTSPlayer ret = new TTSPlayer(NDalicManualPINVOKE.TtsPlayer_Get__SWIG_0((int)mode), true);
88 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
93 /// Gets the singleton of the TtsPlayer for the default mode..
95 /// <returns> A handle of the Ttsplayer for the default mode. </returns>
96 public static TTSPlayer Get()
98 TTSPlayer ret = new TTSPlayer(NDalicManualPINVOKE.TtsPlayer_Get__SWIG_1(), true);
99 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
103 internal TTSPlayer(TTSPlayer handle) : this(NDalicManualPINVOKE.new_TtsPlayer__SWIG_1(TTSPlayer.getCPtr(handle)), true)
105 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
108 internal TTSPlayer Assign(TTSPlayer rhs)
110 TTSPlayer ret = new TTSPlayer(NDalicManualPINVOKE.TtsPlayer_Assign(swigCPtr, TTSPlayer.getCPtr(rhs)), false);
111 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
116 /// Starts playing the audio data synthesized from the specified text.
118 /// <param name="text"> The text to play. </param>
119 /// <remarks>The TtsPlayer needs to be initialized.</remarks>
120 public void Play(string text)
122 NDalicManualPINVOKE.TtsPlayer_Play(swigCPtr, text);
123 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
127 /// Stops playing the utterance.
129 /// <remarks>The TtsPlayer needs to be initialized.</remarks>
132 NDalicManualPINVOKE.TtsPlayer_Stop(swigCPtr);
133 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
137 /// Pauses the currently playing utterance.
139 /// <remarks>The TtsPlayer needs to be initialized.</remarks>
142 NDalicManualPINVOKE.TtsPlayer_Pause(swigCPtr);
143 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
147 /// Resumes the previously paused utterance.
149 /// <remarks>The TtsPlayer needs to be initialized.</remarks>
152 NDalicManualPINVOKE.TtsPlayer_Resume(swigCPtr);
153 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
157 /// Gets the current state of the player.
159 /// <returns> The current TTS state. </returns>
160 /// <remarks>The TtsPlayer needs to be initialized.</remarks>
161 public TTSState GetState()
163 TTSState ret = (TTSState)NDalicManualPINVOKE.TtsPlayer_GetState(swigCPtr);
164 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
169 /// State changed argument.
171 public class StateChangedEventArgs : EventArgs
173 public TTSState PrevState
179 public TTSState NextState
186 private StateChangedEventCallbackType _stateChangedEventCallback;
187 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
188 private delegate void StateChangedEventCallbackType(TTSState prevState, TTSState nextState);
189 private event EventHandler<StateChangedEventArgs> _stateChangedEventHandler;
192 /// State changed event.
194 public event EventHandler<StateChangedEventArgs> StateChanged
198 if (_stateChangedEventHandler == null)
200 _stateChangedEventCallback = OnStateChanged;
201 StateChangedSignal().Connect(_stateChangedEventCallback);
204 _stateChangedEventHandler += value;
208 _stateChangedEventHandler -= value;
210 if (_stateChangedEventHandler == null && StateChangedSignal().Empty() == false && _stateChangedEventCallback != null)
212 StateChangedSignal().Disconnect(_stateChangedEventCallback);
217 private void OnStateChanged(TTSState prevState, TTSState nextState)
219 StateChangedEventArgs e = new StateChangedEventArgs();
221 e.PrevState = prevState;
222 e.NextState = nextState;
224 if (_stateChangedEventHandler != null)
226 _stateChangedEventHandler(this, e);
230 internal StateChangedSignalType StateChangedSignal()
232 StateChangedSignalType ret = new StateChangedSignalType(NDalicManualPINVOKE.TtsPlayer_StateChangedSignal(swigCPtr), false);
233 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
238 /// Enumeration for the instance of TTS mode.
243 /// Default mode for normal application.
247 /// Notification mode, such as playing utterance is started or completed.
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.
263 /// Enumeration for the instance of TTS state.
268 /// Player is not available.
272 /// Player is ready to play.
276 /// Player is playing.
280 /// Player is paused.