();
_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;
}
///
/// Gets the private data from TTS engine.
///
/// 3
///
/// The key string.
///
///
/// The data corresponding to the provided key.
///
///
/// http://tizen.org/feature/speech.synthesis
///
///
/// This exception can be due to the following reasons:
/// 1. Invalid State
/// 2. Engine Not found
/// 3. Operation Failure
///
/// This exception can be due to TTS not supported.
///
/// The Client must be in the state.
///
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;
}
///
/// Sets the private data to tts engine.
///
/// 3
///
/// The key string.
///
///
/// The data string.
///
///
/// http://tizen.org/feature/speech.synthesis
///
///
/// This exception can be due to the following reasons:
/// 1. Invalid State
/// 2. Engine Not found
/// 3. Operation Failure
///
/// This exception can be due to TTS not supported.
/// This exception can be due to improper value provided while setting the value.
///
/// The Client must be in the state.
///
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);
}
}
///
/// Gets the speed range.
///
/// 3
///
/// The SpeedRange value.
///
///
/// http://tizen.org/feature/speech.synthesis
///
///
/// This exception can be due to the following reasons:
/// 1. Invalid State
/// 2. Operation Failure
///
/// This exception can be due to TTS not supported.
///
/// The Client must be in the state.
///
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);
}
///
/// Adds a text to the queue.
///
/// 3
///
/// Locale MUST be set for text validation check.
///
///
/// An input text.
///
///
/// The language selected from the SupportedVoice.Language Property obtained from GetSupportedVoices()(e.g. 'NULL'(Automatic),'en_US').
///
///
/// The voice type selected from the SupportedVoice.VoiceType Property obtained from GetSupportedVoices().
///
///
/// A speaking speed (e.g.0 for Auto or the value from SpeedRange Property).
///
///
/// The utterance ID.
///
///
/// http://tizen.org/feature/speech.synthesis
///
///
/// This exception can be due to the following reasons:
/// 1. Invalid State
/// 2. Operation Failure
/// 3. Invalid Voice
/// 4. Screen reader off
///
/// This exception can be due to TTS not supported.
/// This exception can be due to permission denied.
/// This exception can be due to improper value provided while setting the value.
///
/// The Client must be in the , , or state.
///
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;
}
///
/// Starts synthesizing voice from the text and plays the synthesized audio data.
///
/// 3
///
/// http://tizen.org/feature/speech.synthesis
///
///
/// This exception can be due to the following reasons:
/// 1. Invalid State
/// 2. Operation Failure
/// 3. Out of Network
/// 4. Screen reader off
///
/// This exception can be due to TTS not supported.
/// This exception can be due to permission denied.
///
/// The Client must be in the or state.
///
///
/// If this function succeeds, the Client will be in the state.
///
public void Play()
{
TtsError error = TtsPlay(_handle);
if (error != TtsError.None)
{
Log.Error(LogTag, "Play Failed with error " + error);
throw ExceptionFactory.CreateException(error);
}
}
///
/// Stops playing the utterance and clears the queue.
///
/// 3
///
/// http://tizen.org/feature/speech.synthesis
///
///
/// This exception can be due to the following reasons:
/// 1. Invalid Stat
/// 2. Operation Failure
/// 3. Screen reader off
///
/// This exception can be due to TTS not supported.
///
/// The Client must be in the , , or state.
///
///
/// If this function succeeds, the Client will be in the state.
/// This function will remove all text added via AddText() and synthesized sound data.
///
public void Stop()
{
TtsError error = TtsStop(_handle);
if (error != TtsError.None)
{
Log.Error(LogTag, "Stop Failed with error " + error);
throw ExceptionFactory.CreateException(error);
}
}
///
/// Pauses the currently playing utterance.
///
/// 3
///
/// http://tizen.org/feature/speech.synthesis
///
///
/// This exception can be due to the following reasons:
/// 1. Invalid State
/// 2. Operation Failure
/// 3. Screen reader off
///
/// This exception can be due to TTS not supported.
///
/// The Client must be in the state.
///
///
/// If this function succeeds, the Client will be in the state.
///
public void Pause()
{
TtsError error = TtsPause(_handle);
if (error != TtsError.None)
{
Log.Error(LogTag, "Pause Failed with error " + error);
throw ExceptionFactory.CreateException(error);
}
}
///
/// Repeats the last added text.
///
/// 10
///
/// The RepeatedText instance which stores the text to repeat and its utterance ID.
///
///
/// http://tizen.org/feature/speech.synthesis
///
///
/// This exception can be due to the following reasons:
/// 1. Invalid State
/// 2. Operation Failure
/// 3. Screen reader off
///
/// This exception can be due to TTS not supported.
///
/// The Client must be in the state.
///
///
/// If this function succeeds, the Client will be in the state.
///
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);
}
///
/// Method to release resources.
///
/// 3
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
///
/// Method to release resources.
///
/// 3
///
/// The boolean value for destoying tts handle.
///
protected virtual void Dispose(bool disposing)
{
if (!disposedValue)
{
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;
}
}
}
}