2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 using System.Collections.Generic;
20 using System.Runtime.InteropServices;
21 using static Interop.Tts;
23 namespace Tizen.Uix.Tts
26 /// Enumeration for the states.
28 /// <since_tizen> 3 </since_tizen>
34 /// <since_tizen> 3 </since_tizen>
40 /// <since_tizen> 3 </since_tizen>
46 /// <since_tizen> 3 </since_tizen>
52 /// <since_tizen> 3 </since_tizen>
56 /// Unavailable state.
58 /// <since_tizen> 3 </since_tizen>
63 /// Enumeration for TTS mode.
65 /// <since_tizen> 3 </since_tizen>
69 /// Default mode for normal application.
71 /// <since_tizen> 3 </since_tizen>
75 /// Notification mode.
77 /// <since_tizen> 3 </since_tizen>
81 /// Accessibility mode.
83 /// <since_tizen> 3 </since_tizen>
88 /// Enumeration for error values that can occur.
90 /// <since_tizen> 3 </since_tizen>
94 /// Successful, no error.
96 /// <since_tizen> 3 </since_tizen>
101 /// <since_tizen> 3 </since_tizen>
106 /// <since_tizen> 3 </since_tizen>
109 /// Invalid parameter.
111 /// <since_tizen> 3 </since_tizen>
114 /// No answer from the TTS service.
116 /// <since_tizen> 3 </since_tizen>
121 /// <since_tizen> 3 </since_tizen>
124 /// Permission denied.
126 /// <since_tizen> 3 </since_tizen>
129 /// TTS not supported.
131 /// <since_tizen> 3 </since_tizen>
136 /// <since_tizen> 3 </since_tizen>
141 /// <since_tizen> 3 </since_tizen>
144 /// No available engine.
146 /// <since_tizen> 3 </since_tizen>
149 /// Operation failed.
151 /// <since_tizen> 3 </since_tizen>
154 /// Audio policy blocked.
156 /// <since_tizen> 3 </since_tizen>
159 /// Not supported feature of current engine.
161 /// <since_tizen> 10 </since_tizen>
166 /// <since_tizen> 10 </since_tizen>
169 /// Screen reader off.
171 /// <since_tizen> 10 </since_tizen>
176 /// Enumeration for the voice types.
178 /// <since_tizen> 3 </since_tizen>
182 /// The automatic voice type.
184 /// <since_tizen> 3 </since_tizen>
188 /// The male voice type.
190 /// <since_tizen> 3 </since_tizen>
194 /// The female voice type.
196 /// <since_tizen> 3 </since_tizen>
200 /// The child voice type.
202 /// <since_tizen> 3 </since_tizen>
207 /// Enumeration for the states of TTS service.
209 /// <since_tizen> 10 </since_tizen>
210 public enum ServiceState
218 /// Synthesizing state.
228 /// Unavailable state.
234 /// You can use Text-To-Speech (TTS) API's to read sound data transformed by the engine from input texts.
235 /// 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.
237 /// <since_tizen> 3 </since_tizen>
238 public class TtsClient : IDisposable
240 private IntPtr _handle;
241 private event EventHandler<StateChangedEventArgs> _stateChanged;
242 private event EventHandler<UtteranceEventArgs> _utteranceStarted;
243 private event EventHandler<UtteranceEventArgs> _utteranceCompleted;
244 private event EventHandler<ErrorOccurredEventArgs> _errorOccurred;
245 private event EventHandler<DefaultVoiceChangedEventArgs> _defaultVoiceChanged;
246 private event EventHandler<EngineChangedEventArgs> _engineChanged;
247 private event EventHandler<ScreenReaderChangedEventArgs> _screenReaderChanged;
248 private event EventHandler<ServiceStateChangedEventArgs> _serviceStateChanged;
249 private bool disposedValue = false;
250 private readonly Object _stateChangedLock = new Object();
251 private readonly Object _utteranceStartedLock = new Object();
252 private readonly Object _utteranceCompletedLock = new Object();
253 private readonly Object _errorOccurredLock = new Object();
254 private readonly Object _defaultVoiceChangedLock = new Object();
255 private readonly Object _engineChangedLock = new Object();
256 private readonly Object _screenReaderChangedLock = new Object();
257 private readonly Object _serviceStateChangedLock = new Object();
258 private TtsStateChangedCB _stateDelegate;
259 private TtsUtteranceStartedCB _utteranceStartedResultDelegate;
260 private TtsUtteranceCompletedCB _utteranceCompletedResultDelegate;
261 private TtsErrorCB _errorDelegate;
262 private TtsDefaultVoiceChangedCB _voiceChangedDelegate;
263 private TtsEngineChangedCB _engineDelegate;
264 private TtsScreenReaderChangedCB _screenReaderDelegate;
265 private TtsServiceStateChangedCB _serviceStateDelegate;
266 private TtsSupportedVoiceCB _supportedvoiceDelegate;
269 /// Constructor to create a TTS instance.
271 /// <since_tizen> 3 </since_tizen>
273 /// http://tizen.org/feature/speech.synthesis
275 /// <exception cref="InvalidOperationException">
276 /// This exception can be due to the following reasons:
277 /// 1. Operation Failed
278 /// 2. Engine Not Found
280 /// <exception cref="OutOfMemoryException">This exception can be due to out Of memory.</exception>
281 /// <exception cref="NotSupportedException">This exception can be due to TTS not supported.</exception>
285 TtsError error = TtsCreate(out handle);
286 if (error != TtsError.None)
288 Log.Error(LogTag, "Create Failed with error " + error);
289 throw ExceptionFactory.CreateException(error);
296 /// Destructor to destroy TtsClient handle.
304 /// Event to be invoked when TTS state changes.
306 /// <since_tizen> 3 </since_tizen>
307 public event EventHandler<StateChangedEventArgs> StateChanged
311 lock (_stateChangedLock)
313 if (_stateChanged == null)
315 _stateDelegate = (IntPtr handle, State previous, State current, IntPtr userData) =>
317 StateChangedEventArgs args = new StateChangedEventArgs(previous, current);
318 _stateChanged?.Invoke(this, args);
321 TtsError error = TtsSetStateChangedCB(_handle, _stateDelegate, IntPtr.Zero);
322 if (error != TtsError.None)
324 Log.Error(LogTag, "Add StateChanged Failed with error " + error);
327 _stateChanged += value;
334 lock (_stateChangedLock)
336 _stateChanged -= value;
337 if (_stateChanged == null)
339 TtsError error = TtsUnsetStateChangedCB(_handle);
340 if (error != TtsError.None)
342 Log.Error(LogTag, "Remove StateChanged Failed with error " + error);
351 /// Event to be invoked when the utterance starts.
353 /// <since_tizen> 3 </since_tizen>
354 public event EventHandler<UtteranceEventArgs> UtteranceStarted
358 lock (_utteranceStartedLock)
360 if (_utteranceStarted == null)
362 _utteranceStartedResultDelegate = (IntPtr handle, int uttId, IntPtr userData) =>
364 UtteranceEventArgs args = new UtteranceEventArgs(uttId);
365 _utteranceStarted?.Invoke(this, args);
368 TtsError error = TtsSetUtteranceStartedCB(_handle, _utteranceStartedResultDelegate, IntPtr.Zero);
369 if (error != TtsError.None)
371 Log.Error(LogTag, "Add UtteranceStarted Failed with error " + error);
374 _utteranceStarted += value;
380 lock (_utteranceStartedLock)
382 _utteranceStarted -= value;
383 if (_utteranceStarted == null)
385 TtsError error = TtsUnsetUtteranceStartedCB(_handle);
386 if (error != TtsError.None)
388 Log.Error(LogTag, "Remove UtteranceStarted Failed with error " + error);
396 /// Event to be invoked when the utterance completes.
398 /// <since_tizen> 3 </since_tizen>
399 public event EventHandler<UtteranceEventArgs> UtteranceCompleted
403 lock (_utteranceCompletedLock)
405 if (_utteranceCompleted == null)
407 _utteranceCompletedResultDelegate = (IntPtr handle, int uttId, IntPtr userData) =>
409 UtteranceEventArgs args = new UtteranceEventArgs(uttId);
410 _utteranceCompleted?.Invoke(this, args);
413 TtsError error = TtsSetUtteranceCompletedCB(_handle, _utteranceCompletedResultDelegate, IntPtr.Zero);
414 if (error != TtsError.None)
416 Log.Error(LogTag, "Add UtteranceCompleted Failed with error " + error);
419 _utteranceCompleted += value;
425 lock (_utteranceCompletedLock)
427 _utteranceCompleted -= value;
428 if (_utteranceCompleted == null)
430 TtsError error = TtsUnsetUtteranceCompletedCB(_handle);
431 if (error != TtsError.None)
433 Log.Error(LogTag, "Remove UtteranceCompleted Failed with error " + error);
441 /// Event to be invoked when an error occurs.
443 /// <since_tizen> 4 </since_tizen>
444 public event EventHandler<ErrorOccurredEventArgs> ErrorOccurred
448 lock (_errorOccurredLock)
450 if (_errorOccurred == null)
452 _errorDelegate = (IntPtr handle, int uttId, TtsError reason, IntPtr userData) =>
454 ErrorOccurredEventArgs args = new ErrorOccurredEventArgs(handle, uttId, reason);
455 _errorOccurred?.Invoke(this, args);
458 TtsError error = TtsSetErrorCB(_handle, _errorDelegate, IntPtr.Zero);
459 if (error != TtsError.None)
461 Log.Error(LogTag, "Add ErrorOccurred Failed with error " + error);
464 _errorOccurred += value;
470 lock (_errorOccurredLock)
472 _errorOccurred -= value;
473 if (_errorOccurred == null)
475 TtsError error = TtsUnsetErrorCB(_handle);
476 if (error != TtsError.None)
478 Log.Error(LogTag, "Remove ErrorOccurred Failed with error " + error);
486 /// Event to be invoked when an error occurs.
488 /// <since_tizen> 3 </since_tizen>
489 public event EventHandler<DefaultVoiceChangedEventArgs> DefaultVoiceChanged
493 lock (_defaultVoiceChangedLock)
495 if (_defaultVoiceChanged == null)
497 _voiceChangedDelegate = (IntPtr handle, IntPtr previousLanguage, int previousVoiceType, IntPtr currentLanguage, int currentVoiceType, IntPtr userData) =>
499 string previousLanguageString = Marshal.PtrToStringAnsi(previousLanguage);
500 string currentLanguageString = Marshal.PtrToStringAnsi(currentLanguage);
501 DefaultVoiceChangedEventArgs args = new DefaultVoiceChangedEventArgs(previousLanguageString, previousVoiceType, currentLanguageString, currentVoiceType);
502 _defaultVoiceChanged?.Invoke(this, args);
505 TtsError error = TtsSetDefaultVoiceChangedCB(_handle, _voiceChangedDelegate, IntPtr.Zero);
506 if (error != TtsError.None)
508 Log.Error(LogTag, "Add DefaultVoiceChanged Failed with error " + error);
511 _defaultVoiceChanged += value;
517 lock (_defaultVoiceChangedLock)
519 _defaultVoiceChanged -= value;
520 if (_defaultVoiceChanged == null)
522 TtsError error = TtsUnsetDefaultVoiceChangedCB(_handle);
523 if (error != TtsError.None)
525 Log.Error(LogTag, "Remove DefaultVoiceChanged Failed with error " + error);
533 /// Event to be invoked to detect engine change.
535 /// <since_tizen> 3 </since_tizen>
536 public event EventHandler<EngineChangedEventArgs> EngineChanged
540 lock (_engineChangedLock)
542 if (_engineChanged == null)
544 _engineDelegate = (IntPtr handle, IntPtr engineId, IntPtr language, int voiceType, bool needCredential, IntPtr userData) =>
546 string engineIdString = Marshal.PtrToStringAnsi(engineId);
547 string languageString = Marshal.PtrToStringAnsi(language);
548 EngineChangedEventArgs args = new EngineChangedEventArgs(engineIdString, languageString, voiceType, needCredential);
549 _engineChanged?.Invoke(this, args);
551 TtsError error = TtsSetEngineChangedCB(_handle, _engineDelegate, IntPtr.Zero);
552 if (error != TtsError.None)
554 Log.Error(LogTag, "Add EngineChanged Failed with error " + error);
557 _engineChanged += value;
563 lock (_engineChangedLock)
565 _engineChanged -= value;
566 if (_engineChanged == null)
568 TtsError error = TtsUnsetEngineChangedCB(_handle);
569 if (error != TtsError.None)
571 Log.Error(LogTag, "Remove EngineChanged Failed with error " + error);
579 /// Event to be invoked to detect screen reader status change.
581 /// <since_tizen> 9 </since_tizen>
582 public event EventHandler<ScreenReaderChangedEventArgs> ScreenReaderChanged
586 lock (_screenReaderChangedLock)
588 if (_screenReaderChanged == null)
590 _screenReaderDelegate = (IntPtr handle, bool isOn, IntPtr userData) =>
592 ScreenReaderChangedEventArgs args = new ScreenReaderChangedEventArgs(isOn);
593 _screenReaderChanged?.Invoke(this, args);
595 TtsError error = TtsSetScreenReaderChangedCB(_handle, _screenReaderDelegate, IntPtr.Zero);
596 if (error != TtsError.None)
598 Log.Error(LogTag, "Add ScreenReaderChanged Failed with error " + error);
601 _screenReaderChanged += value;
607 lock (_screenReaderChangedLock)
609 _screenReaderChanged -= value;
610 if (_screenReaderChanged == null)
612 TtsError error = TtsUnsetScreenReaderChangedCB(_handle);
613 if (error != TtsError.None)
615 Log.Error(LogTag, "Remove ScreenReaderChanged Failed with error " + error);
623 /// Event to be invoked when the state of TTS service changes.
625 /// <since_tizen> 10 </since_tizen>
626 public event EventHandler<ServiceStateChangedEventArgs> ServiceStateChanged
630 lock (_serviceStateChangedLock)
632 if (_serviceStateChanged == null)
634 _serviceStateDelegate = (IntPtr handle, ServiceState previous, ServiceState current, IntPtr userData) =>
636 ServiceStateChangedEventArgs args = new ServiceStateChangedEventArgs(previous, current);
637 _serviceStateChanged?.Invoke(this, args);
640 TtsError error = TtsSetServiceStateChangedCB(_handle, _serviceStateDelegate, IntPtr.Zero);
641 if (error != TtsError.None)
643 Log.Error(LogTag, "Add ServiceStateChanged Failed with error " + error);
646 _serviceStateChanged += value;
652 lock (_serviceStateChangedLock)
654 _serviceStateChanged -= value;
655 if (_serviceStateChanged == null)
657 TtsError error = TtsUnsetStateChangedCB(_handle);
658 if (error != TtsError.None)
660 Log.Error(LogTag, "Remove ServiceStateChanged Failed with error " + error);
668 /// Gets the default voice set by the user.
670 /// <since_tizen> 3 </since_tizen>
672 /// The default voice in TTS.
675 /// The default voice SupportedVoice value.
677 public SupportedVoice DefaultVoice
683 TtsError error = TtsGetDefaultVoice(_handle, out language, out voiceType);
684 if (error != TtsError.None)
686 Log.Error(LogTag, "DefaultVoice Failed with error " + error);
687 return new SupportedVoice();
690 return new SupportedVoice(language, voiceType);
695 /// Gets the maximum byte size for text.
697 /// <since_tizen> 3 </since_tizen>
699 /// The Maximum byte size for text.
702 /// The Default Voice SupportedVoice value, 0 if unable to get the value.
705 /// The Client must be in the <see cref="State.Ready"/> state.
707 public uint MaxTextSize
712 TtsError error = TtsGetMaxTextSize(_handle, out maxTextSize);
713 if (error != TtsError.None)
715 Log.Error(LogTag, "MaxTextSize Failed with error " + error);
725 /// Gets the current TTS state.
727 /// <since_tizen> 3 </since_tizen>
729 /// The current state of TTS.
732 /// Current TTS State value.
734 public State CurrentState
739 TtsError error = TtsGetState(_handle, out state);
740 if (error != TtsError.None)
742 Log.Error(LogTag, "CurrentState Failed with error " + error);
743 return State.Unavailable;
752 /// Gets the current state of TTS service.
755 /// The current state of TTS service.
757 /// <since_tizen> 10 </since_tizen>
758 public ServiceState CurrentServiceState
763 TtsError error = TtsGetServiceState(_handle, out state);
764 if (error != TtsError.None)
766 Log.Error(LogTag, "CurrentServiceState Failed with error " + error);
767 return ServiceState.Unavailable;
775 /// The TTS Mode can be set using this property.
777 /// <since_tizen> 3 </since_tizen>
779 /// The current TTS mode (default, screen-reader, notification).
784 /// <exception cref="InvalidOperationException">
785 /// This exception can be due to the following reasons while setting the value:
786 /// 1. Operation Failed
787 /// 2. Engine Not Found
789 /// <exception cref="OutOfMemoryException">This exception can be due to out Of memory.</exception>
790 /// <exception cref="NotSupportedException">This exception can be due to TTS not supported.</exception>
792 /// The Client must be in the <see cref="State.Created"/> state.
794 public Mode CurrentMode
798 Mode mode = Mode.Default;
799 TtsError error = TtsGetMode(_handle, out mode);
800 if (error != TtsError.None)
802 Log.Error(LogTag, "Get Mode Failed with error " + error);
811 error = TtsSetMode(_handle, value);
813 if (error != TtsError.None)
815 Log.Error(LogTag, "Set Mode Failed with error " + error);
816 throw ExceptionFactory.CreateException(error);
822 /// Gets the current status of screen reader.
824 /// <since_tizen> 9 </since_tizen>
826 /// The current status of screen reader.
829 /// Boolean value whether screen reader is on or off.
832 /// http://tizen.org/feature/speech.synthesis
834 /// <exception cref="NotSupportedException">This exception can be due to TTS not supported.</exception>
835 public bool IsScreenReaderOn
840 TtsError error = TtsCheckScreenReaderOn(_handle, out isOn);
841 if (error != TtsError.None)
843 Log.Error(LogTag, "Fail to check screen reader on with error " + error);
852 /// Sets the application credential.
854 /// <since_tizen> 3 </since_tizen>
855 /// <param name="credential">.
856 /// The credential string.
859 /// http://tizen.org/feature/speech.synthesis
861 /// <exception cref="InvalidOperationException">This exception can be due to an invalid state.</exception>
862 /// <exception cref="NotSupportedException">This exception can be due to TTS not supported.</exception>
863 /// <exception cref="ArgumentException">This exception can be due to improper value provided while setting the value.</exception>
865 /// The Client must be in the <see cref="State.Created"/> or <see cref="State.Ready"/> state.
867 public void SetCredential(string credential)
869 TtsError error = TtsSetCredential(_handle, credential);
870 if (error != TtsError.None)
872 Tizen.Log.Error(LogTag, "SetCredential Failed with error " + error);
873 throw ExceptionFactory.CreateException(error);
878 /// Connects to the TTS service asynchronously.
880 /// <since_tizen> 3 </since_tizen>
882 /// http://tizen.org/feature/speech.synthesis
884 /// <exception cref="InvalidOperationException">
885 /// This exception can be due to the following reasons while setting the value:
887 /// 2. Screen reader off
889 /// <exception cref="NotSupportedException">This exception can be due to TTS not supported.</exception>
891 /// The Client must be in the <see cref="State.Created"/> state.
894 /// If this function is successful, the Client will be in the <see cref="State.Ready"/> state.
895 /// If this function is unsuccessful, ErrorOccurred event will be invoked.
897 public void Prepare()
899 TtsError error = TtsPrepare(_handle);
900 if (error != TtsError.None)
902 Log.Error(LogTag, "Prepare Failed with error " + error);
903 throw ExceptionFactory.CreateException(error);
908 /// Disconnects from the TTS service.
910 /// <since_tizen> 3 </since_tizen>
912 /// http://tizen.org/feature/speech.synthesis
914 /// <exception cref="InvalidOperationException">This exception can be due to an invalid state.</exception>
915 /// <exception cref="NotSupportedException">This exception can be due to TTS not supported.</exception>
917 /// The Client must be in the <see cref="State.Ready"/> state.
920 /// If this function is successful, the Client will be in the <see cref="State.Created"/> state.
922 public void Unprepare()
924 TtsError error = TtsUnprepare(_handle);
925 if (error != TtsError.None)
927 Log.Error(LogTag, "Unprepare Failed with error " + error);
928 throw ExceptionFactory.CreateException(error);
933 /// Retrieves all supported voices of the current engine.
935 /// <since_tizen> 3 </since_tizen>
937 /// The list of SupportedVoice.
940 /// http://tizen.org/feature/speech.synthesis
942 /// <exception cref="InvalidOperationException">
943 /// This exception can be due to the following reasons:
944 /// 1. Engine Not Found
945 /// 2. Operation Failed
947 /// <exception cref="NotSupportedException">This exception can be due to TTS not supported.</exception>
948 public IEnumerable<SupportedVoice> GetSupportedVoices()
950 List<SupportedVoice> voicesList = new List<SupportedVoice>();
952 _supportedvoiceDelegate = (IntPtr handle, IntPtr language, int voiceType, IntPtr userData) =>
954 string lang = Marshal.PtrToStringAnsi(language);
955 SupportedVoice voice = new SupportedVoice(lang, voiceType);
956 voicesList.Add(voice);
959 TtsError error = TtsForeachSupportedVoices(_handle, _supportedvoiceDelegate, IntPtr.Zero);
960 if (error != TtsError.None)
962 Log.Error(LogTag, "GetSupportedVoices Failed with error " + error);
963 throw ExceptionFactory.CreateException(error);
970 /// Gets the private data from TTS engine.
972 /// <since_tizen> 3 </since_tizen>
973 /// <param name="key">
977 /// The data corresponding to the provided key.
980 /// http://tizen.org/feature/speech.synthesis
982 /// <exception cref="InvalidOperationException">
983 /// This exception can be due to the following reasons:
985 /// 2. Engine Not found
986 /// 3. Operation Failure
988 /// <exception cref="NotSupportedException">This exception can be due to TTS not supported.</exception>
990 /// The Client must be in the <see cref="State.Ready"/> state.
992 public string GetPrivateData(string key)
995 TtsError error = TtsGetPrivateData(_handle, key, out data);
996 if (error != TtsError.None)
998 Log.Error(LogTag, "GetPrivateData Failed with error " + error);
999 throw ExceptionFactory.CreateException(error);
1006 /// Sets the private data to tts engine.
1008 /// <since_tizen> 3 </since_tizen>
1009 /// <param name="key">
1012 /// <param name="data">
1013 /// The data string.
1016 /// http://tizen.org/feature/speech.synthesis
1018 /// <exception cref="InvalidOperationException">
1019 /// This exception can be due to the following reasons:
1020 /// 1. Invalid State
1021 /// 2. Engine Not found
1022 /// 3. Operation Failure
1024 /// <exception cref="NotSupportedException">This exception can be due to TTS not supported.</exception>
1025 /// <exception cref="ArgumentException">This exception can be due to improper value provided while setting the value.</exception>
1027 /// The Client must be in the <see cref="State.Ready"/> state.
1029 public void SetPrivateData(string key, string data)
1031 TtsError error = TtsSetPrivateData(_handle, key, data);
1032 if (error != TtsError.None)
1034 Log.Error(LogTag, "SetPrivateData Failed with error " + error);
1035 throw ExceptionFactory.CreateException(error);
1040 /// Gets the speed range.
1042 /// <since_tizen> 3 </since_tizen>
1044 /// The SpeedRange value.
1047 /// http://tizen.org/feature/speech.synthesis
1049 /// <exception cref="InvalidOperationException">
1050 /// This exception can be due to the following reasons:
1051 /// 1. Invalid State
1052 /// 2. Operation Failure
1054 /// <exception cref="NotSupportedException">This exception can be due to TTS not supported.</exception>
1056 /// The Client must be in the <see cref="State.Created"/> state.
1058 public SpeedRange GetSpeedRange()
1060 int min = 0, max = 0, normal = 0;
1061 TtsError error = TtsGetSpeedRange(_handle, out min, out normal, out max);
1062 if (error != TtsError.None)
1064 Log.Error(LogTag, "GetSpeedRange Failed with error " + error);
1065 throw ExceptionFactory.CreateException(error);
1068 return new SpeedRange(min, normal, max);
1072 /// Adds a text to the queue.
1074 /// <since_tizen> 3 </since_tizen>
1076 /// Locale MUST be set for text validation check.
1078 /// <param name="text">
1081 /// <param name="language">
1082 /// The language selected from the SupportedVoice.Language Property obtained from GetSupportedVoices()(e.g. 'NULL'(Automatic),'en_US').
1084 /// <param name="voiceType">
1085 /// The voice type selected from the SupportedVoice.VoiceType Property obtained from GetSupportedVoices().
1087 /// <param name="speed">
1088 /// A speaking speed (e.g.0 for Auto or the value from SpeedRange Property).
1091 /// The utterance ID.
1094 /// http://tizen.org/feature/speech.synthesis
1096 /// <exception cref="InvalidOperationException">
1097 /// This exception can be due to the following reasons:
1098 /// 1. Invalid State
1099 /// 2. Operation Failure
1100 /// 3. Invalid Voice
1101 /// 4. Screen reader off
1103 /// <exception cref="NotSupportedException">This exception can be due to TTS not supported.</exception>
1104 /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception>
1105 /// <exception cref="ArgumentException">This exception can be due to improper value provided while setting the value.</exception>
1107 /// The Client must be in the <see cref="State.Ready"/>, <see cref="State.Playing"/>, or <see cref="State.Paused"/> state.
1109 public int AddText(string text, string language, int voiceType, int speed)
1112 TtsError error = TtsAddText(_handle, text, language, voiceType, speed, out id);
1113 if (error != TtsError.None)
1115 Log.Error(LogTag, "AddText Failed with error " + error);
1116 throw ExceptionFactory.CreateException(error);
1123 /// Starts synthesizing voice from the text and plays the synthesized audio data.
1125 /// <since_tizen> 3 </since_tizen>
1127 /// http://tizen.org/feature/speech.synthesis
1129 /// <exception cref="InvalidOperationException">
1130 /// This exception can be due to the following reasons:
1131 /// 1. Invalid State
1132 /// 2. Operation Failure
1133 /// 3. Out of Network
1134 /// 4. Screen reader off
1136 /// <exception cref="NotSupportedException">This exception can be due to TTS not supported.</exception>
1137 /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception>
1139 /// The Client must be in the <see cref="State.Ready"/> or <see cref="State.Paused"/> state.
1142 /// If this function succeeds, the Client will be in the <see cref="State.Playing"/> state.
1146 TtsError error = TtsPlay(_handle);
1147 if (error != TtsError.None)
1149 Log.Error(LogTag, "Play Failed with error " + error);
1150 throw ExceptionFactory.CreateException(error);
1155 /// Stops playing the utterance and clears the queue.
1157 /// <since_tizen> 3 </since_tizen>
1159 /// http://tizen.org/feature/speech.synthesis
1161 /// <exception cref="InvalidOperationException">
1162 /// This exception can be due to the following reasons:
1164 /// 2. Operation Failure
1165 /// 3. Screen reader off
1167 /// <exception cref="NotSupportedException">This exception can be due to TTS not supported.</exception>
1169 /// The Client must be in the <see cref="State.Ready"/>, <see cref="State.Playing"/>, or <see cref="State.Paused"/> state.
1172 /// If this function succeeds, the Client will be in the <see cref="State.Ready"/> state.
1173 /// This function will remove all text added via AddText() and synthesized sound data.
1177 TtsError error = TtsStop(_handle);
1178 if (error != TtsError.None)
1180 Log.Error(LogTag, "Stop Failed with error " + error);
1181 throw ExceptionFactory.CreateException(error);
1186 /// Pauses the currently playing utterance.
1188 /// <since_tizen> 3 </since_tizen>
1190 /// http://tizen.org/feature/speech.synthesis
1192 /// <exception cref="InvalidOperationException">
1193 /// This exception can be due to the following reasons:
1194 /// 1. Invalid State
1195 /// 2. Operation Failure
1196 /// 3. Screen reader off
1198 /// <exception cref="NotSupportedException">This exception can be due to TTS not supported.</exception>
1200 /// The Client must be in the <see cref="State.Playing"/> state.
1203 /// If this function succeeds, the Client will be in the <see cref="State.Paused"/> state.
1207 TtsError error = TtsPause(_handle);
1208 if (error != TtsError.None)
1210 Log.Error(LogTag, "Pause Failed with error " + error);
1211 throw ExceptionFactory.CreateException(error);
1216 /// Repeats the last added text.
1218 /// <since_tizen> 10 </since_tizen>
1220 /// The RepeatedText instance which stores the text to repeat and its utterance ID.
1223 /// http://tizen.org/feature/speech.synthesis
1225 /// <exception cref="InvalidOperationException">
1226 /// This exception can be due to the following reasons:
1227 /// 1. Invalid State
1228 /// 2. Operation Failure
1229 /// 3. Screen reader off
1231 /// <exception cref="NotSupportedException">This exception can be due to TTS not supported.</exception>
1233 /// The Client must be in the <see cref="State.Ready"/> state.
1236 /// If this function succeeds, the Client will be in the <see cref="State.Playing"/> state.
1238 public RepeatedText Repeat()
1240 TtsError error = TtsRepeat(_handle, out string text, out int uttId);
1241 if (error != TtsError.None)
1243 Log.Error(LogTag, "Repeat Failed with error " + error);
1244 throw ExceptionFactory.CreateException(error);
1247 return new RepeatedText(text, uttId);
1251 /// Method to release resources.
1253 /// <since_tizen> 3 </since_tizen>
1254 public void Dispose()
1257 GC.SuppressFinalize(this);
1261 /// Method to release resources.
1263 /// <since_tizen> 3 </since_tizen>
1264 /// <param name="disposing">
1265 /// The boolean value for destoying tts handle.
1267 protected virtual void Dispose(bool disposing)
1271 if (_handle != IntPtr.Zero)
1273 TtsError error = TtsDestroy(_handle);
1274 if (error != TtsError.None)
1276 Log.Error(LogTag, "Destroy Failed with error " + error);
1278 _handle = IntPtr.Zero;
1281 disposedValue = true;