static inline const char *stt_state_str(stt_state_e cur) {
if (cur == STT_STATE_CREATED)
return (const char *) "STT_STATE_CREATED";
-
else if (cur == STT_STATE_READY)
return (const char *) "STT_STATE_READY";
-
else if (cur == STT_STATE_RECORDING)
return (const char *) "STT_STATE_RECORDING";
-
else if (cur == STT_STATE_PROCESSING)
return (const char *) "STT_STATE_PROCESSING";
-
else
return (const char *) "ABNORMAL CASE";
}
-static void player_focus_state_cb(sound_stream_info_h stream_info, sound_stream_focus_change_reason_e reason_for_change, const char *extra_info, void *user_data)
+static void player_focus_state_cb(sound_stream_info_h stream_info, sound_stream_focus_mask_e focus_mask, sound_stream_focus_state_e focus_state,
+ sound_stream_focus_change_reason_e reason_for_change, int sound_behavior, const char *extra_info, void *user_data)
{
}
*/
int ret = stt_create(&handle);
- if(ret != STT_ERROR_NONE)
+ if (ret != STT_ERROR_NONE)
throw SttException(ret, ErrorString((stt_error_e)ret));
ret = sound_manager_create_stream_information(SOUND_STREAM_TYPE_VOICE_RECOGNITION, player_focus_state_cb, NULL, &g_stream_info_h);
}
catch(SttException &e) {
PRINTFUNC(DLOG_ERROR, "reason : %s", e.what());
+
stt_destroy(handle);
}
*/
int ret = stt_prepare(handle);
- if(ret != STT_ERROR_NONE)
+ if (ret != STT_ERROR_NONE)
throw SttException(ret, ErrorString((stt_error_e)ret));
}
void SttManager::UnPrepare() {
- /**
- * UnPrepare stt service.
- *
- */
- int ret = stt_unprepare(handle);
-
- if (ret != STT_ERROR_NONE)
- throw SttException(ret, ErrorString((stt_error_e)ret));
+ /**
+ * UnPrepare stt service.
+ *
+ */
+ int ret = stt_unprepare(handle);
+
+ if (ret != STT_ERROR_NONE)
+ throw SttException(ret, ErrorString((stt_error_e)ret));
}
void SttManager::Start() {
- if(!Validate((int) READY)) {
+ if (!Validate((int) READY)) {
throw SttException((int) STT_ERROR_INVALID_STATE, "INVALID STATE - !STT_STATE_READY");
}
asrtype = STT_RECOGNITION_TYPE_FREE_PARTIAL;
int ret;
- ret = sound_manager_acquire_focus(g_stream_info_h, (sound_stream_focus_mask_e)(SOUND_STREAM_FOCUS_FOR_PLAYBACK | SOUND_STREAM_FOCUS_FOR_RECORDING), NULL);
+ ret = sound_manager_acquire_focus(g_stream_info_h, (sound_stream_focus_mask_e)(SOUND_STREAM_FOCUS_FOR_PLAYBACK | SOUND_STREAM_FOCUS_FOR_RECORDING), SOUND_BEHAVIOR_NONE, NULL);
if (SOUND_MANAGER_ERROR_NONE != ret) {
LOGW("Fail to acquire playback or recording focus. ret : %d, stream handle : %p", ret, g_stream_info_h);
}
ret = stt_start(handle, language.c_str(), asrtype.c_str());
- if(ret != STT_ERROR_NONE)
+ if (ret != STT_ERROR_NONE)
throw SttException(ret, ErrorString((stt_error_e)ret));
}
void SttManager::Stop() {
- if(!Validate((int) RECORDING)) {
+ if (!Validate((int) RECORDING)) {
throw SttException((int) STT_ERROR_INVALID_STATE, "INVALID STATE - !STT_STATE_RECORDING");
}
*/
int ret = stt_stop(handle);
- if(ret != STT_ERROR_NONE)
+ if (ret != STT_ERROR_NONE)
throw SttException(ret, ErrorString((stt_error_e)ret));
}
void SttManager::Cancel() {
- if(iscancelled) {
+ if (iscancelled) {
PRINTFUNC(DLOG_WARN, "iscancelled (%d)", iscancelled);
return;
}
- if(!Validate((int) (RECORDING|PROCESSING))) {
+ if (!Validate((int) (RECORDING|PROCESSING))) {
throw SttException((int) STT_ERROR_INVALID_STATE, "INVALID STATE - !(STT_STATE_RECORDING or STT_STATE_PROCESSING)");
}
*/
int ret = stt_cancel(handle);
- if(ret != STT_ERROR_NONE)
+ if (ret != STT_ERROR_NONE)
throw SttException(ret, ErrorString((stt_error_e)ret));
iscancelled = true;
ifeedback.SttIdle();
}
-
bool SttManager::Validate(int state) {
stt_state_e cur;
cur == STT_STATE_PROCESSING ? "STT_STATE_PROCESSING" : "ABNORMAL");
switch(cur) {
- case STT_STATE_CREATED :
+ case STT_STATE_CREATED:
if (state & CREATE) return true;
break;
- case STT_STATE_READY :
+ case STT_STATE_READY:
if (state & READY) return true;
break;
- case STT_STATE_RECORDING :
+ case STT_STATE_RECORDING:
if (state & RECORDING) return true;
break;
- case STT_STATE_PROCESSING :
+ case STT_STATE_PROCESSING:
if (state & PROCESSING) return true;
break;
- default :
+ default:
break;
}
std::string result;
switch (result_type) {
- case STT_RESULT_EVENT_FINAL_RESULT :
+ case STT_RESULT_EVENT_FINAL_RESULT:
result = "STT_RESULT_EVENT_FINAL_RESULT";
break;
- case STT_RESULT_EVENT_PARTIAL_RESULT :
+ case STT_RESULT_EVENT_PARTIAL_RESULT:
result = "STT_RESULT_EVENT_PARTIAL_RESULT";
break;
- case STT_RESULT_EVENT_ERROR :
+ case STT_RESULT_EVENT_ERROR:
result = "STT_RESULT_EVENT_ERROR";
break;
- default :
+ default:
result = "UNKNOWN";
break;
}
}
void SttManager::on_result(
- stt_h handle,
- stt_result_event_e event,
- const char** data,
- int size,
- const char* msg,
- void *user_data) {
- PrintResultState(event);
-
- if (!user_data) {
+ stt_h handle,
+ stt_result_event_e event,
+ const char** data,
+ int size,
+ const char* msg,
+ void *user_data) {
+ PrintResultState(event);
+
+ if (!user_data) {
PRINTFUNC(DLOG_ERROR, "user_data null");
throw SttException((int)STT_ERROR_INVALID_PARAMETER, "invalid self reference");
- }
+ }
- SttManager& manager = *((SttManager *) user_data);
+ SttManager& manager = *((SttManager *) user_data);
- std::vector<std::string> results;
+ std::vector<std::string> results;
- PRINTFUNC(DLOG_INFO, "result size : %d, msg : %s", size, msg);
+ PRINTFUNC(DLOG_INFO, "result size : %d, msg : %s", size, msg);
- for (size_t i = 0; i < (size_t) size; i++) {
- if (data[i]) {
- results.push_back(std::string(data[i]));
- }
+ for (size_t i = 0; i < (size_t) size; i++) {
+ if (data[i]) {
+ results.push_back(std::string(data[i]));
+ }
- if (msg)
- manager.ifeedback.OnResult(manager.asrtype, event, results, std::string(msg));
- else
- manager.ifeedback.OnResult(manager.asrtype, event, results, std::string(""));
- }
+ if (msg)
+ manager.ifeedback.OnResult(manager.asrtype, event, results, std::string(msg));
+ else
+ manager.ifeedback.OnResult(manager.asrtype, event, results, std::string(""));
+ }
}
void SttManager::PrintState(stt_state_e previous, stt_state_e current)
std::string res;
switch (reason) {
- case STT_ERROR_OUT_OF_MEMORY :
+ case STT_ERROR_OUT_OF_MEMORY:
res = "STT_ERROR_OUT_OF_MEMORY";
break;
- case STT_ERROR_IO_ERROR :
+ case STT_ERROR_IO_ERROR:
res = "STT_ERROR_IO_ERROR";
break;
- case STT_ERROR_INVALID_PARAMETER :
+ case STT_ERROR_INVALID_PARAMETER:
res = "STT_ERROR_INVALID_PARAMETER";
break;
- case STT_ERROR_TIMED_OUT :
+ case STT_ERROR_TIMED_OUT:
res = "STT_ERROR_TIMED_OUT";
break;
- case STT_ERROR_RECORDER_BUSY :
+ case STT_ERROR_RECORDER_BUSY:
res = "STT_ERROR_RECORDER_BUSY";
break;
- case STT_ERROR_OUT_OF_NETWORK :
+ case STT_ERROR_OUT_OF_NETWORK:
res = "STT_ERROR_OUT_OF_NETWORK";
break;
- case STT_ERROR_PERMISSION_DENIED :
+ case STT_ERROR_PERMISSION_DENIED:
res = "STT_ERROR_PERMISSION_DENIED";
break;
- case STT_ERROR_NOT_SUPPORTED :
+ case STT_ERROR_NOT_SUPPORTED:
res = "STT_ERROR_NOT_SUPPORTED";
break;
- case STT_ERROR_INVALID_STATE :
+ case STT_ERROR_INVALID_STATE:
res = "STT_ERROR_INVALID_STATE";
break;
- case STT_ERROR_INVALID_LANGUAGE :
+ case STT_ERROR_INVALID_LANGUAGE:
res = "STT_ERROR_INVALID_LANGUAGE";
break;
- case STT_ERROR_ENGINE_NOT_FOUND :
+ case STT_ERROR_ENGINE_NOT_FOUND:
res = "STT_ERROR_ENGINE_NOT_FOUND";
break;
- case STT_ERROR_OPERATION_FAILED :
+ case STT_ERROR_OPERATION_FAILED:
res = "STT_ERROR_OPERATION_FAILED";
break;
- case STT_ERROR_NOT_SUPPORTED_FEATURE :
+ case STT_ERROR_NOT_SUPPORTED_FEATURE:
res = "STT_ERROR_NOT_SUPPORTED_FEATURE";
break;
- default :
+ default:
res = "UNKNOWN ERROR REASON";
break;
}
}
void SttManager::on_error(
- stt_h handle,
- stt_error_e reason,
- void *user_data) {
- PRINTFUNC(DLOG_INFO, "stt-daemon error (%d)", reason);
+ stt_h handle,
+ stt_error_e reason,
+ void *user_data) {
+ PRINTFUNC(DLOG_INFO, "stt-daemon error (%d)", reason);
- if (!user_data)
+ if (!user_data)
throw SttException((int)STT_ERROR_INVALID_PARAMETER, "invalid self reference");
- SttManager& manager = *((SttManager *) user_data);
- manager.ifeedback.OnError(reason);
+ SttManager& manager = *((SttManager *) user_data);
+ manager.ifeedback.OnError(reason);
}
void SttManager::SetLanguage(std::string language) {
- this->language = language;
+ this->language = language;
}
void SttManager::EnableFeedback(bool enabled) {
- int ret = STT_ERROR_NONE;
+ int ret = STT_ERROR_NONE;
- void *udata = static_cast<void *>(this);
+ void *udata = static_cast<void *>(this);
- if (enabled) {
- ret = stt_set_recognition_result_cb(handle, on_result, udata);
- if (STT_ERROR_NONE != ret)
- throw SttException(ret, ErrorString((stt_error_e)ret));
+ if (enabled) {
+ ret = stt_set_recognition_result_cb(handle, on_result, udata);
+ if (STT_ERROR_NONE != ret)
+ throw SttException(ret, ErrorString((stt_error_e)ret));
- ret = stt_set_error_cb(handle, on_error, udata);
- if (STT_ERROR_NONE != ret)
- throw SttException(ret, ErrorString((stt_error_e)ret));
+ ret = stt_set_error_cb(handle, on_error, udata);
+ if (STT_ERROR_NONE != ret)
+ throw SttException(ret, ErrorString((stt_error_e)ret));
- ret = stt_set_state_changed_cb(handle, on_state_changed, udata);
- if (STT_ERROR_NONE != ret)
- throw SttException(ret, ErrorString((stt_error_e)ret));
- } else {
- ret = stt_unset_error_cb(handle);
- if (STT_ERROR_NONE != ret)
- throw SttException(ret, ErrorString((stt_error_e)ret));
+ ret = stt_set_state_changed_cb(handle, on_state_changed, udata);
+ if (STT_ERROR_NONE != ret)
+ throw SttException(ret, ErrorString((stt_error_e)ret));
+ } else {
+ ret = stt_unset_error_cb(handle);
+ if (STT_ERROR_NONE != ret)
+ throw SttException(ret, ErrorString((stt_error_e)ret));
- ret = stt_unset_state_changed_cb(handle);
- if (STT_ERROR_NONE != ret)
- throw SttException(ret, ErrorString((stt_error_e)ret));
+ ret = stt_unset_state_changed_cb(handle);
+ if (STT_ERROR_NONE != ret)
+ throw SttException(ret, ErrorString((stt_error_e)ret));
- ret = stt_unset_recognition_result_cb(handle);
- if (STT_ERROR_NONE != ret)
- throw SttException(ret, ErrorString((stt_error_e)ret));
- }
+ ret = stt_unset_recognition_result_cb(handle);
+ if (STT_ERROR_NONE != ret)
+ throw SttException(ret, ErrorString((stt_error_e)ret));
+ }
}
const char* SttManager::ErrorString(int ecode) {
- const char *str = NULL;
-
- switch (ecode) {
- case STT_ERROR_OUT_OF_MEMORY:
- str = (const char *) "STT_ERROR_OUT_OF_MEMORY";
- break;
- case STT_ERROR_IO_ERROR:
- str = (const char *) "STT_ERROR_IO_ERROR";
- break;
- case STT_ERROR_INVALID_PARAMETER:
- str = (const char *) "STT_ERROR_INVALID_PARAMETER";
- break;
- case STT_ERROR_TIMED_OUT:
- str = (const char *) "STT_ERROR_TIMED_OUT";
- break;
- case STT_ERROR_RECORDER_BUSY:
- str = (const char *) "STT_ERROR_RECORDER_BUSY";
- break;
- case STT_ERROR_OUT_OF_NETWORK:
- str = (const char *) "STT_ERROR_OUT_OF_NETWORK";
- break;
- case STT_ERROR_INVALID_STATE:
- str = (const char *) " STT_ERROR_INVALID_STATE";
- break;
- case STT_ERROR_INVALID_LANGUAGE:
- str = (const char *) "STT_ERROR_INVALID_LANGUAGE";
- break;
- case STT_ERROR_ENGINE_NOT_FOUND:
- str = (const char *) "STT_ERROR_ENGINE_NOT_FOUND";
- break;
- case STT_ERROR_OPERATION_FAILED:
- str = (const char *) "STT_ERROR_OPERATION_FAILED";
- break;
- case STT_ERROR_NOT_SUPPORTED_FEATURE:
- str = (const char *) "STT_ERROR_NOT_SUPPORTED_FEATURE";
- break;
- }
- return str;
+ const char *str = NULL;
+
+ switch (ecode) {
+ case STT_ERROR_OUT_OF_MEMORY:
+ str = (const char *) "STT_ERROR_OUT_OF_MEMORY";
+ break;
+ case STT_ERROR_IO_ERROR:
+ str = (const char *) "STT_ERROR_IO_ERROR";
+ break;
+ case STT_ERROR_INVALID_PARAMETER:
+ str = (const char *) "STT_ERROR_INVALID_PARAMETER";
+ break;
+ case STT_ERROR_TIMED_OUT:
+ str = (const char *) "STT_ERROR_TIMED_OUT";
+ break;
+ case STT_ERROR_RECORDER_BUSY:
+ str = (const char *) "STT_ERROR_RECORDER_BUSY";
+ break;
+ case STT_ERROR_OUT_OF_NETWORK:
+ str = (const char *) "STT_ERROR_OUT_OF_NETWORK";
+ break;
+ case STT_ERROR_INVALID_STATE:
+ str = (const char *) " STT_ERROR_INVALID_STATE";
+ break;
+ case STT_ERROR_INVALID_LANGUAGE:
+ str = (const char *) "STT_ERROR_INVALID_LANGUAGE";
+ break;
+ case STT_ERROR_ENGINE_NOT_FOUND:
+ str = (const char *) "STT_ERROR_ENGINE_NOT_FOUND";
+ break;
+ case STT_ERROR_OPERATION_FAILED:
+ str = (const char *) "STT_ERROR_OPERATION_FAILED";
+ break;
+ case STT_ERROR_NOT_SUPPORTED_FEATURE:
+ str = (const char *) "STT_ERROR_NOT_SUPPORTED_FEATURE";
+ break;
+ }
+ return str;
}
void SttManager::SoundFeedback() {
- int is_sound = 0;
- int is_sound_vibe = 0;
-
- if (vconf_get_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, &is_sound)) {
- PRINTFUNC(DLOG_ERROR, "get sound status failed.");
- }
-
- if (vconf_get_bool(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, &is_sound_vibe)) {
- PRINTFUNC(DLOG_ERROR, "get vibe status failed.");
- }
-
- if (is_sound || is_sound_vibe) {
- stt_set_start_sound(handle, "/usr/share/ise-voice-input/audio/voice_start.wav");
- stt_set_stop_sound(handle, "/usr/share/ise-voice-input/audio/voice_stop.wav");
- } else {
- stt_unset_start_sound(handle);
- stt_unset_stop_sound(handle);
- }
-}
+ int is_sound = 0;
+ int is_sound_vibe = 0;
+
+ if (vconf_get_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, &is_sound)) {
+ PRINTFUNC(DLOG_ERROR, "get sound status failed.");
+ }
+ if (vconf_get_bool(VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL, &is_sound_vibe)) {
+ PRINTFUNC(DLOG_ERROR, "get vibe status failed.");
+ }
+ if (is_sound || is_sound_vibe) {
+ stt_set_start_sound(handle, "/usr/share/ise-voice-input/audio/voice_start.wav");
+ stt_set_stop_sound(handle, "/usr/share/ise-voice-input/audio/voice_stop.wav");
+ } else {
+ stt_unset_start_sound(handle);
+ stt_unset_stop_sound(handle);
+ }
+}
void SttManager::EnableSilenceDetection(bool enabled) {
stt_option_silence_detection_e s_option;
void SttManager::ReleaseSoundFocus()
{
- int ret = sound_manager_release_focus(g_stream_info_h, (sound_stream_focus_mask_e)(SOUND_STREAM_FOCUS_FOR_PLAYBACK | SOUND_STREAM_FOCUS_FOR_RECORDING), NULL);
+ int ret = sound_manager_release_focus(g_stream_info_h, (sound_stream_focus_mask_e)(SOUND_STREAM_FOCUS_FOR_PLAYBACK | SOUND_STREAM_FOCUS_FOR_RECORDING), SOUND_BEHAVIOR_NONE, NULL);
if (SOUND_MANAGER_ERROR_NONE != ret) {
LOGW("Fail to release playback or recording focus. ret : %d", ret);
}