Fix API reference
[platform/core/csapi/uix-tts.git] / Tizen.Uix.Tts / Tizen.Uix.Tts / TtsClient.cs
1 /*
2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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.Collections.Generic;
20 using System.Runtime.InteropServices;
21 using static Interop.Tts;
22
23 namespace Tizen.Uix.Tts
24 {
25     /// <summary>
26     /// Enumeration for States
27     /// </summary>
28     public enum State
29     {
30         /// <summary>
31         /// Created atate
32         /// </summary>
33         Created = 0,
34
35         /// <summary>
36         /// Ready state
37         /// </summary>
38         Ready = 1,
39
40         /// <summary>
41         /// Playing state
42         /// </summary>
43         Playing = 2,
44
45         /// <summary>
46         /// Paused state
47         /// </summary>
48         Paused = 3,
49
50         /// <summary>
51         /// state Unavailable
52         /// </summary>
53         Unavailable
54     };
55
56     /// <summary>
57     /// Enumeration for TTS mode.
58     /// </summary>
59     public enum Mode
60     {
61         /// <summary>
62         /// Default mode for normal application
63         /// </summary>
64         Default = 0,
65
66         /// <summary>
67         /// Notification mode
68         /// </summary>
69         Notification = 1,
70
71         /// <summary>
72         /// Accessibiliity mode
73         /// </summary>
74         ScreenReader = 2
75     };
76
77     /// <summary>
78     /// Enum for Error values that can occur
79     /// </summary>
80     public enum Error
81     {
82         /// <summary>
83         /// Successful, No error
84         /// </summary>
85         None,
86         /// <summary>
87         /// Out of Memory
88         /// </summary>
89         OutOfMemory,
90         /// <summary>
91         /// I/O error
92         /// </summary>
93         IoError,
94         /// <summary>
95         /// Invalid parameter
96         /// </summary>
97         InvalidParameter,
98         /// <summary>
99         /// No answer from the STT service
100         /// </summary>
101         TimedOut,
102         /// <summary>
103         /// Network is down
104         /// </summary>
105         OutOfNetwork,
106         /// <summary>
107         /// Permission denied
108         /// </summary>
109         PermissionDenied,
110         /// <summary>
111         /// STT NOT supported
112         /// </summary>
113         NotSupported,
114         /// <summary>
115         /// Invalid state
116         /// </summary>
117         InvalidState,
118         /// <summary>
119         /// Invalid Voice
120         /// </summary>
121         InvalidVoice,
122         /// <summary>
123         /// No available engine
124         /// </summary>
125         EngineNotFound,
126         /// <summary>
127         /// Operation failed
128         /// </summary>
129         OperationFailed,
130         /// <summary>
131         /// Audio policy blocked
132         /// </summary>
133         AudioPolicyBlocked
134     };
135
136     /// <summary>
137     /// Enumeration for Voice Types
138     /// </summary>
139     public enum Voice
140     {
141         /// <summary>
142         /// Automatic Voice Type
143         /// </summary>
144         Auto,
145
146         /// <summary>
147         /// Male Voice
148         /// </summary>
149         Male,
150
151         /// <summary>
152         /// Female Voice
153         /// </summary>
154         Female,
155
156         /// <summary>
157         /// Child Voice Type
158         /// </summary>
159         Child
160     };
161
162     /// <summary>
163     /// You can use Text-To-Speech (TTS) API's to read sound data transformed by the engine from input texts.
164     /// 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.
165     /// </summary>
166     public class TtsClient : IDisposable
167     {
168         private IntPtr _handle;
169         private event EventHandler<StateChangedEventArgs> _stateChanged;
170         private event EventHandler<UtteranceEventArgs> _utteranceStarted;
171         private event EventHandler<UtteranceEventArgs> _utteranceCompleted;
172         private event EventHandler<ErrorOccuredEventArgs> _errorOccured;
173         private event EventHandler<DefaultVoiceChangedEventArgs> _defaultVoiceChanged;
174         private event EventHandler<EngineChangedEventArgs> _engineChanged;
175         private bool disposedValue = false;
176         private Object thisLock = new Object();
177         private TtsStateChangedCB _stateDelegate;
178         private TtsUtteranceStartedCB _utteranceStartedResultDelegate;
179         private TtsUtteranceCompletedCB _utteranceCompletedResultDelegate;
180         private TtsErrorCB _errorDelegate;
181         private TtsDefaultVoiceChangedCB _voiceChangedDelegate;
182         private TtsEngineChangedCB _engineDelegate;
183         private TtsSupportedVoiceCB _supportedvoiceDelegate;
184
185         /// <summary>
186         /// Constructor to create a TTS instance.
187         /// </summary>
188         /// <feature>
189         /// http://tizen.org/feature/speech.synthesis
190         /// </feature>
191         /// <exception cref="InvalidOperationException">
192         /// This Exception can be due to the following reaons
193         /// 1. Out Of Memory
194         /// 2. Operation Failed
195         /// 3. TTS Not Supported
196         /// 4. Engine Not Found
197         /// </exception>
198         public TtsClient()
199         {
200             IntPtr handle;
201             TtsError error = TtsCreate(out handle);
202             if (error != TtsError.None)
203             {
204                 Log.Error(LogTag, "Create Failed with error " + error);
205                 throw ExceptionFactory.CreateException(error);
206             }
207
208             _handle = handle;
209         }
210
211         /// <summary>
212         /// Event to be invoked when TTS state changes.
213         /// </summary>
214         public event EventHandler<StateChangedEventArgs> StateChanged
215         {
216             add
217             {
218                 lock (thisLock)
219                 {
220                     _stateDelegate = (IntPtr handle, State previous, State current, IntPtr userData) =>
221                 {
222                     StateChangedEventArgs args = new StateChangedEventArgs(previous, current);
223                     _stateChanged?.Invoke(this, args);
224                 };
225                     TtsError error = TtsSetStateChangedCB(_handle, _stateDelegate, IntPtr.Zero);
226                     if (error != TtsError.None)
227                     {
228                         Log.Error(LogTag, "Add StateChanged Failed with error " + error);
229                     }
230                     else
231                     {
232                         _stateChanged += value;
233                     }
234                 }
235
236             }
237
238             remove
239             {
240                 lock (thisLock)
241                 {
242                     TtsError error = TtsUnsetStateChangedCB(_handle);
243                     if (error != TtsError.None)
244                     {
245                         Log.Error(LogTag, "Remove StateChanged Failed with error " + error);
246                     }
247
248                     _stateChanged -= value;
249                 }
250             }
251
252         }
253
254         /// <summary>
255         /// Event to be invoked when the utterance starts.
256         /// </summary>
257         public event EventHandler<UtteranceEventArgs> UtteranceStarted
258         {
259             add
260             {
261                 lock (thisLock)
262                 {
263                     _utteranceStartedResultDelegate = (IntPtr handle, int uttId, IntPtr userData) =>
264                 {
265                     UtteranceEventArgs args = new UtteranceEventArgs(uttId);
266                     _utteranceStarted?.Invoke(this, args);
267                 };
268                     TtsError error = TtsSetUtteranceStartedCB(_handle, _utteranceStartedResultDelegate, IntPtr.Zero);
269                     if (error != TtsError.None)
270                     {
271                         Log.Error(LogTag, "Add UtteranceStarted Failed with error " + error);
272                     }
273                     else
274                     {
275                         _utteranceStarted += value;
276                     }
277                 }
278             }
279
280             remove
281             {
282                 lock (thisLock)
283                 {
284                     TtsError error = TtsUnsetUtteranceStartedCB(_handle);
285                     if (error != TtsError.None)
286                     {
287                         Log.Error(LogTag, "Remove UtteranceStarted Failed with error " + error);
288                     }
289
290                     _utteranceStarted -= value;
291                 }
292             }
293         }
294
295         /// <summary>
296         /// Event to be invoked when the utterance completes.
297         /// </summary>
298         public event EventHandler<UtteranceEventArgs> UtteranceCompleted
299         {
300             add
301             {
302                 lock (thisLock)
303                 {
304                     _utteranceCompletedResultDelegate = (IntPtr handle, int uttId, IntPtr userData) =>
305                 {
306                     UtteranceEventArgs args = new UtteranceEventArgs(uttId);
307                     _utteranceCompleted?.Invoke(this, args);
308                 };
309                     TtsError error = TtsSetUtteranceCompletedCB(_handle, _utteranceCompletedResultDelegate, IntPtr.Zero);
310                     if (error != TtsError.None)
311                     {
312                         Log.Error(LogTag, "Add UtteranceCompleted Failed with error " + error);
313                     }
314                     else
315                     {
316                         _utteranceCompleted += value;
317                     }
318                 }
319             }
320
321             remove
322             {
323                 lock (thisLock)
324                 {
325                     TtsError error = TtsUnsetUtteranceCompletedCB(_handle);
326                     if (error != TtsError.None)
327                     {
328                         Log.Error(LogTag, "Remove UtteranceCompleted Failed with error " + error);
329                     }
330
331                     _utteranceCompleted -= value;
332                 }
333             }
334         }
335
336         /// <summary>
337         /// Event to be invoked when an error occurs.
338         /// </summary>
339         public event EventHandler<ErrorOccuredEventArgs> ErrorOccured
340         {
341             add
342             {
343                 lock (thisLock)
344                 {
345                     _errorDelegate = (IntPtr handle, int uttId, TtsError reason, IntPtr userData) =>
346                 {
347                     ErrorOccuredEventArgs args = new ErrorOccuredEventArgs(handle, uttId, reason);
348                     _errorOccured?.Invoke(this, args);
349                 };
350                     TtsError error = TtsSetErrorCB(_handle, _errorDelegate, IntPtr.Zero);
351                     if (error != TtsError.None)
352                     {
353                         Log.Error(LogTag, "Add ErrorOccured Failed with error " + error);
354                     }
355
356                     else
357                     {
358                         _errorOccured += value;
359                     }
360                 }
361             }
362
363             remove
364             {
365                 lock (thisLock)
366                 {
367                     TtsError error = TtsUnsetErrorCB(_handle);
368                     if (error != TtsError.None)
369                     {
370                         Log.Error(LogTag, "Remove ErrorOccured Failed with error " + error);
371                     }
372
373                     _errorOccured -= value;
374                 }
375             }
376         }
377
378         /// <summary>
379         /// Event to be invoked when an error occurs.
380         /// </summary>
381         public event EventHandler<DefaultVoiceChangedEventArgs> DefaultVoiceChanged
382         {
383             add
384             {
385                 lock (thisLock)
386                 {
387                     _voiceChangedDelegate = (IntPtr handle, IntPtr previousLanguage, int previousVoiceType, IntPtr currentLanguage, int currentVoiceType, IntPtr userData) =>
388                 {
389                     string previousLanguageString = Marshal.PtrToStringAnsi(previousLanguage);
390                     string currentLanguageString = Marshal.PtrToStringAnsi(currentLanguage);
391                     DefaultVoiceChangedEventArgs args = new DefaultVoiceChangedEventArgs(previousLanguageString, previousVoiceType, currentLanguageString, currentVoiceType);
392                     _defaultVoiceChanged?.Invoke(this, args);
393                 };
394                     TtsError error = TtsSetDefaultVoiceChangedCB(_handle, _voiceChangedDelegate, IntPtr.Zero);
395                     if (error != TtsError.None)
396                     {
397                         Log.Error(LogTag, "Add DefaultVoiceChanged Failed with error " + error);
398                     }
399
400                     else
401                     {
402                         _defaultVoiceChanged += value;
403                     }
404                 }
405
406             }
407
408             remove
409             {
410                 lock (thisLock)
411                 {
412                     TtsError error = TtsUnsetDefaultVoiceChangedCB(_handle);
413                     if (error != TtsError.None)
414                     {
415                         Log.Error(LogTag, "Remove DefaultVoiceChanged Failed with error " + error);
416                     }
417
418                     _defaultVoiceChanged -= value;
419                 }
420             }
421         }
422
423         /// <summary>
424         /// Event to be invoked to detect engine change.
425         /// </summary>
426         public event EventHandler<EngineChangedEventArgs> EngineChanged
427         {
428             add
429             {
430                 lock (thisLock)
431                 {
432                     _engineDelegate = (IntPtr handle, IntPtr engineId, IntPtr language, int voiceType, bool needCredential, IntPtr userData) =>
433                 {
434                     string engineIdString = Marshal.PtrToStringAnsi(engineId);
435                     string languageString = Marshal.PtrToStringAnsi(language);
436                     EngineChangedEventArgs args = new EngineChangedEventArgs(engineIdString, languageString, voiceType, needCredential);
437                     _engineChanged?.Invoke(this, args);
438                 };
439                     TtsError error = TtsSetEngineChangedCB(_handle, _engineDelegate, IntPtr.Zero);
440                     if (error != TtsError.None)
441                     {
442                         Log.Error(LogTag, "Add EngineChanged Failed with error " + error);
443                     }
444                     else
445                     {
446                         _engineChanged += value;
447                     }
448                 }
449             }
450
451             remove
452             {
453                 lock (thisLock)
454                 {
455                     TtsError error = TtsUnsetEngineChangedCB(_handle);
456                     if (error != TtsError.None)
457                     {
458                         Log.Error(LogTag, "Remove EngineChanged Failed with error " + error);
459                     }
460
461                     _engineChanged -= value;
462                 }
463             }
464         }
465
466         /// <summary>
467         /// Gets the default voice set by the user.
468         /// </summary>
469         /// <value>
470         /// Default voice in TTS
471         /// </value>
472         /// <returns>
473         /// Default Voice SupportedVoice value.
474         /// </returns>
475         public SupportedVoice DefaultVoice
476         {
477             get
478             {
479                 lock (thisLock)
480                 {
481                     string language;
482                     int voiceType;
483                     TtsError error = TtsGetDefaultVoice(_handle, out language, out voiceType);
484                     if (error != TtsError.None)
485                     {
486                         Log.Error(LogTag, "DefaultVoice Failed with error " + error);
487                         return new SupportedVoice();
488                     }
489
490                     return new SupportedVoice(language, voiceType);
491                 }
492             }
493         }
494
495         /// <summary>
496         /// Gets the maximum byte size for text.
497         /// </summary>
498         /// <value>
499         /// Maximum byte size for text
500         /// </value>
501         /// <returns>
502         /// Default Voice SupportedVoice value, 0 if unable to get the value
503         /// </returns>
504         /// <pre>
505         /// The State should be Ready
506         /// </pre>
507         public uint GetMaxTextSize
508         {
509             get
510             {
511                 uint maxTextSize;
512                 lock (thisLock)
513                 {
514                     TtsError error = TtsGetMaxTextSize(_handle, out maxTextSize);
515                     if (error != TtsError.None)
516                     {
517                         Log.Error(LogTag, "MaxTextSize Failed with error " + error);
518                         return 0;
519                     }
520
521                 }
522
523                 return maxTextSize;
524             }
525
526         }
527
528         /// <summary>
529         /// Gets the current TTS state.
530         /// </summary>
531         /// <value>
532         /// Current state of TTS
533         /// </value>
534         /// <returns>
535         /// Current TTS State value.
536         /// </returns>
537         public State GetState
538         {
539             get
540             {
541                 State state;
542                 lock (thisLock)
543                 {
544                     TtsError error = TtsGetState(_handle, out state);
545                     if (error != TtsError.None)
546                     {
547                         Log.Error(LogTag, "CurrentState Failed with error " + error);
548                         return State.Unavailable;
549                     }
550
551                 }
552
553                 return state;
554             }
555
556         }
557
558         /// <summary>
559         /// The TTS Mode can be set using this property
560         /// </summary>
561         /// <value>
562         /// Current mode of TTS (default, screen-reader, notification)
563         /// </value>
564         /// <returns>
565         /// The Mode value
566         /// </returns>
567         /// <exception cref="InvalidOperationException">
568         /// This Exception can be due to the following reaons while setting the value
569         /// 1. Out Of Memory
570         /// 2. Operation Failed
571         /// 3. TTS Not Supported
572         /// 4. Engine Not Found
573         /// </exception>
574         /// <pre>
575         /// State should be Created
576         /// </pre>
577         public Mode CurrentMode
578         {
579             get
580             {
581                 Mode mode = Mode.Default;
582                 lock (thisLock)
583                 {
584                     TtsError error = TtsGetMode(_handle, out mode);
585                     if (error != TtsError.None)
586                     {
587                         Log.Error(LogTag, "Get Mode Failed with error " + error);
588                         return Mode.Default;
589                     }
590                 }
591
592                 return mode;
593             }
594             set
595             {
596                 TtsError error;
597                 lock (thisLock)
598                 {
599                     error = TtsSetMode(_handle, value);
600                 }
601
602                 if (error != TtsError.None)
603                 {
604                     Log.Error(LogTag, "Set Mode Failed with error " + error);
605                     throw ExceptionFactory.CreateException(error);
606                 }
607             }
608         }
609
610         /// <summary>
611         /// Sets the app credential
612         /// </summary>
613         /// <param name="credential">
614         /// The credential string
615         /// </param>
616         /// <feature>
617         /// http://tizen.org/feature/speech.synthesis
618         /// </feature>
619         /// <exception cref="InvalidOperationException">
620         /// This Exception can be due to the following reaons
621         /// 1. TTS Not Supported
622         /// 2. Invalid State
623         /// </exception>
624         /// <exception cref="ArgumentException">
625         /// This can happen if Improper value is provided while setting the value.
626         /// </exception>
627         /// <pre>
628         /// The State must be Created or Ready.
629         /// </pre>
630         public void SetCredential(string credential)
631         {
632             lock (thisLock)
633             {
634                 TtsError error = TtsSetCredential(_handle, credential);
635                 if (error != TtsError.None)
636                 {
637                     Tizen.Log.Error(LogTag, "SetCredential Failed with error " + error);
638                     throw ExceptionFactory.CreateException(error);
639                 }
640             }
641         }
642
643         /// <summary>
644         /// Connects to the TTS service asynchronously.
645         /// </summary>
646         /// <feature>
647         /// http://tizen.org/feature/speech.synthesis
648         /// </feature>
649         /// <exception cref="InvalidOperationException">
650         /// This Exception can be due to the following reasons
651         /// 1. TTS Not Supported
652         /// 2. Invalid State
653         /// </exception>
654         /// <pre>
655         /// The State must be Created.
656         /// </pre>
657         /// <post>
658         /// If this function is successful, the TTS state will be Ready
659         /// If this function is unsuccessful, ErrorOccured event will be invoked
660         /// </post>
661         public void Prepare()
662         {
663             lock (thisLock)
664             {
665                 TtsError error = TtsPrepare(_handle);
666                 if (error != TtsError.None)
667                 {
668                     Log.Error(LogTag, "Prepare Failed with error " + error);
669                     throw ExceptionFactory.CreateException(error);
670                 }
671             }
672         }
673
674         /// <summary>
675         /// Disconnects from the STT service.
676         /// </summary>
677         /// <feature>
678         /// http://tizen.org/feature/speech.synthesis
679         /// </feature>
680         /// <exception cref="InvalidOperationException">
681         /// This Exception can be due to the following reasons
682         /// 1. TTS Not Supported
683         /// 2. Invalid State
684         /// </exception>
685         /// <pre>
686         /// The State must be Ready.
687         /// </pre>
688         /// <post>
689         /// If this function is successful, the TTS state will be Created
690         /// </post>
691         public void Unprepare()
692         {
693             lock (thisLock)
694             {
695                 TtsError error = TtsUnprepare(_handle);
696                 if (error != TtsError.None)
697                 {
698                     Log.Error(LogTag, "Unprepare Failed with error " + error);
699                     throw ExceptionFactory.CreateException(error);
700                 }
701             }
702         }
703
704         /// <summary>
705         /// Retrieves all supported voices of the current engine.
706         /// </summary>
707         /// <returns>
708         /// list of SupportedVoice.
709         /// </returns>
710         /// <feature>
711         /// http://tizen.org/feature/speech.synthesis
712         /// </feature>
713         /// <exception cref="InvalidOperationException">
714         /// This Exception can be due to the following reasons
715         /// 1. TTS Not Supported
716         /// 2. Engine Not Found.
717         /// 3. Operation Failed.
718         /// </exception>
719         public IEnumerable<SupportedVoice> GetSupportedVoices()
720         {
721             List<SupportedVoice> voicesList = new List<SupportedVoice>();
722             lock (thisLock)
723             {
724                _supportedvoiceDelegate = (IntPtr handle, IntPtr language, int voiceType, IntPtr userData) =>
725             {
726                 string lang = Marshal.PtrToStringAnsi(language);
727                 SupportedVoice voice = new SupportedVoice(lang, voiceType);
728                 voicesList.Add(voice);
729                 return true;
730             };
731                 TtsError error = TtsForeachSupportedVoices(_handle, _supportedvoiceDelegate, IntPtr.Zero);
732                 if (error != TtsError.None)
733                 {
734                     Log.Error(LogTag, "GetSupportedVoices Failed with error " + error);
735                     throw ExceptionFactory.CreateException(error);
736                 }
737
738             }
739
740             return voicesList;
741         }
742
743         /// <summary>
744         /// Gets the private data from tts engine.
745         /// </summary>
746         /// <param name="key">
747         /// The key string
748         /// </param>
749         /// <returns>
750         /// The Data Corresponding to the Key provided
751         /// </returns>
752         /// <feature>
753         /// http://tizen.org/feature/speech.synthesis
754         /// </feature>
755         /// <exception cref="InvalidOperationException">
756         /// This Exception can be due to the following reaons
757         /// 1. TTS Not Supported
758         /// 2. Invalid State
759         /// 3. Engine Not found
760         /// 4. Operation Failure
761         /// </exception>
762         /// <pre>
763         /// The State must be Ready.
764         /// </pre>
765         public string GetPrivateData(string key)
766         {
767             string data;
768             lock (thisLock)
769             {
770                 TtsError error = TtsGetPrivateData(_handle, key, out data);
771                 if (error != TtsError.None)
772                 {
773                     Log.Error(LogTag, "GetPrivateData Failed with error " + error);
774                     throw ExceptionFactory.CreateException(error);
775                 }
776
777             }
778
779             return data;
780         }
781
782         /// <summary>
783         /// Sets the private data to tts engine.
784         /// </summary>
785         /// <param name="key">
786         /// The key string
787         /// </param>
788         /// <param name="data">
789         /// The data string
790         /// </param>
791         /// <feature>
792         /// http://tizen.org/feature/speech.synthesis
793         /// </feature>
794         /// <exception cref="InvalidOperationException">
795         /// This Exception can be due to the following reaons
796         /// 1. TTS Not Supported
797         /// 2. Invalid State
798         /// 3. Engine Not found
799         /// 4. Operation Failure
800         /// </exception>
801         /// <exception cref="ArgumentException">
802         /// This can happen if Improper value is provided while setting the value.
803         /// </exception>
804         /// <pre>
805         /// The State must be Ready.
806         /// </pre>
807         public void SetPrivateData(string key, string data)
808         {
809             lock (thisLock)
810             {
811                 TtsError error = TtsSetPrivateData(_handle, key, data);
812                 if (error != TtsError.None)
813                 {
814                     Log.Error(LogTag, "SetPrivateData Failed with error " + error);
815                     throw ExceptionFactory.CreateException(error);
816                 }
817             }
818         }
819
820         /// <summary>
821         /// Gets the speed range.
822         /// </summary>
823         /// <returns>
824         /// The SpeedRange value
825         /// </returns>
826         /// <feature>
827         /// http://tizen.org/feature/speech.synthesis
828         /// </feature>
829         /// <exception cref="InvalidOperationException">
830         /// This Exception can be due to the following reaons
831         /// 1. TTS Not Supported
832         /// 2. Invalid State
833         /// 3. Operation Failure
834         /// </exception>
835         /// <pre>
836         /// The State must be Created.
837         /// </pre>
838         public SpeedRange GetSpeedRange()
839         {
840             int min = 0, max = 0, normal = 0;
841             lock (thisLock)
842             {
843                 TtsError error = TtsGetSpeedRange(_handle, out min, out normal, out max);
844                 if (error != TtsError.None)
845                 {
846                     Log.Error(LogTag, "GetSpeedRange Failed with error " + error);
847                     throw ExceptionFactory.CreateException(error);
848                 }
849
850             }
851
852             return new SpeedRange(min, normal, max);
853         }
854
855         /// <summary>
856         /// Adds a text to the queue.
857         /// </summary>
858         /// <remarks>
859         /// Locale MUST be set for utf8 text validation check.
860         /// </remarks>
861         /// <param name="text">
862         /// An input text based utf8
863         /// </param>
864         /// <param name="language">
865         /// The language selected from the SupportedVoice.Language Property obtained from GetSupportedVoices() (e.g. 'NULL'(Automatic), 'en_US')
866         /// </param>
867         /// <param name="voiceType">
868         /// The voice type selected from the SupportedVoice.VoiceType Property obtained from GetSupportedVoices()
869         /// </param>
870         /// <param name="speed">
871         /// A speaking speed (e.g.0 for Auto or the value from SpeedRange Property)
872         /// </param>
873         /// <returns>
874         /// The utterance ID.
875         /// </returns>
876         /// <feature>
877         /// http://tizen.org/feature/speech.synthesis
878         /// </feature>
879         /// <exception cref="InvalidOperationException">
880         /// This Exception can be due to the following reaons
881         /// 1. TTS Not Supported
882         /// 2. Invalid State
883         /// 3. Operation Failure
884         /// 4. Invalid Voice
885         /// 5. Permission Denied
886         /// </exception>
887         /// <exception cref="ArgumentException">
888         /// This can happen if Improper value is provided.
889         /// </exception>
890         /// <pre>
891         /// The State must be Ready or Playing or Paused.
892         /// </pre>
893         public int AddText(string text, string language, int voiceType, int speed)
894         {
895             int id;
896             lock (thisLock)
897             {
898                 TtsError error = TtsAddText(_handle, text, language, voiceType, speed, out id);
899                 if (error != TtsError.None)
900                 {
901                     Log.Error(LogTag, "AddText Failed with error " + error);
902                     throw ExceptionFactory.CreateException(error);
903                 }
904
905             }
906
907             return id;
908         }
909
910         /// <summary>
911         /// Starts synthesizing voice from the text and plays the synthesized audio data.
912         /// </summary>
913         /// <feature>
914         /// http://tizen.org/feature/speech.synthesis
915         /// </feature>
916         /// <exception cref="InvalidOperationException">
917         /// This Exception can be due to the following reaons
918         /// 1. TTS Not Supported
919         /// 2. Invalid State
920         /// 3. Operation Failure
921         /// 4. Out of Network
922         /// 5. Permission Denied
923         /// </exception>
924         /// <pre>
925         /// The State must be Ready or Paused.
926         /// </pre>
927         /// <post>
928         /// If this function succeeds, the TTS state will be Playing.
929         /// </post>
930         public void Play()
931         {
932             lock (thisLock)
933             {
934                 TtsError error = TtsPlay(_handle);
935                 if (error != TtsError.None)
936                 {
937                     Log.Error(LogTag, "Play Failed with error " + error);
938                     throw ExceptionFactory.CreateException(error);
939                 }
940             }
941         }
942
943         /// <summary>
944         /// Stops playing the utterance and clears the queue.
945         /// </summary>
946         /// <feature>
947         /// http://tizen.org/feature/speech.synthesis
948         /// </feature>
949         /// <exception cref="InvalidOperationException">
950         /// This Exception can be due to the following reaons
951         /// 1. TTS Not Supported
952         /// 2. Invalid State
953         /// 3. Operation Failure
954         /// </exception>
955         /// <pre>
956         /// The State must be Ready or Playing or Paused.
957         /// </pre>
958         /// <post>
959         /// If this function succeeds, the TTS state will be Ready.
960         /// This function will remove all text added via AddText() and synthesized sound data.
961         /// </post>
962         public void Stop()
963         {
964             lock (thisLock)
965             {
966                 TtsError error = TtsStop(_handle);
967                 if (error != TtsError.None)
968                 {
969                     Log.Error(LogTag, "Stop Failed with error " + error);
970                     throw ExceptionFactory.CreateException(error);
971                 }
972             }
973         }
974
975         /// <summary>
976         /// Pauses the currently playing utterance.
977         /// </summary>
978         /// <feature>
979         /// http://tizen.org/feature/speech.synthesis
980         /// </feature>
981         /// <exception cref="InvalidOperationException">
982         /// This Exception can be due to the following reaons
983         /// 1. TTS Not Supported
984         /// 2. Invalid State
985         /// 3. Operation Failure
986         /// </exception>
987         /// <pre>
988         /// The State must be Playing.
989         /// </pre>
990         /// <post>
991         /// If this function succeeds, the TTS state will be Paused.
992         /// </post>
993         public void Pause()
994         {
995             lock (thisLock)
996             {
997                 TtsError error = TtsPause(_handle);
998                 if (error != TtsError.None)
999                 {
1000                     Log.Error(LogTag, "Pause Failed with error " + error);
1001                     throw ExceptionFactory.CreateException(error);
1002                 }
1003             }
1004         }
1005
1006         /// <summary>
1007         /// Method to release resources
1008         /// </summary>
1009         public void Dispose()
1010         {
1011             Dispose(true);
1012         }
1013
1014         protected virtual void Dispose(bool disposing)
1015         {
1016             if (!disposedValue)
1017             {
1018                 if (disposing)
1019                 {
1020                     TtsError error = TtsDestroy(_handle);
1021                     if (error != TtsError.None)
1022                     {
1023                         Log.Error(LogTag, "Destroy Failed with error " + error);
1024                     }
1025                 }
1026
1027                 disposedValue = true;
1028             }
1029         }
1030     }
1031 }