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 Osp::Base;
24 using namespace Osp::Base::Collection;
25 using namespace Osp::Ui;
26 using namespace Osp::Ui::Controls;
27 using namespace Osp::Ui::Scenes;
28 using namespace Osp::Uix::Speech;
29 using namespace Osp::Graphics;
30 using namespace Osp::Locales;
33 SpeechAppSttForm::SpeechAppSttForm(void)
36 , __pButtonStart(null)
38 , __pButtonCancel(null)
43 SpeechAppSttForm::~SpeechAppSttForm(void)
48 SpeechAppSttForm::Initialize()
50 Construct(L"IDF_FORM_STT");
56 SpeechAppSttForm::OnInitializing(void)
60 // TODO: Add your initialization code here
62 SetFormBackEventListener(this);
64 __pButtonStart = static_cast<Button*>(GetControl(L"IDC_BUTTON_START"));
65 if (__pButtonStart != null)
67 __pButtonStart->SetActionId(ID_BUTTON_START);
68 __pButtonStart->AddActionEventListener(*this);
69 __pButtonStart->SetEnabled(true);
72 __pButtonStop = static_cast<Button*>(GetControl(L"IDC_BUTTON_STOP"));
73 if (__pButtonStop != null)
75 __pButtonStop->SetActionId(ID_BUTTON_STOP);
76 __pButtonStop->AddActionEventListener(*this);
77 __pButtonStop->SetEnabled(false);
80 __pButtonCancel = static_cast<Button*>(GetControl(L"IDC_BUTTON_CANCEL"));
81 if (__pButtonCancel != null)
83 __pButtonCancel->SetActionId(ID_BUTTON_CANCEL);
84 __pButtonCancel->AddActionEventListener(*this);
85 __pButtonCancel->SetEnabled(false);
88 __pLabel = static_cast<Label*>(GetControl(L"IDC_LABEL_INFO"));
91 __pLabel->SetText("Information box");
94 __pStt = new SpeechToText();
97 r = __pStt->Construct(*this);
100 AppLog("[%s] Construct() error", GetErrorMessage(r));
103 r = __pStt->Initialize();
106 AppLog("[%s] Initialize() error", GetErrorMessage(r));
111 SceneManager* pSceneManager = SceneManager::GetInstance();
112 AppAssert(pSceneManager);
113 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT));
120 SpeechAppSttForm::OnTerminating(void)
122 result r = E_SUCCESS;
130 SpeechAppSttForm::OnActionPerformed(const Osp::Ui::Control& source, int actionId)
132 result r = E_SUCCESS;
134 SceneManager* pSceneManager = SceneManager::GetInstance();
135 AppAssert(pSceneManager);
139 case ID_BUTTON_START:
143 AppLog("[%s] Start() error", GetErrorMessage(r));
147 __pButtonStart->SetEnabled(false);
148 __pButtonStop->SetEnabled(true);
149 __pButtonCancel->SetEnabled(true);
151 __pLabel->SetText("Recording Speech....");
160 AppLog("[%s] Stop() error", GetErrorMessage(r));
164 __pButtonStart->SetEnabled(false);
165 __pButtonStop->SetEnabled(false);
166 __pButtonCancel->SetEnabled(true);
167 __pLabel->SetText("Converting Speech....");
172 case ID_BUTTON_CANCEL:
173 r = __pStt->Cancel();
176 AppLog("[%s] Cancle() error", GetErrorMessage(r));
178 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT));
187 SpeechAppSttForm::OnUserEventReceivedN(RequestId requestId, Osp::Base::Collection::IList* pArgs)
191 case REQUEST_ID_EXIT:
200 SpeechAppSttForm::OnFormBackRequested(Osp::Ui::Controls::Form& source)
202 SceneManager* pSceneManager = SceneManager::GetInstance();
203 AppAssert(pSceneManager);
205 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT));
209 SpeechAppSttForm::OnSpeechToTextInitialized(void)
211 Osp::Ui::Controls::ListView *pList = static_cast<ListView*>(GetControl(L"IDC_LISTVIEW_LANGS"));
214 pList->SetItemProvider(*this);
215 pList->AddListViewItemEventListener(*this);
219 __pStt->SetLocale(Locale(LANGUAGE_ENG, COUNTRY_US));
222 __pLabel->SetText("Default Language: eng_US");
227 SpeechAppSttForm::OnSpeechToTextStatusChanged(Osp::Uix::Speech::SpeechToTextStatus status)
232 SpeechAppSttForm::OnSpeechToTextErrorOccurred(Osp::Uix::Speech::SpeechToTextError error)
234 if (error == SPEECH_TO_TEXT_ERROR_UNSUPPORTED_SERVICE)
236 this->SendUserEvent(REQUEST_ID_EXIT, null);
241 SpeechAppSttForm::OnSpeechToTextCompleted(const Osp::Base::String& result)
243 SceneManager* pSceneManager = SceneManager::GetInstance();
244 AppAssert(pSceneManager);
246 IList* pList = new ArrayList();
247 pList->Add(*(new String(result)));
248 pList->Add(*(new Locale(__pStt->GetLocale())));
249 pSceneManager->GoForward(ForwardSceneTransition(L"TtsScene", SCENE_TRANSITION_ANIMATION_TYPE_LEFT, SCENE_HISTORY_OPTION_NO_HISTORY, SCENE_DESTROY_OPTION_DESTROY), pList);
253 SpeechAppSttForm::ShowMsgBox(void)
255 SceneManager* pSceneManager = SceneManager::GetInstance();
256 AppAssert(pSceneManager);
258 MessageBox messageBox;
259 messageBox.Construct(L"Error", L"Unsupported service.", MSGBOX_STYLE_OK);
262 messageBox.ShowAndWait(result);
266 case MSGBOX_RESULT_OK:
267 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT));
274 Osp::Ui::Controls::ListItemBase*
275 SpeechAppSttForm::CreateItem(int index, int itemWidth)
277 ListAnnexStyle style = LIST_ANNEX_STYLE_NORMAL;
278 CustomItem* pItem = new CustomItem();
279 pItem->Construct(Osp::Graphics::Dimension(itemWidth, 100), style);
281 const IList* pList = __pStt->GetSupportedLocales();
282 const Locale* pLocale = static_cast<const Locale*>(pList->GetAt(index));
284 pItem->AddElement(Rectangle(10, 25, itemWidth, 50), index, pLocale->GetLocaleCodeString(), true);
290 SpeechAppSttForm::DeleteItem(int index, Osp::Ui::Controls::ListItemBase* pItem, int itemWidth)
299 SpeechAppSttForm::GetItemCount(void)
301 return __pStt->GetSupportedLocales()->GetCount();
305 SpeechAppSttForm::OnListViewContextItemStateChanged(Osp::Ui::Controls::ListView &listView, int index, int elementId, Osp::Ui::Controls::ListContextItemStatus state)
310 SpeechAppSttForm::OnListViewItemStateChanged(Osp::Ui::Controls::ListView &listView, int index, int elementId, Osp::Ui::Controls::ListItemStatus status)
313 const IList* pList = __pStt->GetSupportedLocales();
314 const Locale* pLocale = static_cast<const Locale*>(pList->GetAt(index));
316 result r = __pStt->SetLocale(*pLocale);
319 AppLog("[%s] Error occurred", GetErrorMessage(r));
322 __pLabel->SetText(String("Selected Language: ") + pLocale->GetLocaleCodeString().GetPointer());
328 SpeechAppSttForm::OnListViewItemSwept(Osp::Ui::Controls::ListView &listView, int index, Osp::Ui::Controls::SweepDirection direction)
333 SpeechAppSttForm::OnSceneActivatedN(const Osp::Ui::Scenes::SceneId& previousSceneId,
334 const Osp::Ui::Scenes::SceneId& currentSceneId, Osp::Base::Collection::IList* pArgs)
336 AppLog("OnSceneActivatedN()");
339 SpeechAppSttForm::OnSceneDeactivated(const Osp::Ui::Scenes::SceneId& currentSceneId,
340 const Osp::Ui::Scenes::SceneId& nextSceneId)
342 AppLog("OnSceneActivatedN()");