public class SttClient : IDisposable
{
private IntPtr _handle;
- private Object thisLock = new Object();
private event EventHandler<RecognitionResultEventArgs> _recognitionResult;
private event EventHandler<StateChangedEventArgs> _stateChanged;
private event EventHandler<ErrorOccurredEventArgs> _errorOccurred;
private event EventHandler<DefaultLanguageChangedEventArgs> _defaultLanguageChanged;
private event EventHandler<EngineChangedEventArgs> _engineChanged;
private bool disposedValue = false;
+ private readonly Object _recognitionResultLock = new Object();
+ private readonly Object _stateChangedLock = new Object();
+ private readonly Object _errorOccurredLock = new Object();
+ private readonly Object _defaultLanguageChangedLock = new Object();
+ private readonly Object _engineChangedLock = new Object();
private Interop.Stt.RecognitionResultCallback _resultDelegate;
private Interop.Stt.StateChangedCallback _stateDelegate;
private Interop.Stt.ErrorCallback _errorDelegate;
{
add
{
- lock (thisLock)
+ lock (_recognitionResultLock)
{
if (_recognitionResult == null)
{
remove
{
- lock (thisLock)
+ lock (_recognitionResultLock)
{
_recognitionResult -= value;
if (_recognitionResult == null)
{
add
{
- lock (thisLock)
+ lock (_stateChangedLock)
{
if (_stateChanged == null)
{
remove
{
- lock (thisLock)
+ lock (_stateChangedLock)
{
_stateChanged -= value;
if (_stateChanged == null)
}
}
}
-
}
/// <summary>
{
add
{
- lock (thisLock)
+ lock (_errorOccurredLock)
{
if (_errorOccurred == null)
{
remove
{
- lock (thisLock)
+ lock (_errorOccurredLock)
{
_errorOccurred -= value;
if (_errorOccurred == null)
{
add
{
- lock (thisLock)
+ lock (_defaultLanguageChangedLock)
{
if (_defaultLanguageChanged == null)
{
remove
{
- lock (thisLock)
+ lock (_defaultLanguageChangedLock)
{
_defaultLanguageChanged -= value;
if (_defaultLanguageChanged == null)
{
add
{
- lock (thisLock)
+ lock (_engineChangedLock)
{
if (_engineChanged == null)
{
remove
{
- lock (thisLock)
+ lock (_engineChangedLock)
{
_engineChanged -= value;
if (_engineChanged == null)
get
{
string language;
- lock (thisLock)
+ SttError error = SttGetDefaultLanguage(_handle, out language);
+ if (error != SttError.None)
{
- SttError error = SttGetDefaultLanguage(_handle, out language);
- if (error != SttError.None)
- {
- Log.Error(LogTag, "DefaultLanguage Failed with error " + error);
- return "";
- }
+ Log.Error(LogTag, "DefaultLanguage Failed with error " + error);
+ return "";
}
return language;
get
{
float volume;
- lock (thisLock)
+ SttError error = SttGetRecordingVolume(_handle, out volume);
+ if (error != SttError.None)
{
- SttError error = SttGetRecordingVolume(_handle, out volume);
- if (error != SttError.None)
- {
- Log.Error(LogTag, "GetRecordingVolume Failed with error " + error);
- return 0.0f;
- }
+ Log.Error(LogTag, "GetRecordingVolume Failed with error " + error);
+ return 0.0f;
}
return volume;
get
{
State state;
- lock (thisLock)
+ SttError error = SttGetState(_handle, out state);
+ if (error != SttError.None)
{
- SttError error = SttGetState(_handle, out state);
- if (error != SttError.None)
- {
- Log.Error(LogTag, "GetState Failed with error " + error);
- return State.Unavailable;
- }
+ Log.Error(LogTag, "GetState Failed with error " + error);
+ return State.Unavailable;
}
return state;
get
{
string engineId;
- lock (thisLock)
+ SttError error = SttGetEngine(_handle, out engineId);
+ if (error != SttError.None)
{
- SttError error = SttGetEngine(_handle, out engineId);
- if (error != SttError.None)
- {
- Log.Error(LogTag, "Get EngineId Failed with error " + error);
- return "";
- }
+ Log.Error(LogTag, "Get EngineId Failed with error " + error);
+ return "";
}
return engineId;
}
set
{
- lock (thisLock)
+ SttError error = SttSetEngine(_handle, value);
+ if (error != SttError.None)
{
- SttError error = SttSetEngine(_handle, value);
- if (error != SttError.None)
- {
- Log.Error(LogTag, "Set EngineId Failed with error " + error);
- throw ExceptionFactory.CreateException(error);
- }
+ Log.Error(LogTag, "Set EngineId Failed with error " + error);
+ throw ExceptionFactory.CreateException(error);
}
-
}
}
public IEnumerable<ResultTime> GetDetailedResult()
{
List<ResultTime> list = new List<ResultTime>();
- lock (thisLock)
+ _resultTimeDelegate = (IntPtr handle, int index, TimeEvent e, IntPtr text, IntPtr startTime, IntPtr endTime, IntPtr userData) =>
{
- _resultTimeDelegate = (IntPtr handle, int index, TimeEvent e, IntPtr text, IntPtr startTime, IntPtr endTime, IntPtr userData) =>
- {
- _result = new ResultTime(index, e, Marshal.PtrToStringAnsi(text), (long)startTime, (long)endTime);
- list.Add(_result);
- return true;
- };
- SttError error = SttForeachDetailedResult(_handle, _resultTimeDelegate, IntPtr.Zero);
- if (error != SttError.None)
- {
- Log.Error(LogTag, "GetDetailedResult Failed with error " + error);
- throw ExceptionFactory.CreateException(error);
- }
+ _result = new ResultTime(index, e, Marshal.PtrToStringAnsi(text), (long)startTime, (long)endTime);
+ list.Add(_result);
+ return true;
+ };
+
+ SttError error = SttForeachDetailedResult(_handle, _resultTimeDelegate, IntPtr.Zero);
+ if (error != SttError.None)
+ {
+ Log.Error(LogTag, "GetDetailedResult Failed with error " + error);
+ throw ExceptionFactory.CreateException(error);
}
return list;
}
public string GetPrivateData(string key)
{
string data;
- lock (thisLock)
+ SttError error = SttGetPrivateData(_handle, key, out data);
+ if (error != SttError.None)
{
- SttError error = SttGetPrivateData(_handle, key, out data);
- if (error != SttError.None)
- {
- Log.Error(LogTag, "GetPrivateData Failed with error " + error);
- throw ExceptionFactory.CreateException(error);
- }
+ Log.Error(LogTag, "GetPrivateData Failed with error " + error);
+ throw ExceptionFactory.CreateException(error);
}
return data;
/// </pre>
public void SetPrivateData(string key, string data)
{
- lock (thisLock)
+ SttError error = SttSetPrivateData(_handle, key, data);
+ if (error != SttError.None)
{
- SttError error = SttSetPrivateData(_handle, key, data);
- if (error != SttError.None)
- {
- Log.Error(LogTag, "SetPrivateData Failed with error " + error);
- throw ExceptionFactory.CreateException(error);
- }
+ Log.Error(LogTag, "SetPrivateData Failed with error " + error);
+ throw ExceptionFactory.CreateException(error);
}
}
public IEnumerable<SupportedEngine> GetSupportedEngines()
{
List<SupportedEngine> engineList = new List<SupportedEngine>();
- lock (thisLock)
+ SupportedEngineCallback supportedEngineDelegate = (IntPtr handle, IntPtr engineId, IntPtr engineName, IntPtr userData) =>
{
- SupportedEngineCallback supportedEngineDelegate = (IntPtr handle, IntPtr engineId, IntPtr engineName, IntPtr userData) =>
- {
- string id = Marshal.PtrToStringAnsi(engineId);
- string name = Marshal.PtrToStringAnsi(engineName);
- SupportedEngine engine = new SupportedEngine(id, name);
- engineList.Add(engine);
- return true;
- };
- SttError error = SttForeEachSupportedEngines(_handle, supportedEngineDelegate, IntPtr.Zero);
- if (error != SttError.None)
- {
- Log.Error(LogTag, "Create Failed with error " + error);
- throw ExceptionFactory.CreateException(error);
- }
+ string id = Marshal.PtrToStringAnsi(engineId);
+ string name = Marshal.PtrToStringAnsi(engineName);
+ SupportedEngine engine = new SupportedEngine(id, name);
+ engineList.Add(engine);
+ return true;
+ };
+
+ SttError error = SttForeEachSupportedEngines(_handle, supportedEngineDelegate, IntPtr.Zero);
+ if (error != SttError.None)
+ {
+ Log.Error(LogTag, "Create Failed with error " + error);
+ throw ExceptionFactory.CreateException(error);
}
return engineList;
/// </pre>
public void SetCredential(string credential)
{
- lock (thisLock)
+ SttError error = SttSetcredential(_handle, credential);
+ if (error != SttError.None)
{
- SttError error = SttSetcredential(_handle, credential);
- if (error != SttError.None)
- {
- Log.Error(LogTag, "SetCredential Failed with error " + error);
- throw ExceptionFactory.CreateException(error);
- }
+ Log.Error(LogTag, "SetCredential Failed with error " + error);
+ throw ExceptionFactory.CreateException(error);
}
}
/// </post>
public void Prepare()
{
- lock (thisLock)
+ SttError error = SttPrepare(_handle);
+ if (error != SttError.None)
{
- SttError error = SttPrepare(_handle);
- if (error != SttError.None)
- {
- Log.Error(LogTag, "SetEngine Failed with error " + error);
- throw ExceptionFactory.CreateException(error);
- }
+ Log.Error(LogTag, "SetEngine Failed with error " + error);
+ throw ExceptionFactory.CreateException(error);
}
}
/// </post>
public void Unprepare()
{
- lock (thisLock)
+ SttError error = SttUnprepare(_handle);
+ if (error != SttError.None)
{
- SttError error = SttUnprepare(_handle);
- if (error != SttError.None)
- {
- Log.Error(LogTag, "Unprepare Failed with error " + error);
- throw ExceptionFactory.CreateException(error);
- }
+ Log.Error(LogTag, "Unprepare Failed with error " + error);
+ throw ExceptionFactory.CreateException(error);
}
}
public IEnumerable<string> GetSupportedLanguages()
{
List<string> languageList = new List<string>();
- lock (thisLock)
+ SupportedLanguageCallback supportedLanguageDelegate = (IntPtr handle, IntPtr language, IntPtr userData) =>
{
- SupportedLanguageCallback supportedLanguageDelegate = (IntPtr handle, IntPtr language, IntPtr userData) =>
- {
- string lang = Marshal.PtrToStringAnsi(language);
- languageList.Add(lang);
- return true;
- };
+ string lang = Marshal.PtrToStringAnsi(language);
+ languageList.Add(lang);
+ return true;
+ };
- SttError error = SttForeachSupportedLanguages(_handle, supportedLanguageDelegate, IntPtr.Zero);
- if (error != SttError.None)
- {
- Log.Error(LogTag, "GetSupportedLanguages Failed with error " + error);
- throw ExceptionFactory.CreateException(error);
- }
+ SttError error = SttForeachSupportedLanguages(_handle, supportedLanguageDelegate, IntPtr.Zero);
+ if (error != SttError.None)
+ {
+ Log.Error(LogTag, "GetSupportedLanguages Failed with error " + error);
+ throw ExceptionFactory.CreateException(error);
}
return languageList;
public bool IsRecognitionTypeSupported(RecognitionType type)
{
bool supported;
- lock (thisLock)
+ string recType = "stt.recognition.type.FREE";
+ switch (type)
{
- string recType = "stt.recognition.type.FREE";
- switch (type)
- {
- case RecognitionType.Free:
- {
- recType = "stt.recognition.type.FREE";
- break;
- }
+ case RecognitionType.Free:
+ {
+ recType = "stt.recognition.type.FREE";
+ break;
+ }
- case RecognitionType.Partial:
- {
- recType = "stt.recognition.type.FREE.PARTIAL";
- break;
- }
+ case RecognitionType.Partial:
+ {
+ recType = "stt.recognition.type.FREE.PARTIAL";
+ break;
+ }
- case RecognitionType.Search:
- {
- recType = "stt.recognition.type.SEARCH";
- break;
- }
+ case RecognitionType.Search:
+ {
+ recType = "stt.recognition.type.SEARCH";
+ break;
+ }
- case RecognitionType.WebSearch:
- {
- recType = "stt.recognition.type.WEB_SEARCH";
- break;
- }
+ case RecognitionType.WebSearch:
+ {
+ recType = "stt.recognition.type.WEB_SEARCH";
+ break;
+ }
- case RecognitionType.Map:
- {
- recType = "stt.recognition.type.MAP";
- break;
- }
- }
+ case RecognitionType.Map:
+ {
+ recType = "stt.recognition.type.MAP";
+ break;
+ }
+ }
- SttError error = SttIsRecognitionTypeSupported(_handle, recType, out supported);
- if (error != SttError.None)
- {
- Log.Error(LogTag, "IsRecognitionTypeSupported Failed with error " + error);
- throw ExceptionFactory.CreateException(error);
- }
+ SttError error = SttIsRecognitionTypeSupported(_handle, recType, out supported);
+ if (error != SttError.None)
+ {
+ Log.Error(LogTag, "IsRecognitionTypeSupported Failed with error " + error);
+ throw ExceptionFactory.CreateException(error);
}
return supported;
/// </pre>
public void SetSilenceDetection(SilenceDetection type)
{
- lock (thisLock)
+ SttError error = SttSetSilenceDetection(_handle, type);
+ if (error != SttError.None)
{
- SttError error = SttSetSilenceDetection(_handle, type);
- if (error != SttError.None)
- {
- Log.Error(LogTag, "SetSilenceDetection Failed with error " + error);
- throw ExceptionFactory.CreateException(error);
- }
+ Log.Error(LogTag, "SetSilenceDetection Failed with error " + error);
+ throw ExceptionFactory.CreateException(error);
}
}
/// </pre>
public void SetStartSound(string filePath)
{
- lock (thisLock)
+ SttError error = SttSetStartSound(_handle, filePath);
+ if (error != SttError.None)
{
- SttError error = SttSetStartSound(_handle, filePath);
- if (error != SttError.None)
- {
- Log.Error(LogTag, "SetStartSound Failed with error " + error);
- throw ExceptionFactory.CreateException(error);
- }
+ Log.Error(LogTag, "SetStartSound Failed with error " + error);
+ throw ExceptionFactory.CreateException(error);
}
}
/// </pre>
public void UnsetStartSound()
{
- lock (thisLock)
+ SttError error = SttUnsetStartSound(_handle);
+ if (error != SttError.None)
{
- SttError error = SttUnsetStartSound(_handle);
- if (error != SttError.None)
- {
- Log.Error(LogTag, "UnsetStartSound Failed with error " + error);
- throw ExceptionFactory.CreateException(error);
- }
+ Log.Error(LogTag, "UnsetStartSound Failed with error " + error);
+ throw ExceptionFactory.CreateException(error);
}
}
/// </pre>
public void SetStopSound(string filePath)
{
- lock (thisLock)
+ SttError error = SttSetStopSound(_handle, filePath);
+ if (error != SttError.None)
{
- SttError error = SttSetStopSound(_handle, filePath);
- if (error != SttError.None)
- {
- Log.Error(LogTag, "SetStopSound Failed with error " + error);
- throw ExceptionFactory.CreateException(error);
- }
+ Log.Error(LogTag, "SetStopSound Failed with error " + error);
+ throw ExceptionFactory.CreateException(error);
}
}
/// </pre>
public void UnsetStopSound()
{
- lock (thisLock)
+ SttError error = SttUnsetStopSound(_handle);
+ if (error != SttError.None)
{
- SttError error = SttUnsetStopSound(_handle);
- if (error != SttError.None)
- {
- Log.Error(LogTag, "UnsetStopSound Failed with error " + error);
- throw ExceptionFactory.CreateException(error);
- }
+ Log.Error(LogTag, "UnsetStopSound Failed with error " + error);
+ throw ExceptionFactory.CreateException(error);
}
}
/// </post>
public void Start(string language, RecognitionType type)
{
- lock (thisLock)
+ string recType = "stt.recognition.type.FREE";
+ switch (type)
{
- string recType = "stt.recognition.type.FREE";
- switch (type)
- {
- case RecognitionType.Free:
- {
- recType = "stt.recognition.type.FREE";
- break;
- }
+ case RecognitionType.Free:
+ {
+ recType = "stt.recognition.type.FREE";
+ break;
+ }
- case RecognitionType.Partial:
- {
- recType = "stt.recognition.type.FREE.PARTIAL";
- break;
- }
+ case RecognitionType.Partial:
+ {
+ recType = "stt.recognition.type.FREE.PARTIAL";
+ break;
+ }
- case RecognitionType.Search:
- {
- recType = "stt.recognition.type.SEARCH";
- break;
- }
+ case RecognitionType.Search:
+ {
+ recType = "stt.recognition.type.SEARCH";
+ break;
+ }
- case RecognitionType.WebSearch:
- {
- recType = "stt.recognition.type.WEB_SEARCH";
- break;
- }
+ case RecognitionType.WebSearch:
+ {
+ recType = "stt.recognition.type.WEB_SEARCH";
+ break;
+ }
- case RecognitionType.Map:
- {
- recType = "stt.recognition.type.MAP";
- break;
- }
- }
+ case RecognitionType.Map:
+ {
+ recType = "stt.recognition.type.MAP";
+ break;
+ }
+ }
- SttError error = SttStart(_handle, language, recType);
- if (error != SttError.None)
- {
- Log.Error(LogTag, "Start Failed with error " + error);
- throw ExceptionFactory.CreateException(error);
- }
+ SttError error = SttStart(_handle, language, recType);
+ if (error != SttError.None)
+ {
+ Log.Error(LogTag, "Start Failed with error " + error);
+ throw ExceptionFactory.CreateException(error);
}
}
/// </post>
public void Stop()
{
- lock (thisLock)
+ SttError error = SttStop(_handle);
+ if (error != SttError.None)
{
- SttError error = SttStop(_handle);
- if (error != SttError.None)
- {
- Log.Error(LogTag, "Stop Failed with error " + error);
- throw ExceptionFactory.CreateException(error);
- }
+ Log.Error(LogTag, "Stop Failed with error " + error);
+ throw ExceptionFactory.CreateException(error);
}
}
/// </post>
public void Cancel()
{
- lock (thisLock)
+ SttError error = SttCancel(_handle);
+ if (error != SttError.None)
{
- SttError error = SttCancel(_handle);
- if (error != SttError.None)
- {
- Log.Error(LogTag, "Cancel Failed with error " + error);
- throw ExceptionFactory.CreateException(error);
- }
+ Log.Error(LogTag, "Cancel Failed with error " + error);
+ throw ExceptionFactory.CreateException(error);
}
}
{
if (!disposedValue)
{
- lock (thisLock)
- {
- if (_handle != IntPtr.Zero)
- {
- SttError error = SttDestroy(_handle);
- if (error != SttError.None)
- {
- Log.Error(LogTag, "Destroy Failed with error " + error);
- }
- _handle = IntPtr.Zero;
- }
- }
-
- disposedValue = true;
+ if (_handle != IntPtr.Zero)
+ {
+ SttError error = SttDestroy(_handle);
+ if (error != SttError.None)
+ {
+ Log.Error(LogTag, "Destroy Failed with error " + error);
+ }
+ _handle = IntPtr.Zero;
+ }
+
+ disposedValue = true;
}
}
}
private event EventHandler<DefaultVoiceChangedEventArgs> _defaultVoiceChanged;
private event EventHandler<EngineChangedEventArgs> _engineChanged;
private bool disposedValue = false;
- private Object thisLock = new Object();
+ private readonly Object _stateChangedLock = new Object();
+ private readonly Object _utteranceStartedLock = new Object();
+ private readonly Object _utteranceCompletedLock = new Object();
+ private readonly Object _errorOccurredLock = new Object();
+ private readonly Object _defaultVoiceChangedLock = new Object();
+ private readonly Object _engineChangedLock = new Object();
private TtsStateChangedCB _stateDelegate;
private TtsUtteranceStartedCB _utteranceStartedResultDelegate;
private TtsUtteranceCompletedCB _utteranceCompletedResultDelegate;
{
add
{
- lock (thisLock)
+ lock (_stateChangedLock)
{
if (_stateChanged == null)
{
remove
{
- lock (thisLock)
+ lock (_stateChangedLock)
{
_stateChanged -= value;
if (_stateChanged == null)
{
add
{
- lock (thisLock)
+ lock (_utteranceStartedLock)
{
if (_utteranceStarted == null)
{
remove
{
- lock (thisLock)
+ lock (_utteranceStartedLock)
{
_utteranceStarted -= value;
if (_utteranceStarted == null)
{
add
{
- lock (thisLock)
+ lock (_utteranceCompletedLock)
{
if (_utteranceCompleted == null)
{
remove
{
- lock (thisLock)
+ lock (_utteranceCompletedLock)
{
_utteranceCompleted -= value;
if (_utteranceCompleted == null)
{
add
{
- lock (thisLock)
+ lock (_errorOccurredLock)
{
if (_errorOccurred == null)
{
remove
{
- lock (thisLock)
+ lock (_errorOccurredLock)
{
_errorOccurred -= value;
if (_errorOccurred == null)
{
add
{
- lock (thisLock)
+ lock (_defaultVoiceChangedLock)
{
if (_defaultVoiceChanged == null)
{
}
_defaultVoiceChanged += value;
}
-
}
remove
{
- lock (thisLock)
+ lock (_defaultVoiceChangedLock)
{
_defaultVoiceChanged -= value;
if (_defaultVoiceChanged == null)
- {
+ {
TtsError error = TtsUnsetDefaultVoiceChangedCB(_handle);
if (error != TtsError.None)
{
{
add
{
- lock (thisLock)
+ lock (_engineChangedLock)
{
if (_engineChanged == null)
{
remove
{
- lock (thisLock)
+ lock (_engineChangedLock)
{
_engineChanged -= value;
if (_engineChanged == null)
{
get
{
- lock (thisLock)
+ string language;
+ int voiceType;
+ TtsError error = TtsGetDefaultVoice(_handle, out language, out voiceType);
+ if (error != TtsError.None)
{
- string language;
- int voiceType;
- TtsError error = TtsGetDefaultVoice(_handle, out language, out voiceType);
- if (error != TtsError.None)
- {
- Log.Error(LogTag, "DefaultVoice Failed with error " + error);
- return new SupportedVoice();
- }
-
- return new SupportedVoice(language, voiceType);
+ Log.Error(LogTag, "DefaultVoice Failed with error " + error);
+ return new SupportedVoice();
}
+
+ return new SupportedVoice(language, voiceType);
}
}
get
{
uint maxTextSize;
- lock (thisLock)
+ TtsError error = TtsGetMaxTextSize(_handle, out maxTextSize);
+ if (error != TtsError.None)
{
- TtsError error = TtsGetMaxTextSize(_handle, out maxTextSize);
- if (error != TtsError.None)
- {
- Log.Error(LogTag, "MaxTextSize Failed with error " + error);
- return 0;
- }
+ Log.Error(LogTag, "MaxTextSize Failed with error " + error);
+ return 0;
}
return maxTextSize;
get
{
State state;
- lock (thisLock)
+ TtsError error = TtsGetState(_handle, out state);
+ if (error != TtsError.None)
{
- TtsError error = TtsGetState(_handle, out state);
- if (error != TtsError.None)
- {
- Log.Error(LogTag, "CurrentState Failed with error " + error);
- return State.Unavailable;
- }
+ Log.Error(LogTag, "CurrentState Failed with error " + error);
+ return State.Unavailable;
}
return state;
get
{
Mode mode = Mode.Default;
- lock (thisLock)
+ TtsError error = TtsGetMode(_handle, out mode);
+ if (error != TtsError.None)
{
- TtsError error = TtsGetMode(_handle, out mode);
- if (error != TtsError.None)
- {
- Log.Error(LogTag, "Get Mode Failed with error " + error);
- return Mode.Default;
- }
+ Log.Error(LogTag, "Get Mode Failed with error " + error);
+ return Mode.Default;
}
return mode;
set
{
TtsError error;
- lock (thisLock)
- {
- error = TtsSetMode(_handle, value);
- }
+ error = TtsSetMode(_handle, value);
if (error != TtsError.None)
{
/// </pre>
public void SetCredential(string credential)
{
- lock (thisLock)
+ TtsError error = TtsSetCredential(_handle, credential);
+ if (error != TtsError.None)
{
- TtsError error = TtsSetCredential(_handle, credential);
- if (error != TtsError.None)
- {
- Tizen.Log.Error(LogTag, "SetCredential Failed with error " + error);
- throw ExceptionFactory.CreateException(error);
- }
+ Tizen.Log.Error(LogTag, "SetCredential Failed with error " + error);
+ throw ExceptionFactory.CreateException(error);
}
}
/// </post>
public void Prepare()
{
- lock (thisLock)
+ TtsError error = TtsPrepare(_handle);
+ if (error != TtsError.None)
{
- TtsError error = TtsPrepare(_handle);
- if (error != TtsError.None)
- {
- Log.Error(LogTag, "Prepare Failed with error " + error);
- throw ExceptionFactory.CreateException(error);
- }
+ Log.Error(LogTag, "Prepare Failed with error " + error);
+ throw ExceptionFactory.CreateException(error);
}
}
/// </post>
public void Unprepare()
{
- lock (thisLock)
+ TtsError error = TtsUnprepare(_handle);
+ if (error != TtsError.None)
{
- TtsError error = TtsUnprepare(_handle);
- if (error != TtsError.None)
- {
- Log.Error(LogTag, "Unprepare Failed with error " + error);
- throw ExceptionFactory.CreateException(error);
- }
+ Log.Error(LogTag, "Unprepare Failed with error " + error);
+ throw ExceptionFactory.CreateException(error);
}
}
public IEnumerable<SupportedVoice> GetSupportedVoices()
{
List<SupportedVoice> voicesList = new List<SupportedVoice>();
- lock (thisLock)
+
+ _supportedvoiceDelegate = (IntPtr handle, IntPtr language, int voiceType, IntPtr userData) =>
{
- _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);
- }
+ 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;
public string GetPrivateData(string key)
{
string data;
- lock (thisLock)
+ TtsError error = TtsGetPrivateData(_handle, key, out data);
+ if (error != TtsError.None)
{
- TtsError error = TtsGetPrivateData(_handle, key, out data);
- if (error != TtsError.None)
- {
- Log.Error(LogTag, "GetPrivateData Failed with error " + error);
- throw ExceptionFactory.CreateException(error);
- }
+ Log.Error(LogTag, "GetPrivateData Failed with error " + error);
+ throw ExceptionFactory.CreateException(error);
}
return data;
/// </pre>
public void SetPrivateData(string key, string data)
{
- lock (thisLock)
+ TtsError error = TtsSetPrivateData(_handle, key, data);
+ if (error != TtsError.None)
{
- TtsError error = TtsSetPrivateData(_handle, key, data);
- if (error != TtsError.None)
- {
- Log.Error(LogTag, "SetPrivateData Failed with error " + error);
- throw ExceptionFactory.CreateException(error);
- }
+ Log.Error(LogTag, "SetPrivateData Failed with error " + error);
+ throw ExceptionFactory.CreateException(error);
}
}
public SpeedRange GetSpeedRange()
{
int min = 0, max = 0, normal = 0;
- lock (thisLock)
+ TtsError error = TtsGetSpeedRange(_handle, out min, out normal, out max);
+ if (error != TtsError.None)
{
- 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);
- }
+ Log.Error(LogTag, "GetSpeedRange Failed with error " + error);
+ throw ExceptionFactory.CreateException(error);
}
return new SpeedRange(min, normal, max);
public int AddText(string text, string language, int voiceType, int speed)
{
int id;
- lock (thisLock)
+ TtsError error = TtsAddText(_handle, text, language, voiceType, speed, out id);
+ if (error != TtsError.None)
{
- 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);
- }
+ Log.Error(LogTag, "AddText Failed with error " + error);
+ throw ExceptionFactory.CreateException(error);
}
return id;
/// </post>
public void Play()
{
- lock (thisLock)
+ TtsError error = TtsPlay(_handle);
+ if (error != TtsError.None)
{
- TtsError error = TtsPlay(_handle);
- if (error != TtsError.None)
- {
- Log.Error(LogTag, "Play Failed with error " + error);
- throw ExceptionFactory.CreateException(error);
- }
+ Log.Error(LogTag, "Play Failed with error " + error);
+ throw ExceptionFactory.CreateException(error);
}
}
/// </post>
public void Stop()
{
- lock (thisLock)
+ TtsError error = TtsStop(_handle);
+ if (error != TtsError.None)
{
- TtsError error = TtsStop(_handle);
- if (error != TtsError.None)
- {
- Log.Error(LogTag, "Stop Failed with error " + error);
- throw ExceptionFactory.CreateException(error);
- }
+ Log.Error(LogTag, "Stop Failed with error " + error);
+ throw ExceptionFactory.CreateException(error);
}
}
/// </post>
public void Pause()
{
- lock (thisLock)
+ TtsError error = TtsPause(_handle);
+ if (error != TtsError.None)
{
- TtsError error = TtsPause(_handle);
- if (error != TtsError.None)
- {
- Log.Error(LogTag, "Pause Failed with error " + error);
- throw ExceptionFactory.CreateException(error);
- }
+ Log.Error(LogTag, "Pause Failed with error " + error);
+ throw ExceptionFactory.CreateException(error);
}
}
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;
+ {
+ 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;
}
}
}