/// <summary> /// Sets the private data to tts engine. /// </summary> /// <since_tizen> 3 </since_tizen> /// <param name="key"> /// The key string. /// </param> /// <param name="data"> /// The data string. /// </param> /// <feature> /// http://tizen.org/feature/speech.synthesis /// </feature> /// <exception cref="InvalidOperationException"> /// This exception can be due to the following reasons: /// 1. Invalid State /// 2. Engine Not found /// 3. Operation Failure /// </exception> /// <exception cref="NotSupportedException">This exception can be due to TTS not supported.</exception> /// <exception cref="ArgumentException">This exception can be due to improper value provided while setting the value.</exception> /// <pre> /// The state must be ready. /// </pre> public void SetPrivateData(string key, string data) { TtsError error = TtsSetPrivateData(_handle, key, data); if (error != TtsError.None) { Log.Error(LogTag, "SetPrivateData Failed with error " + error); throw ExceptionFactory.CreateException(error); } }
/// <summary> /// Sets the application credential. /// </summary> /// <since_tizen> 3 </since_tizen> /// <param name="credential">. /// The credential string. /// </param> /// <feature> /// http://tizen.org/feature/speech.synthesis /// </feature> /// <exception cref="InvalidOperationException">This exception can be due to an invalid state.</exception> /// <exception cref="NotSupportedException">This exception can be due to TTS not supported.</exception> /// <exception cref="ArgumentException">This exception can be due to improper value provided while setting the value.</exception> /// <pre> /// The State should be created or ready. /// </pre> public void SetCredential(string credential) { TtsError error = TtsSetCredential(_handle, credential); if (error != TtsError.None) { Tizen.Log.Error(LogTag, "SetCredential Failed with error " + error); throw ExceptionFactory.CreateException(error); } }
/// <summary> /// Disconnects from the STT service. /// </summary> /// <since_tizen> 3 </since_tizen> /// <feature> /// http://tizen.org/feature/speech.synthesis /// </feature> /// <exception cref="InvalidOperationException">This exception can be due to an invalid state.</exception> /// <exception cref="NotSupportedException">This exception can be due to TTS not supported.</exception> /// <pre> /// The state must be ready. /// </pre> /// <post> /// If this function is successful, the TTS state will be created. /// </post> public void Unprepare() { TtsError error = TtsUnprepare(_handle); if (error != TtsError.None) { Log.Error(LogTag, "Unprepare Failed with error " + error); throw ExceptionFactory.CreateException(error); } }
/// <summary> /// Stops playing the utterance and clears the queue. /// </summary> /// <since_tizen> 3 </since_tizen> /// <feature> /// http://tizen.org/feature/speech.synthesis /// </feature> /// <exception cref="InvalidOperationException"> /// This exception can be due to the following reasons: /// 1. Invalid Stat /// 2. Operation Failure /// </exception> /// <exception cref="NotSupportedException">This exception can be due to TTS not supported.</exception> /// <pre> /// The state must be ready or playing or paused. /// </pre> /// <post> /// If this function succeeds, the TTS state will be ready. /// This function will remove all text added via AddText() and synthesized sound data. /// </post> public void Stop() { TtsError error = TtsStop(_handle); if (error != TtsError.None) { Log.Error(LogTag, "Stop Failed with error " + error); throw ExceptionFactory.CreateException(error); } }
/// <summary> /// Starts synthesizing voice from the text and plays the synthesized audio data. /// </summary> /// <since_tizen> 3 </since_tizen> /// <feature> /// http://tizen.org/feature/speech.synthesis /// </feature> /// <exception cref="InvalidOperationException"> /// This exception can be due to the following reasons: /// 1. Invalid State /// 2. Operation Failure /// 3. Out of Network /// </exception> /// <exception cref="NotSupportedException">This exception can be due to TTS not supported.</exception> /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception> /// <pre> /// The state must be ready or paused. /// </pre> /// <post> /// If this function succeeds, the TTS state will be playing. /// </post> public void Play() { lock (thisLock) { TtsError error = TtsPlay(_handle); if (error != TtsError.None) { Log.Error(LogTag, "Play Failed with error " + error); throw ExceptionFactory.CreateException(error); } } }
/// <summary> /// Repeats the last added text. /// </summary> /// <since_tizen> 10 </since_tizen> /// <returns> /// The RepeatedText instance which stores the text to repeat and its utterance ID. /// </returns> /// <feature> /// http://tizen.org/feature/speech.synthesis /// </feature> /// <exception cref="InvalidOperationException"> /// This exception can be due to the following reasons: /// 1. Invalid State /// 2. Operation Failure /// 3. Screen reader off /// </exception> /// <exception cref="NotSupportedException">This exception can be due to TTS not supported.</exception> /// <pre> /// The Client must be in the <see cref="State.Ready"/> state. /// </pre> /// <post> /// If this function succeeds, the Client will be in the <see cref="State.Playing"/> state. /// </post> public RepeatedText Repeat() { TtsError error = TtsRepeat(_handle, out string text, out int uttId); if (error != TtsError.None) { Log.Error(LogTag, "Repeat Failed with error " + error); throw ExceptionFactory.CreateException(error); } return(new RepeatedText(text, uttId)); }
/// <summary> /// Adds a text to the queue. /// </summary> /// <since_tizen> 3 </since_tizen> /// <remarks> /// Locale MUST be set for UTF-8 text validation check. /// </remarks> /// <param name="text"> /// An input text based UTF-8. /// </param> /// <param name="language"> /// The language selected from the SupportedVoice.Language Property obtained from GetSupportedVoices()(e.g. 'NULL'(Automatic),'en_US'). /// </param> /// <param name="voiceType"> /// The voice type selected from the SupportedVoice.VoiceType Property obtained from GetSupportedVoices(). /// </param> /// <param name="speed"> /// A speaking speed (e.g.0 for Auto or the value from SpeedRange Property). /// </param> /// <returns> /// The utterance ID. /// </returns> /// <feature> /// http://tizen.org/feature/speech.synthesis /// </feature> /// <exception cref="InvalidOperationException"> /// This exception can be due to the following reasons: /// 1. Invalid State /// 2. Operation Failure /// 3. Invalid Voice /// </exception> /// <exception cref="NotSupportedException">This exception can be due to TTS not supported.</exception> /// <exception cref="UnauthorizedAccessException">This exception can be due to permission denied.</exception> /// <exception cref="ArgumentException">This exception can be due to improper value provided while setting the value.</exception> /// <pre> /// The state must be ready or playing or paused. /// </pre> public int AddText(string text, string language, int voiceType, int speed) { int id; TtsError error = TtsAddText(_handle, text, language, voiceType, speed, out id); if (error != TtsError.None) { Log.Error(LogTag, "AddText Failed with error " + error); throw ExceptionFactory.CreateException(error); } return(id); }
/// <summary> /// Gets the speed range. /// </summary> /// <since_tizen> 3 </since_tizen> /// <returns> /// The SpeedRange value. /// </returns> /// <feature> /// http://tizen.org/feature/speech.synthesis /// </feature> /// <exception cref="InvalidOperationException"> /// This exception can be due to the following reasons: /// 1. Invalid State /// 2. Operation Failure /// </exception> /// <exception cref="NotSupportedException">This exception can be due to TTS not supported.</exception> /// <pre> /// The state must be created. /// </pre> public SpeedRange GetSpeedRange() { int min = 0, max = 0, normal = 0; TtsError error = TtsGetSpeedRange(_handle, out min, out normal, out max); if (error != TtsError.None) { Log.Error(LogTag, "GetSpeedRange Failed with error " + error); throw ExceptionFactory.CreateException(error); } return(new SpeedRange(min, normal, max)); }
/// <summary> /// Gets the private data from TTS engine. /// </summary> /// <since_tizen> 3 </since_tizen> /// <param name="key"> /// The key string. /// </param> /// <returns> /// The data corresponding to the provided key. /// </returns> /// <feature> /// http://tizen.org/feature/speech.synthesis /// </feature> /// <exception cref="InvalidOperationException"> /// This exception can be due to the following reasons: /// 1. Invalid State /// 2. Engine Not found /// 3. Operation Failure /// </exception> /// <exception cref="NotSupportedException">This exception can be due to TTS not supported.</exception> /// <pre> /// The state must be ready. /// </pre> public string GetPrivateData(string key) { string data; TtsError error = TtsGetPrivateData(_handle, key, out data); if (error != TtsError.None) { Log.Error(LogTag, "GetPrivateData Failed with error " + error); throw ExceptionFactory.CreateException(error); } return(data); }
/// <summary> /// Constructor to create a TTS instance. /// </summary> /// <since_tizen> 3 </since_tizen> /// <feature> /// http://tizen.org/feature/speech.synthesis /// </feature> /// <exception cref="InvalidOperationException"> /// This exception can be due to the following reasons: /// 1. Operation Failed /// 2. Engine Not Found /// </exception> /// <exception cref="OutOfMemoryException">This exception can be due to out Of memory.</exception> /// <exception cref="NotSupportedException">This exception can be due to TTS not supported.</exception> public TtsClient() { IntPtr handle; TtsError error = TtsCreate(out handle); if (error != TtsError.None) { Log.Error(LogTag, "Create Failed with error " + error); throw ExceptionFactory.CreateException(error); } _handle = handle; }
/// <summary> /// Method to release resources. /// </summary> /// <since_tizen> 3 </since_tizen> /// <param name="disposing"> /// The boolean value for destoying tts handle. /// </param> protected virtual void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { TtsError error = TtsDestroy(_handle); if (error != TtsError.None) { Log.Error(LogTag, "Destroy Failed with error " + error); } } disposedValue = true; } }
/// <summary> /// Method to release resources. /// </summary> /// <since_tizen> 3 </since_tizen> /// <param name="disposing"> /// The boolean value for destoying tts handle. /// </param> protected virtual void Dispose(bool disposing) { if (!disposedValue) { lock (thisLock) { if (_handle != IntPtr.Zero) { TtsError error = TtsDestroy(_handle); if (error != TtsError.None) { Log.Error(LogTag, "Destroy Failed with error " + error); } _handle = IntPtr.Zero; } } disposedValue = true; } }
/// <summary> /// Retrieves all supported voices of the current engine. /// </summary> /// <since_tizen> 3 </since_tizen> /// <returns> /// The list of SupportedVoice. /// </returns> /// <feature> /// http://tizen.org/feature/speech.synthesis /// </feature> /// <exception cref="InvalidOperationException"> /// This exception can be due to the following reasons: /// 1. Engine Not Found /// 2. Operation Failed /// </exception> /// <exception cref="NotSupportedException">This exception can be due to TTS not supported.</exception> public IEnumerable <SupportedVoice> GetSupportedVoices() { List <SupportedVoice> voicesList = new List <SupportedVoice>(); _supportedvoiceDelegate = (IntPtr handle, IntPtr language, int voiceType, IntPtr userData) => { string lang = Marshal.PtrToStringAnsi(language); SupportedVoice voice = new SupportedVoice(lang, voiceType); voicesList.Add(voice); return(true); }; TtsError error = TtsForeachSupportedVoices(_handle, _supportedvoiceDelegate, IntPtr.Zero); if (error != TtsError.None) { Log.Error(LogTag, "GetSupportedVoices Failed with error " + error); throw ExceptionFactory.CreateException(error); } return(voicesList); }
internal static Exception CreateException(TtsError err) { Tizen.Log.Error(LogTag, "Error " + err); Exception exp; switch (err) { case TtsError.OutOfMemory: { exp = new OutOfMemoryException("Out Of Memory"); break; } case TtsError.IoError: { exp = new InvalidOperationException("I/O Error Occurred"); break; } case TtsError.InvalidParameter: { exp = new ArgumentException("Invalid Parameters Provided"); break; } case TtsError.TimedOut: { exp = new TimeoutException("No answer from the TTS service"); break; } case TtsError.OutOfNetwork: { exp = new InvalidOperationException("Network is down"); break; } case TtsError.PermissionDenied: { exp = new UnauthorizedAccessException("Permission Denied"); break; } case TtsError.NotSupported: { exp = new NotSupportedException("TTS NOT supported"); break; } case TtsError.InvalidState: { exp = new InvalidOperationException("Invalid state"); break; } case TtsError.InvalidVoice: { exp = new InvalidOperationException("Invalid Voice"); break; } case TtsError.EngineNotFound: { exp = new InvalidOperationException("No available engine"); break; } case TtsError.OperationFailed: { exp = new InvalidOperationException("Operation Failed"); break; } case TtsError.AudioPolicyBlocked: { exp = new InvalidOperationException("AudioPolicyBlocked"); break; } case TtsError.NotSupportedFeature: { exp = new InvalidOperationException("Feature NotSupported"); break; } case TtsError.ServiceReset: { exp = new InvalidOperationException("Service Reset"); break; } default: { exp = new Exception(""); break; } } return(exp); }