[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void TtsScreenReaderChangedCB(IntPtr handle, bool is_on, IntPtr userData);
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ internal delegate void TtsServiceStateChangedCB(IntPtr handle, ServiceState previous, ServiceState current, IntPtr userData);
+
[DllImport(Libraries.Tts, EntryPoint = "tts_create", CallingConvention = CallingConvention.Cdecl)]
internal static extern TtsError TtsCreate(out IntPtr handle);
[DllImport(Libraries.Tts, EntryPoint = "tts_get_state", CallingConvention = CallingConvention.Cdecl)]
internal static extern TtsError TtsGetState(IntPtr handle, out State state);
+ [DllImport(Libraries.Tts, EntryPoint = "tts_get_service_state", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern TtsError TtsGetServiceState(IntPtr handle, out ServiceState serviceState);
+
[DllImport(Libraries.Tts, EntryPoint = "tts_get_speed_range", CallingConvention = CallingConvention.Cdecl)]
internal static extern TtsError TtsGetSpeedRange(IntPtr handle, out int min, out int normal, out int max);
[DllImport(Libraries.Tts, EntryPoint = "tts_unset_screen_reader_changed_cb", CallingConvention = CallingConvention.Cdecl)]
internal static extern TtsError TtsUnsetScreenReaderChangedCB(IntPtr handle);
+
+ [DllImport(Libraries.Tts, EntryPoint = "tts_set_service_state_changed_cb", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern TtsError TtsSetServiceStateChangedCB(IntPtr handle, TtsServiceStateChangedCB callback, IntPtr userData);
+
+ [DllImport(Libraries.Tts, EntryPoint = "tts_unset_service_state_changed_cb", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern TtsError TtsUnsetServiceStateChangedCB(IntPtr handle);
}
}
--- /dev/null
+/*
+* Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* Licensed under the Apache License, Version 2.0 (the License);
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an AS IS BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+
+namespace Tizen.Uix.Tts
+{
+ /// <summary>
+ /// This class holds information related to the TTS ServiceStateChanged event.
+ /// </summary>
+ /// <since_tizen> 10 </since_tizen>
+ public class ServiceStateChangedEventArgs
+ {
+ internal ServiceStateChangedEventArgs(ServiceState previous, ServiceState current)
+ {
+ Previous = previous;
+ Current = current;
+ }
+
+ /// <summary>
+ /// The previous state of TTS service.
+ /// </summary>
+ /// <since_tizen> 10 </since_tizen>
+ public ServiceState Previous
+ {
+ get;
+ internal set;
+ }
+
+ /// <summary>
+ /// The current state of TTS service.
+ /// </summary>
+ /// <since_tizen> 10 </since_tizen>
+ public ServiceState Current
+ {
+ get;
+ internal set;
+ }
+ }
+}
};
/// <summary>
+ /// Enumeration for the states of TTS service.
+ /// </summary>
+ /// <since_tizen> 10 </since_tizen>
+ public enum ServiceState
+ {
+ /// <summary>
+ /// Ready state.
+ /// </summary>
+ Ready = 0,
+
+ /// <summary>
+ /// Synthesizing state.
+ /// </summary>
+ Synthesizing = 1,
+
+ /// <summary>
+ /// Playing state.
+ /// </summary>
+ Playing = 2,
+
+ /// <summary>
+ /// Unavailable state.
+ /// </summary>
+ Unavailable
+ };
+
+ /// <summary>
/// You can use Text-To-Speech (TTS) API's to read sound data transformed by the engine from input texts.
/// Applications can add input-text to queue for reading continuously and control the player that can play, pause, and stop sound data synthesized from text.
/// </summary>
private event EventHandler<DefaultVoiceChangedEventArgs> _defaultVoiceChanged;
private event EventHandler<EngineChangedEventArgs> _engineChanged;
private event EventHandler<ScreenReaderChangedEventArgs> _screenReaderChanged;
+ private event EventHandler<ServiceStateChangedEventArgs> _serviceStateChanged;
private bool disposedValue = false;
private readonly Object _stateChangedLock = new Object();
private readonly Object _utteranceStartedLock = new Object();
private readonly Object _defaultVoiceChangedLock = new Object();
private readonly Object _engineChangedLock = new Object();
private readonly Object _screenReaderChangedLock = new Object();
+ private readonly Object _serviceStateChangedLock = new Object();
private TtsStateChangedCB _stateDelegate;
private TtsUtteranceStartedCB _utteranceStartedResultDelegate;
private TtsUtteranceCompletedCB _utteranceCompletedResultDelegate;
private TtsDefaultVoiceChangedCB _voiceChangedDelegate;
private TtsEngineChangedCB _engineDelegate;
private TtsScreenReaderChangedCB _screenReaderDelegate;
+ private TtsServiceStateChangedCB _serviceStateDelegate;
private TtsSupportedVoiceCB _supportedvoiceDelegate;
/// <summary>
}
/// <summary>
+ /// Event to be invoked when the state of TTS service changes.
+ /// </summary>
+ /// <since_tizen> 10 </since_tizen>
+ public event EventHandler<ServiceStateChangedEventArgs> ServiceStateChanged
+ {
+ add
+ {
+ lock (_serviceStateChangedLock)
+ {
+ if (_serviceStateChanged == null)
+ {
+ _serviceStateDelegate = (IntPtr handle, ServiceState previous, ServiceState current, IntPtr userData) =>
+ {
+ ServiceStateChangedEventArgs args = new ServiceStateChangedEventArgs(previous, current);
+ _serviceStateChanged?.Invoke(this, args);
+ };
+
+ TtsError error = TtsSetServiceStateChangedCB(_handle, _serviceStateDelegate, IntPtr.Zero);
+ if (error != TtsError.None)
+ {
+ Log.Error(LogTag, "Add ServiceStateChanged Failed with error " + error);
+ }
+ }
+ _serviceStateChanged += value;
+ }
+ }
+
+ remove
+ {
+ lock (_serviceStateChangedLock)
+ {
+ _serviceStateChanged -= value;
+ if (_serviceStateChanged == null)
+ {
+ TtsError error = TtsUnsetStateChangedCB(_handle);
+ if (error != TtsError.None)
+ {
+ Log.Error(LogTag, "Remove ServiceStateChanged Failed with error " + error);
+ }
+ }
+ }
+ }
+ }
+
+ /// <summary>
/// Gets the default voice set by the user.
/// </summary>
/// <since_tizen> 3 </since_tizen>
}
/// <summary>
+ /// Gets the current state of TTS service.
+ /// </summary>
+ /// <value>
+ /// The current state of TTS service.
+ /// </value>
+ /// <since_tizen> 10 </since_tizen>
+ public ServiceState CurrentServiceState
+ {
+ get
+ {
+ ServiceState state;
+ TtsError error = TtsGetServiceState(_handle, out state);
+ if (error != TtsError.None)
+ {
+ Log.Error(LogTag, "CurrentServiceState Failed with error " + error);
+ return ServiceState.Unavailable;
+ }
+
+ return state;
+ }
+ }
+
+ /// <summary>
/// The TTS Mode can be set using this property.
/// </summary>
/// <since_tizen> 3 </since_tizen>