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"
22 #include "AppResourceId.h"
24 using namespace Tizen::Base;
25 using namespace Tizen::Base::Collection;
26 using namespace Tizen::Ui;
27 using namespace Tizen::Ui::Controls;
28 using namespace Tizen::Ui::Scenes;
29 using namespace Tizen::Uix::Speech;
30 using namespace Tizen::Graphics;
31 using namespace Tizen::Locales;
34 SpeechAppSttForm::SpeechAppSttForm(void)
37 , __pButtonStart(null)
39 , __pButtonCancel(null)
44 SpeechAppSttForm::~SpeechAppSttForm(void)
49 SpeechAppSttForm::Initialize(void)
51 Construct(IDF_FORM_STT);
57 SpeechAppSttForm::OnInitializing(void)
61 SetFormBackEventListener(this);
63 __pButtonStart = static_cast< Button* >(GetControl(IDC_BUTTON_START));
64 if (__pButtonStart != null)
66 __pButtonStart->SetActionId(ID_BUTTON_START);
67 __pButtonStart->AddActionEventListener(*this);
68 __pButtonStart->SetEnabled(true);
71 __pButtonStop = static_cast< Button* >(GetControl(IDC_BUTTON_STOP));
72 if (__pButtonStop != null)
74 __pButtonStop->SetActionId(ID_BUTTON_STOP);
75 __pButtonStop->AddActionEventListener(*this);
76 __pButtonStop->SetEnabled(false);
79 __pButtonCancel = static_cast< Button* >(GetControl(IDC_BUTTON_CANCEL));
80 if (__pButtonCancel != null)
82 __pButtonCancel->SetActionId(ID_BUTTON_CANCEL);
83 __pButtonCancel->AddActionEventListener(*this);
84 __pButtonCancel->SetEnabled(false);
87 __pLabel = static_cast< Label* >(GetControl(IDC_LABEL_INFO));
90 __pLabel->SetText("Information box");
93 __pStt = new (std::nothrow) SpeechToText();
96 r = __pStt->Construct(*this);
97 TryLog(r == E_SUCCESS, "[%s] Construct() error", GetErrorMessage(r));
99 r = __pStt->Initialize();
100 TryLog(r == E_SUCCESS, "[%s] Initialize() error", GetErrorMessage(r));
104 SceneManager* pSceneManager = SceneManager::GetInstance();
105 AppAssert(pSceneManager);
106 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT));
109 SetOrientation(ORIENTATION_PORTRAIT);
115 SpeechAppSttForm::OnTerminating(void)
117 result r = E_SUCCESS;
125 SpeechAppSttForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
127 result r = E_SUCCESS;
129 SceneManager* pSceneManager = SceneManager::GetInstance();
130 AppAssert(pSceneManager);
134 case ID_BUTTON_START:
138 AppLog("[%s] Start() error", GetErrorMessage(r));
142 __pButtonStart->SetEnabled(false);
143 __pButtonStop->SetEnabled(true);
144 __pButtonCancel->SetEnabled(true);
146 __pLabel->SetText("Recording Speech....");
156 AppLog("[%s] Stop() error", GetErrorMessage(r));
160 __pButtonStart->SetEnabled(false);
161 __pButtonStop->SetEnabled(false);
162 __pButtonCancel->SetEnabled(true);
163 __pLabel->SetText("Converting Speech....");
169 case ID_BUTTON_CANCEL:
170 r = __pStt->Cancel();
171 TryLog(r == E_SUCCESS, "[%s] Cancel() error", GetErrorMessage(r));
173 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT));
182 SpeechAppSttForm::OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList* pArgs)
186 case REQUEST_ID_EXIT:
196 SpeechAppSttForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
198 SceneManager* pSceneManager = SceneManager::GetInstance();
199 AppAssert(pSceneManager);
201 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT));
205 SpeechAppSttForm::OnSpeechToTextInitialized(void)
207 Tizen::Ui::Controls::ListView* pList = static_cast< ListView* >(GetControl(IDC_LISTVIEW_LANGS));
210 pList->SetItemProvider(*this);
211 pList->AddListViewItemEventListener(*this);
215 __pStt->SetLocale(Locale(LANGUAGE_ENG, COUNTRY_US));
218 __pLabel->SetText("Default Language: eng_US");
223 SpeechAppSttForm::OnSpeechToTextStatusChanged(Tizen::Uix::Speech::SpeechToTextStatus status)
228 SpeechAppSttForm::OnSpeechToTextErrorOccurred(Tizen::Uix::Speech::SpeechToTextError error)
230 if (error == SPEECH_TO_TEXT_ERROR_UNSUPPORTED_SERVICE)
232 this->SendUserEvent(REQUEST_ID_EXIT, null);
237 SpeechAppSttForm::OnSpeechToTextCompleted(const Tizen::Base::String& result)
239 SceneManager* pSceneManager = SceneManager::GetInstance();
240 AppAssert(pSceneManager);
242 IList* pList = new (std::nothrow) ArrayList();
243 pList->Add(*(new (std::nothrow) String(result)));
244 pList->Add(*(new (std::nothrow) Locale(__pStt->GetLocale())));
245 pSceneManager->GoForward(ForwardSceneTransition(L"TtsScene", SCENE_TRANSITION_ANIMATION_TYPE_LEFT, SCENE_HISTORY_OPTION_NO_HISTORY, SCENE_DESTROY_OPTION_DESTROY), pList);
249 SpeechAppSttForm::ShowMsgBox(void)
251 SceneManager* pSceneManager = SceneManager::GetInstance();
252 AppAssert(pSceneManager);
254 MessageBox messageBox;
255 messageBox.Construct(L"Error", L"Unsupported service.", MSGBOX_STYLE_OK);
258 messageBox.ShowAndWait(result);
262 case MSGBOX_RESULT_OK:
263 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT));
271 Tizen::Ui::Controls::ListItemBase*
272 SpeechAppSttForm::CreateItem(int index, int itemWidth)
274 ListAnnexStyle style = LIST_ANNEX_STYLE_NORMAL;
275 CustomItem* pItem = new (std::nothrow) CustomItem();
276 pItem->Construct(Tizen::Graphics::Dimension(itemWidth, 100), style);
278 const IList* pList = __pStt->GetSupportedLocales();
279 const Locale* pLocale = static_cast< const Locale* >(pList->GetAt(index));
281 pItem->AddElement(Rectangle(10, 25, itemWidth, 50), index, pLocale->GetLocaleCodeString(), true);
287 SpeechAppSttForm::DeleteItem(int index, Tizen::Ui::Controls::ListItemBase* pItem, int itemWidth)
296 SpeechAppSttForm::GetItemCount(void)
298 return __pStt->GetSupportedLocales()->GetCount();
302 SpeechAppSttForm::OnListViewContextItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId, Tizen::Ui::Controls::ListContextItemStatus state)
307 SpeechAppSttForm::OnListViewItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId, Tizen::Ui::Controls::ListItemStatus status)
309 const IList* pList = __pStt->GetSupportedLocales();
310 const Locale* pLocale = static_cast< const Locale* >(pList->GetAt(index));
312 result r = __pStt->SetLocale(*pLocale);
313 TryLog(r == E_SUCCESS, "[%s] Error occurred", GetErrorMessage(r));
315 __pLabel->SetText(String("Selected Language: ") + pLocale->GetLocaleCodeString().GetPointer());
320 SpeechAppSttForm::OnListViewItemSwept(Tizen::Ui::Controls::ListView& listView, int index, Tizen::Ui::Controls::SweepDirection direction)
325 SpeechAppSttForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId,
326 const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
328 AppLog("OnSceneActivatedN()");
331 SpeechAppSttForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId,
332 const Tizen::Ui::Scenes::SceneId& nextSceneId)
334 AppLog("OnSceneActivatedN()");