3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.tizenopensource.org/license
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
18 #include <FUiScenes.h>
19 #include <FGraphics.h>
21 #include "SpeechAppSttForm.h"
23 using namespace Tizen::Base;
24 using namespace Tizen::Base::Collection;
25 using namespace Tizen::Ui;
26 using namespace Tizen::Ui::Controls;
27 using namespace Tizen::Ui::Scenes;
28 using namespace Tizen::Uix::Speech;
29 using namespace Tizen::Graphics;
30 using namespace Tizen::Locales;
33 SpeechAppSttForm::SpeechAppSttForm(void)
36 , __pButtonStart(null)
38 , __pButtonCancel(null)
43 SpeechAppSttForm::~SpeechAppSttForm(void)
48 SpeechAppSttForm::Initialize(void)
50 Construct(L"IDF_FORM_STT");
56 SpeechAppSttForm::OnInitializing(void)
60 SetFormBackEventListener(this);
62 __pButtonStart = static_cast< Button* >(GetControl(L"IDC_BUTTON_START"));
63 if (__pButtonStart != null)
65 __pButtonStart->SetActionId(ID_BUTTON_START);
66 __pButtonStart->AddActionEventListener(*this);
67 __pButtonStart->SetEnabled(true);
70 __pButtonStop = static_cast< Button* >(GetControl(L"IDC_BUTTON_STOP"));
71 if (__pButtonStop != null)
73 __pButtonStop->SetActionId(ID_BUTTON_STOP);
74 __pButtonStop->AddActionEventListener(*this);
75 __pButtonStop->SetEnabled(false);
78 __pButtonCancel = static_cast< Button* >(GetControl(L"IDC_BUTTON_CANCEL"));
79 if (__pButtonCancel != null)
81 __pButtonCancel->SetActionId(ID_BUTTON_CANCEL);
82 __pButtonCancel->AddActionEventListener(*this);
83 __pButtonCancel->SetEnabled(false);
86 __pLabel = static_cast< Label* >(GetControl(L"IDC_LABEL_INFO"));
89 __pLabel->SetText("Information box");
92 __pStt = new (std::nothrow) SpeechToText();
95 r = __pStt->Construct(*this);
96 TryLog(r == E_SUCCESS, "[%s] Construct() error", GetErrorMessage(r));
98 r = __pStt->Initialize();
99 TryLog(r == E_SUCCESS, "[%s] Initialize() error", GetErrorMessage(r));
103 SceneManager* pSceneManager = SceneManager::GetInstance();
104 AppAssert(pSceneManager);
105 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT));
108 SetOrientation(ORIENTATION_PORTRAIT);
114 SpeechAppSttForm::OnTerminating(void)
116 result r = E_SUCCESS;
124 SpeechAppSttForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
126 result r = E_SUCCESS;
128 SceneManager* pSceneManager = SceneManager::GetInstance();
129 AppAssert(pSceneManager);
133 case ID_BUTTON_START:
137 AppLog("[%s] Start() error", GetErrorMessage(r));
141 __pButtonStart->SetEnabled(false);
142 __pButtonStop->SetEnabled(true);
143 __pButtonCancel->SetEnabled(true);
145 __pLabel->SetText("Recording Speech....");
155 AppLog("[%s] Stop() error", GetErrorMessage(r));
159 __pButtonStart->SetEnabled(false);
160 __pButtonStop->SetEnabled(false);
161 __pButtonCancel->SetEnabled(true);
162 __pLabel->SetText("Converting Speech....");
168 case ID_BUTTON_CANCEL:
169 r = __pStt->Cancel();
170 TryLog(r == E_SUCCESS, "[%s] Cancel() error", GetErrorMessage(r));
172 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT));
181 SpeechAppSttForm::OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList* pArgs)
185 case REQUEST_ID_EXIT:
195 SpeechAppSttForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
197 SceneManager* pSceneManager = SceneManager::GetInstance();
198 AppAssert(pSceneManager);
200 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT));
204 SpeechAppSttForm::OnSpeechToTextInitialized(void)
206 Tizen::Ui::Controls::ListView* pList = static_cast< ListView* >(GetControl(L"IDC_LISTVIEW_LANGS"));
209 pList->SetItemProvider(*this);
210 pList->AddListViewItemEventListener(*this);
214 __pStt->SetLocale(Locale(LANGUAGE_ENG, COUNTRY_US));
217 __pLabel->SetText("Default Language: eng_US");
222 SpeechAppSttForm::OnSpeechToTextStatusChanged(Tizen::Uix::Speech::SpeechToTextStatus status)
227 SpeechAppSttForm::OnSpeechToTextErrorOccurred(Tizen::Uix::Speech::SpeechToTextError error)
229 if (error == SPEECH_TO_TEXT_ERROR_UNSUPPORTED_SERVICE)
231 this->SendUserEvent(REQUEST_ID_EXIT, null);
236 SpeechAppSttForm::OnSpeechToTextCompleted(const Tizen::Base::String& result)
238 SceneManager* pSceneManager = SceneManager::GetInstance();
239 AppAssert(pSceneManager);
241 IList* pList = new (std::nothrow) ArrayList();
242 pList->Add(*(new (std::nothrow) String(result)));
243 pList->Add(*(new (std::nothrow) Locale(__pStt->GetLocale())));
244 pSceneManager->GoForward(ForwardSceneTransition(L"TtsScene", SCENE_TRANSITION_ANIMATION_TYPE_LEFT, SCENE_HISTORY_OPTION_NO_HISTORY, SCENE_DESTROY_OPTION_DESTROY), pList);
248 SpeechAppSttForm::ShowMsgBox(void)
250 SceneManager* pSceneManager = SceneManager::GetInstance();
251 AppAssert(pSceneManager);
253 MessageBox messageBox;
254 messageBox.Construct(L"Error", L"Unsupported service.", MSGBOX_STYLE_OK);
257 messageBox.ShowAndWait(result);
261 case MSGBOX_RESULT_OK:
262 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT));
270 Tizen::Ui::Controls::ListItemBase*
271 SpeechAppSttForm::CreateItem(int index, int itemWidth)
273 ListAnnexStyle style = LIST_ANNEX_STYLE_NORMAL;
274 CustomItem* pItem = new (std::nothrow) CustomItem();
275 pItem->Construct(Tizen::Graphics::Dimension(itemWidth, 100), style);
277 const IList* pList = __pStt->GetSupportedLocales();
278 const Locale* pLocale = static_cast< const Locale* >(pList->GetAt(index));
280 pItem->AddElement(Rectangle(10, 25, itemWidth, 50), index, pLocale->GetLocaleCodeString(), true);
286 SpeechAppSttForm::DeleteItem(int index, Tizen::Ui::Controls::ListItemBase* pItem, int itemWidth)
295 SpeechAppSttForm::GetItemCount(void)
297 return __pStt->GetSupportedLocales()->GetCount();
301 SpeechAppSttForm::OnListViewContextItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId, Tizen::Ui::Controls::ListContextItemStatus state)
306 SpeechAppSttForm::OnListViewItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId, Tizen::Ui::Controls::ListItemStatus status)
308 const IList* pList = __pStt->GetSupportedLocales();
309 const Locale* pLocale = static_cast< const Locale* >(pList->GetAt(index));
311 result r = __pStt->SetLocale(*pLocale);
312 TryLog(r == E_SUCCESS, "[%s] Error occurred", GetErrorMessage(r));
314 __pLabel->SetText(String("Selected Language: ") + pLocale->GetLocaleCodeString().GetPointer());
319 SpeechAppSttForm::OnListViewItemSwept(Tizen::Ui::Controls::ListView& listView, int index, Tizen::Ui::Controls::SweepDirection direction)
324 SpeechAppSttForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId,
325 const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
327 AppLog("OnSceneActivatedN()");
330 SpeechAppSttForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId,
331 const Tizen::Ui::Scenes::SceneId& nextSceneId)
333 AppLog("OnSceneActivatedN()");