();
lock (thisLock)
{
SupportedLanguageCallback supportedLanguageDelegate = (IntPtr handle, IntPtr language, IntPtr userData) =>
{
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);
}
}
return languageList;
}
///
/// Checks whether the recognition type is supported.
///
/// 3
///
/// http://tizen.org/privilege/recorder
///
///
/// RecognitionType value.
///
///
/// bool value indicating whether the recognition type is supported.
///
///
/// http://tizen.org/feature/speech.recognition
/// http://tizen.org/feature/microphone
///
///
/// This Exception can be due to the following reasons
/// 1. Invalid State
/// 2. Engine Not Found.
/// 3. Operation Failed.
///
/// This Exception can be due to STT Not Supported.
///
/// The state should be Ready.
///
public bool IsRecognitionTypeSupported(RecognitionType type)
{
bool supported;
lock (thisLock)
{
string recType = "stt.recognition.type.FREE";
switch (type)
{
case RecognitionType.Free:
{
recType = "stt.recognition.type.FREE";
break;
}
case RecognitionType.Partial:
{
recType = "stt.recognition.type.FREE.PARTIAL";
break;
}
case RecognitionType.Search:
{
recType = "stt.recognition.type.SEARCH";
break;
}
case RecognitionType.WebSearch:
{
recType = "stt.recognition.type.WEB_SEARCH";
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);
}
}
return supported;
}
///
/// Sets the silence detection.
///
/// 3
///
/// http://tizen.org/privilege/recorder
///
///
/// SilenceDetection value.
///
///
/// http://tizen.org/feature/speech.recognition
/// http://tizen.org/feature/microphone
///
///
/// This Exception can be due to the following reasons
/// 1. Invalid State
/// 2. Not supported feature of current engine.
/// 3. Operation Failed.
///
/// This Exception can be due to STT Not Supported.
///
/// The state should be Ready.
///
public void SetSilenceDetection(SilenceDetection type)
{
lock (thisLock)
{
SttError error = SttSetSilenceDetection(_handle, type);
if (error != SttError.None)
{
Log.Error(LogTag, "SetSilenceDetection Failed with error " + error);
throw ExceptionFactory.CreateException(error);
}
}
}
///
/// Sets the sound to start recording.
/// Sound file type should be wav type.
///
/// 3
///
/// http://tizen.org/privilege/recorder
///
///
/// File Path for the sound.
///
///
/// http://tizen.org/feature/speech.recognition
/// http://tizen.org/feature/microphone
///
///
/// This Exception can be due to the following reasons
/// 1. Invalid State.
/// 2. Operation Failed.
///
/// This Exception can be due to STT Not Supported.
/// This Exception can be due to Permission Denied.
/// If an Invalid Parameter is provided.
///
/// The state should be Ready.
///
public void SetStartSound(string filePath)
{
lock (thisLock)
{
SttError error = SttSetStartSound(_handle, filePath);
if (error != SttError.None)
{
Log.Error(LogTag, "SetStartSound Failed with error " + error);
throw ExceptionFactory.CreateException(error);
}
}
}
///
/// Unsets the sound to start recording.
///
/// 3
///
/// http://tizen.org/privilege/recorder
///
///
/// http://tizen.org/feature/speech.recognition
/// http://tizen.org/feature/microphone
///
///
/// This Exception can be due to the following reasons
/// 1. Invalid State.
/// 2. Operation Failed.
///
/// This Exception can be due to STT Not Supported.
/// This Exception can be due to Permission Denied.
///
/// The state should be Ready.
///
public void UnsetStartSound()
{
lock (thisLock)
{
SttError error = SttUnsetStartSound(_handle);
if (error != SttError.None)
{
Log.Error(LogTag, "UnsetStartSound Failed with error " + error);
throw ExceptionFactory.CreateException(error);
}
}
}
///
/// Sets the sound to stop recording.
/// Sound file type should be wav type.
///
/// 3
///
/// http://tizen.org/privilege/recorder
///
///
/// File Path for the sound.
///
///
/// http://tizen.org/feature/speech.recognition
/// http://tizen.org/feature/microphone
///
///
/// This Exception can be due to the following reasons
/// 1. Invalid State.
/// 2. Operation Failed.
///
/// This Exception can be due to STT Not Supported.
/// This Exception can be due to Permission Denied.
/// If an Invalid Parameter is provided.
///
/// The state should be Ready.
///
public void SetStopSound(string filePath)
{
lock (thisLock)
{
SttError error = SttSetStopSound(_handle, filePath);
if (error != SttError.None)
{
Log.Error(LogTag, "SetStopSound Failed with error " + error);
throw ExceptionFactory.CreateException(error);
}
}
}
///
/// Unsets the sound to stop recording.
///
/// 3
///
/// http://tizen.org/privilege/recorder
///
///
/// http://tizen.org/feature/speech.recognition
/// http://tizen.org/feature/microphone
///
///
/// This Exception can be due to the following reasons
/// 1. Invalid State.
/// 2. Operation Failed.
///
/// This Exception can be due to STT Not Supported.
/// This Exception can be due to Permission Denied.
///
/// The state should be Ready.
///
public void UnsetStopSound()
{
lock (thisLock)
{
SttError error = SttUnsetStopSound(_handle);
if (error != SttError.None)
{
Log.Error(LogTag, "UnsetStopSound Failed with error " + error);
throw ExceptionFactory.CreateException(error);
}
}
}
///
/// Starts recording and recognition asynchronously.
/// This function starts recording in the STT service and sending recording data to engine.
/// This work continues until Stop, Cancel or silence detected by engine
///
/// 3
///
/// http://tizen.org/privilege/recorder
///
///
/// The language selected
///
///
/// The type for recognition
///
///
/// http://tizen.org/feature/speech.recognition
/// http://tizen.org/feature/microphone
///
///
/// This Exception can be due to the following reasons
/// 1. Invalid State.
/// 2. Operation Failed.
/// 3. Recorder Busy.
/// 4. Progress to recording is not finished
///
/// This Exception can be due to STT Not Supported.
/// This Exception can be due to Permission Denied.
/// If an Invalid Language is provided.
///
/// The state should be Ready.
///
///
/// It will invoke StateChanged Event if registered.
/// If this function succeeds, the STT state will be Recording.
/// If you call this function again before state changes, you will receive ErrorINProgressToRecording.
///
public void Start(string language, RecognitionType type)
{
lock (thisLock)
{
string recType = "stt.recognition.type.FREE";
switch (type)
{
case RecognitionType.Free:
{
recType = "stt.recognition.type.FREE";
break;
}
case RecognitionType.Partial:
{
recType = "stt.recognition.type.FREE.PARTIAL";
break;
}
case RecognitionType.Search:
{
recType = "stt.recognition.type.SEARCH";
break;
}
case RecognitionType.WebSearch:
{
recType = "stt.recognition.type.WEB_SEARCH";
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);
}
}
}
///
/// Finishes the recording and starts recognition processing in engine asynchronously.
///
/// 3
///
/// http://tizen.org/privilege/recorder
///
///
/// http://tizen.org/feature/speech.recognition
/// http://tizen.org/feature/microphone
///
///
/// This Exception can be due to the following reasons
/// 1. Invalid State.
/// 2. Operation Failed.
/// 3. Progress to ready is not finished.
/// 4. Progress to recording is not finished.
/// 5. Progress to processing is not finished.
///
/// This Exception can be due to STT Not Supported.
/// This Exception can be due to Permission Denied.
///
/// The state should be Recording.
///
///
/// It will invoke StateChanged Event if registered.
/// If this function succeeds, the STT state will be Processing.
/// If you call this function again before state changes, you will receive ErrorINProgressToProcessing.
/// After processing of engine, RecognitionResult event is invoked
///
public void Stop()
{
lock (thisLock)
{
SttError error = SttStop(_handle);
if (error != SttError.None)
{
Log.Error(LogTag, "Stop Failed with error " + error);
throw ExceptionFactory.CreateException(error);
}
}
}
///
/// Cancels processing recognition and recording asynchronously.
/// This function cancels recording and engine cancels recognition processing.
/// After successful cancel, StateChanged event is invoked otherwise if error is occurred, ErrorOccurred event is invoked.
///
/// 3
///
/// http://tizen.org/privilege/recorder
///
///
/// http://tizen.org/feature/speech.recognition
/// http://tizen.org/feature/microphone
///
///
/// This Exception can be due to the following reasons
/// 1. Invalid State.
/// 2. Operation Failed.
/// 3. Progress to ready is not finished.
/// 4. Progress to recording is not finished.
/// 5. Progress to processing is not finished.
///
/// This Exception can be due to STT Not Supported.
/// This Exception can be due to Permission Denied.
///
/// The state should be Recording or Processing.
///
///
/// It will invoke StateChanged Event if registered.
/// If this function succeeds, the STT state will be Ready.
/// If you call this function again before state changes, you will receive ErrorINProgressToReady.
///
public void Cancel()
{
lock (thisLock)
{
SttError error = SttCancel(_handle);
if (error != SttError.None)
{
Log.Error(LogTag, "Cancel Failed with error " + error);
throw ExceptionFactory.CreateException(error);
}
}
}
///
/// Method to release resources
///
public void Dispose()
{
Dispose(true);
}
protected virtual void Dispose(bool disposing)
{
if (!disposedValue)
{
if (disposing)
{
SttError error = SttDestroy(_handle);
if (error != SttError.None)
{
Log.Error(LogTag, "Destroy Failed with error " + error);
}
}
disposedValue = true;
}
}
}
}