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 (swigCPtr.Handle != global::System.IntPtr.Zero)
62 NDalicManualPINVOKE.delete_TtsPlayer(swigCPtr);
64 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
70 internal TTSPlayer() : this(NDalicManualPINVOKE.new_TtsPlayer__SWIG_0(), true)
72 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
76 /// Gets the singleton of the TtsPlayer for the given mode.
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)
82 TTSPlayer ret = new TTSPlayer(NDalicManualPINVOKE.TtsPlayer_Get__SWIG_0((int)mode), true);
83 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
88 /// Gets the singleton of the TtsPlayer for the default mode..
90 /// <returns> A handle of the Ttsplayer for the default mode. </returns>
91 public static TTSPlayer Get()
93 TTSPlayer ret = new TTSPlayer(NDalicManualPINVOKE.TtsPlayer_Get__SWIG_1(), true);
94 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
98 internal TTSPlayer(TTSPlayer handle) : this(NDalicManualPINVOKE.new_TtsPlayer__SWIG_1(TTSPlayer.getCPtr(handle)), true)
100 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
103 internal TTSPlayer Assign(TTSPlayer rhs)
105 TTSPlayer ret = new TTSPlayer(NDalicManualPINVOKE.TtsPlayer_Assign(swigCPtr, TTSPlayer.getCPtr(rhs)), false);
106 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
111 /// Starts playing the audio data synthesized from the specified text.
113 /// <param name="text"> The text to play. </param>
114 /// <remarks>The TtsPlayer needs to be initialized.</remarks>
115 public void Play(string text)
117 NDalicManualPINVOKE.TtsPlayer_Play(swigCPtr, text);
118 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
122 /// Stops playing the utterance.
124 /// <remarks>The TtsPlayer needs to be initialized.</remarks>
127 NDalicManualPINVOKE.TtsPlayer_Stop(swigCPtr);
128 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
132 /// Pauses the currently playing utterance.
134 /// <remarks>The TtsPlayer needs to be initialized.</remarks>
137 NDalicManualPINVOKE.TtsPlayer_Pause(swigCPtr);
138 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
142 /// Resumes the previously paused utterance.
144 /// <remarks>The TtsPlayer needs to be initialized.</remarks>
147 NDalicManualPINVOKE.TtsPlayer_Resume(swigCPtr);
148 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
152 /// Gets the current state of the player.
154 /// <returns> The current TTS state. </returns>
155 /// <remarks>The TtsPlayer needs to be initialized.</remarks>
156 public TTSState GetState()
158 TTSState ret = (TTSState)NDalicManualPINVOKE.TtsPlayer_GetState(swigCPtr);
159 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
164 /// State changed argument.
166 public class StateChangedEventArgs : EventArgs
168 public TTSState PrevState
174 public TTSState NextState
181 private StateChangedEventCallbackType _stateChangedEventCallback;
182 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
183 private delegate void StateChangedEventCallbackType(TTSState prevState, TTSState nextState);
184 private event EventHandler<StateChangedEventArgs> _stateChangedEventHandler;
187 /// State changed event.
189 public event EventHandler<StateChangedEventArgs> StateChanged
193 if (_stateChangedEventHandler == null)
195 _stateChangedEventCallback = OnStateChanged;
196 StateChangedSignal().Connect(_stateChangedEventCallback);
199 _stateChangedEventHandler += value;
203 _stateChangedEventHandler -= value;
205 if (_stateChangedEventHandler == null && StateChangedSignal().Empty() == false && _stateChangedEventCallback != null)
207 StateChangedSignal().Disconnect(_stateChangedEventCallback);
212 private void OnStateChanged(TTSState prevState, TTSState nextState)
214 StateChangedEventArgs e = new StateChangedEventArgs();
216 e.PrevState = prevState;
217 e.NextState = nextState;
219 if (_stateChangedEventHandler != null)
221 _stateChangedEventHandler(this, e);
225 internal StateChangedSignalType StateChangedSignal()
227 StateChangedSignalType ret = new StateChangedSignalType(NDalicManualPINVOKE.TtsPlayer_StateChangedSignal(swigCPtr), false);
228 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
233 /// Enumeration for the instance of TTS mode.
238 /// Default mode for normal application.
242 /// Notification mode, such as playing utterance is started or completed.
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.
258 /// Enumeration for the instance of TTS state.
263 /// Player is not available.
267 /// Player is ready to play.
271 /// Player is playing.
275 /// Player is paused.