diff options
author | Kai Sommerfeld <kai.sommerfeld@gmx.com> | 2022-05-10 08:20:09 +0200 |
---|---|---|
committer | Kai Sommerfeld <kai.sommerfeld@gmx.com> | 2022-05-12 18:40:56 +0200 |
commit | 6f69d363d0dee6f608e0a650b9c821bfb286424b (patch) | |
tree | 7cb5e8a6b865663ea3a4f30482aede6a55af4de5 | |
parent | 99a4d44eb55763234bc9a4ffce471e1a039ebfed (diff) |
[speech] Add multiplatform support, make speech recognition available at Service Broker.
-rw-r--r-- | cmake/treedata/darwin_embedded/subdirs.txt | 1 | ||||
-rw-r--r-- | cmake/treedata/freebsd/subdirs.txt | 1 | ||||
-rw-r--r-- | cmake/treedata/linux/subdirs.txt | 1 | ||||
-rw-r--r-- | cmake/treedata/osx/subdirs.txt | 1 | ||||
-rw-r--r-- | cmake/treedata/windows/subdirs.txt | 1 | ||||
-rw-r--r-- | cmake/treedata/windowsstore/subdirs.txt | 1 | ||||
-rw-r--r-- | xbmc/Application.cpp | 5 | ||||
-rw-r--r-- | xbmc/ServiceBroker.cpp | 16 | ||||
-rw-r--r-- | xbmc/ServiceBroker.h | 11 | ||||
-rw-r--r-- | xbmc/dialogs/GUIDialogKeyboardGeneric.cpp | 24 | ||||
-rw-r--r-- | xbmc/platform/android/activity/XBMCApp.cpp | 2 | ||||
-rw-r--r-- | xbmc/platform/android/activity/XBMCApp.h | 11 | ||||
-rw-r--r-- | xbmc/platform/android/speech/SpeechRecognitionAndroid.cpp | 6 | ||||
-rw-r--r-- | xbmc/platform/common/speech/CMakeLists.txt | 5 | ||||
-rw-r--r-- | xbmc/platform/common/speech/SpeechRecognitionStub.cpp | 15 | ||||
-rw-r--r-- | xbmc/platform/common/speech/SpeechRecognitionStub.h | 22 | ||||
-rw-r--r-- | xbmc/speech/ISpeechRecognition.h | 2 |
17 files changed, 100 insertions, 25 deletions
diff --git a/cmake/treedata/darwin_embedded/subdirs.txt b/cmake/treedata/darwin_embedded/subdirs.txt index 52892f47c2..31cd9b9c09 100644 --- a/cmake/treedata/darwin_embedded/subdirs.txt +++ b/cmake/treedata/darwin_embedded/subdirs.txt @@ -2,6 +2,7 @@ xbmc/cores/RetroPlayer/process/ios cores/RetroPlayer/process/ios xbmc/cores/VideoPlayer/Process/ios cores/VideoPlayer/Process/ios xbmc/input/touch input/touch xbmc/input/touch/generic input/touch/generic +xbmc/platform/common/speech platform/common/speech xbmc/platform/darwin platform/darwin xbmc/platform/darwin/ios-common platform/ios-common xbmc/platform/darwin/ios-common/network platform/ios-common/network diff --git a/cmake/treedata/freebsd/subdirs.txt b/cmake/treedata/freebsd/subdirs.txt index 1e5515e9ab..d7d954e953 100644 --- a/cmake/treedata/freebsd/subdirs.txt +++ b/cmake/treedata/freebsd/subdirs.txt @@ -1,5 +1,6 @@ xbmc/input/touch input/touch xbmc/input/touch/generic input/touch/generic +xbmc/platform/common/speech platform/common/speech xbmc/platform/freebsd platform/freebsd xbmc/platform/freebsd/network platform/freebsd/network xbmc/platform/linux/input platform/linux/input diff --git a/cmake/treedata/linux/subdirs.txt b/cmake/treedata/linux/subdirs.txt index d25c36de51..a8e8194038 100644 --- a/cmake/treedata/linux/subdirs.txt +++ b/cmake/treedata/linux/subdirs.txt @@ -1,5 +1,6 @@ xbmc/input/touch input/touch xbmc/input/touch/generic input/touch/generic +xbmc/platform/common/speech platform/common/speech xbmc/platform/linux platform/linux xbmc/platform/linux/input platform/linux/input xbmc/platform/linux/network platform/linux/network diff --git a/cmake/treedata/osx/subdirs.txt b/cmake/treedata/osx/subdirs.txt index 9bee62332f..0c1ba717eb 100644 --- a/cmake/treedata/osx/subdirs.txt +++ b/cmake/treedata/osx/subdirs.txt @@ -1,5 +1,6 @@ xbmc/cores/RetroPlayer/process/osx cores/RetroPlayer/process/osx xbmc/cores/VideoPlayer/Process/osx cores/VideoPlayer/Process/osx +xbmc/platform/common/speech platform/common/speech xbmc/platform/darwin platform/darwin xbmc/platform/darwin/network platform/darwin/network xbmc/platform/darwin/osx platform/osx diff --git a/cmake/treedata/windows/subdirs.txt b/cmake/treedata/windows/subdirs.txt index 7b3ded3db6..c81ca86b2d 100644 --- a/cmake/treedata/windows/subdirs.txt +++ b/cmake/treedata/windows/subdirs.txt @@ -5,6 +5,7 @@ xbmc/cores/VideoPlayer/VideoRenderers/windows cores/VideoPlayer/VideoRenderers/w xbmc/input/touch input/touch xbmc/input/touch/generic input/touch/generic xbmc/network/mdns network/mdns +xbmc/platform/common/speech platform/common/speech xbmc/platform/win32 platform/win32 xbmc/platform/win32/filesystem platform/win32/filesystem xbmc/platform/win32/input platform/win32/input diff --git a/cmake/treedata/windowsstore/subdirs.txt b/cmake/treedata/windowsstore/subdirs.txt index f75f7c7406..16299fce2c 100644 --- a/cmake/treedata/windowsstore/subdirs.txt +++ b/cmake/treedata/windowsstore/subdirs.txt @@ -3,6 +3,7 @@ xbmc/cores/VideoPlayer/VideoRenderers/windows cores/VideoPlayer/VideoRenderers/w xbmc/input/touch input/touch xbmc/input/touch/generic input/touch/generic xbmc/network/mdns network/mdns +xbmc/platform/common/speech platform/common/speech xbmc/platform/win10 platform/win10 xbmc/platform/win10/filesystem platform/win10/filesystem xbmc/platform/win10/network platform/win10/network diff --git a/xbmc/Application.cpp b/xbmc/Application.cpp index 42cc02aa42..1c063006c1 100644 --- a/xbmc/Application.cpp +++ b/xbmc/Application.cpp @@ -86,6 +86,7 @@ #include "settings/SettingsComponent.h" #include "settings/SkinSettings.h" #include "settings/lib/SettingsManager.h" +#include "speech/ISpeechRecognition.h" #include "threads/SingleLock.h" #include "utils/CPUInfo.h" #include "utils/FileExtensionProvider.h" @@ -852,6 +853,8 @@ bool CApplication::Initialize() CJSONRPC::Initialize(); + CServiceBroker::RegisterSpeechRecognition(speech::ISpeechRecognition::CreateInstance()); + if (!m_ServiceManager->InitStageThree(profileManager)) { CLog::Log(LOGERROR, "Application - Init3 failed"); @@ -2148,6 +2151,8 @@ bool CApplication::Cleanup() if (m_ServiceManager) m_ServiceManager->DeinitStageThree(); + CServiceBroker::UnregisterSpeechRecognition(); + CLog::Log(LOGINFO, "unload skin"); UnloadSkin(); diff --git a/xbmc/ServiceBroker.cpp b/xbmc/ServiceBroker.cpp index 5bc649f302..e0011a9bcd 100644 --- a/xbmc/ServiceBroker.cpp +++ b/xbmc/ServiceBroker.cpp @@ -412,3 +412,19 @@ std::shared_ptr<CKeyboardLayoutManager> CServiceBroker::GetKeyboardLayoutManager { return g_serviceBroker.m_keyboardLayoutManager; } + +void CServiceBroker::RegisterSpeechRecognition( + const std::shared_ptr<speech::ISpeechRecognition>& speechRecognition) +{ + g_serviceBroker.m_speechRecognition = speechRecognition; +} + +void CServiceBroker::UnregisterSpeechRecognition() +{ + g_serviceBroker.m_speechRecognition.reset(); +} + +std::shared_ptr<speech::ISpeechRecognition> CServiceBroker::GetSpeechRecognition() +{ + return g_serviceBroker.m_speechRecognition; +} diff --git a/xbmc/ServiceBroker.h b/xbmc/ServiceBroker.h index ee0f5ac0cc..332d71b4f0 100644 --- a/xbmc/ServiceBroker.h +++ b/xbmc/ServiceBroker.h @@ -107,6 +107,11 @@ namespace PERIPHERALS class CPeripherals; } +namespace speech +{ +class ISpeechRecognition; +} + class CServiceBroker { public: @@ -204,6 +209,11 @@ public: static void UnregisterKeyboardLayoutManager(); static std::shared_ptr<CKeyboardLayoutManager> GetKeyboardLayoutManager(); + static void RegisterSpeechRecognition( + const std::shared_ptr<speech::ISpeechRecognition>& speechRecognition); + static void UnregisterSpeechRecognition(); + static std::shared_ptr<speech::ISpeechRecognition> GetSpeechRecognition(); + private: std::shared_ptr<CAppParams> m_appParams; std::unique_ptr<CLog> m_logging; @@ -219,6 +229,7 @@ private: std::shared_ptr<CJobManager> m_jobManager; std::shared_ptr<KODI::MESSAGING::CApplicationMessenger> m_appMessenger; std::shared_ptr<CKeyboardLayoutManager> m_keyboardLayoutManager; + std::shared_ptr<speech::ISpeechRecognition> m_speechRecognition; }; XBMC_GLOBAL_REF(CServiceBroker, g_serviceBroker); diff --git a/xbmc/dialogs/GUIDialogKeyboardGeneric.cpp b/xbmc/dialogs/GUIDialogKeyboardGeneric.cpp index 3f89a58a1b..3f0cf20765 100644 --- a/xbmc/dialogs/GUIDialogKeyboardGeneric.cpp +++ b/xbmc/dialogs/GUIDialogKeyboardGeneric.cpp @@ -37,10 +37,6 @@ #include <mutex> -#ifdef TARGET_ANDROID -#include "platform/android/activity/XBMCApp.h" -#endif - using namespace KODI::MESSAGING; #define BUTTON_ID_OFFSET 100 @@ -648,14 +644,18 @@ void CGUIDialogKeyboardGeneric::OnIPAddress() void CGUIDialogKeyboardGeneric::OnVoiceRecognition() { -#ifdef TARGET_ANDROID - if (!m_speechRecognitionListener) - m_speechRecognitionListener = std::make_shared<CSpeechRecognitionListener>(GetID()); - - CXBMCApp::Get().GetSpeechRecognition()->StartSpeechRecognition(m_speechRecognitionListener); -#else - CLog::LogF(LOGWARNING, "No voice recognition implementation avaliable for this platform."); -#endif + const auto speechRecognition = CServiceBroker::GetSpeechRecognition(); + if (speechRecognition) + { + if (!m_speechRecognitionListener) + m_speechRecognitionListener = std::make_shared<CSpeechRecognitionListener>(GetID()); + + speechRecognition->StartSpeechRecognition(m_speechRecognitionListener); + } + else + { + CLog::LogF(LOGWARNING, "No voice recognition implementation available."); + } } void CGUIDialogKeyboardGeneric::SetControlLabel(int id, const std::string &label) diff --git a/xbmc/platform/android/activity/XBMCApp.cpp b/xbmc/platform/android/activity/XBMCApp.cpp index e81b666a18..2dd0da57be 100644 --- a/xbmc/platform/android/activity/XBMCApp.cpp +++ b/xbmc/platform/android/activity/XBMCApp.cpp @@ -94,7 +94,6 @@ #include "platform/android/activity/IInputDeviceEventHandler.h" #include "platform/android/network/NetworkAndroid.h" #include "platform/android/powermanagement/AndroidPowerSyscall.h" -#include "platform/android/speech/SpeechRecognitionAndroid.h" #define GIGABYTES 1073741824 @@ -159,7 +158,6 @@ std::unique_ptr<CXBMCApp> CXBMCApp::m_appinstance; CXBMCApp::CXBMCApp(ANativeActivity* nativeActivity, IInputHandler& inputHandler) : CJNIMainActivity(nativeActivity), CJNIBroadcastReceiver(CJNIContext::getPackageName() + ".XBMCBroadcastReceiver"), - m_speechRecognition(new CSpeechRecognitionAndroid(*this)), m_inputHandler(inputHandler) { m_activity = nativeActivity; diff --git a/xbmc/platform/android/activity/XBMCApp.h b/xbmc/platform/android/activity/XBMCApp.h index e43dfdebef..f3ce2173c3 100644 --- a/xbmc/platform/android/activity/XBMCApp.h +++ b/xbmc/platform/android/activity/XBMCApp.h @@ -43,11 +43,6 @@ class IInputDeviceEventHandler; class CVideoSyncAndroid; class CJNIActivityManager; -namespace speech -{ -class ISpeechRecognition; -} - typedef struct _JNIEnv JNIEnv; struct androidIcon @@ -219,11 +214,6 @@ public: bool GetMemoryInfo(long& availMem, long& totalMem); - std::shared_ptr<speech::ISpeechRecognition> GetSpeechRecognition() const - { - return m_speechRecognition; - } - protected: // limit who can access Volume friend class CAESinkAUDIOTRACK; @@ -240,7 +230,6 @@ private: CJNIXBMCAudioManagerOnAudioFocusChangeListener m_audioFocusListener; CJNIXBMCDisplayManagerDisplayListener m_displayListener; - std::shared_ptr<speech::ISpeechRecognition> m_speechRecognition; std::unique_ptr<CJNIXBMCMainView> m_mainView; std::unique_ptr<jni::CJNIXBMCMediaSession> m_mediaSession; std::string GetFilenameFromIntent(const CJNIIntent &intent); diff --git a/xbmc/platform/android/speech/SpeechRecognitionAndroid.cpp b/xbmc/platform/android/speech/SpeechRecognitionAndroid.cpp index 9e0b2adb12..d2d0b7f4e5 100644 --- a/xbmc/platform/android/speech/SpeechRecognitionAndroid.cpp +++ b/xbmc/platform/android/speech/SpeechRecognitionAndroid.cpp @@ -13,6 +13,7 @@ #include "utils/log.h" #include "platform/android/activity/JNIMainActivity.h" +#include "platform/android/activity/XBMCApp.h" #include "platform/android/speech/SpeechRecognitionListenerAndroid.h" #include <mutex> @@ -25,6 +26,11 @@ #include <androidjni/SpeechRecognizer.h> #include <jni.h> +std::shared_ptr<speech::ISpeechRecognition> speech::ISpeechRecognition::CreateInstance() +{ + return std::make_shared<CSpeechRecognitionAndroid>(CXBMCApp::Get()); +} + CSpeechRecognitionAndroid::CSpeechRecognitionAndroid(const CJNIContext& context) : m_context(context) { diff --git a/xbmc/platform/common/speech/CMakeLists.txt b/xbmc/platform/common/speech/CMakeLists.txt new file mode 100644 index 0000000000..ac9752bf22 --- /dev/null +++ b/xbmc/platform/common/speech/CMakeLists.txt @@ -0,0 +1,5 @@ +set(SOURCES SpeechRecognitionStub.cpp) + +set(HEADERS SpeechRecognitionStub.h) + +core_add_library(platform_common_speech) diff --git a/xbmc/platform/common/speech/SpeechRecognitionStub.cpp b/xbmc/platform/common/speech/SpeechRecognitionStub.cpp new file mode 100644 index 0000000000..2f76863153 --- /dev/null +++ b/xbmc/platform/common/speech/SpeechRecognitionStub.cpp @@ -0,0 +1,15 @@ +/* + * Copyright (C) 2012-2022 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#include "SpeechRecognitionStub.h" + +std::shared_ptr<speech::ISpeechRecognition> speech::ISpeechRecognition::CreateInstance() +{ + // speech recognition not implemented + return {}; +} diff --git a/xbmc/platform/common/speech/SpeechRecognitionStub.h b/xbmc/platform/common/speech/SpeechRecognitionStub.h new file mode 100644 index 0000000000..ec44bc58fa --- /dev/null +++ b/xbmc/platform/common/speech/SpeechRecognitionStub.h @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2012-2022 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#pragma once + +#include "speech/ISpeechRecognition.h" + +// This is a stub for all platforms without a speech recognition implementation +// Saves us from feature/platform ifdeffery. +class CSpeechRecognitionStub : public speech::ISpeechRecognition +{ +public: + void StartSpeechRecognition( + const std::shared_ptr<speech::ISpeechRecognitionListener>& listener) override + { + } +}; diff --git a/xbmc/speech/ISpeechRecognition.h b/xbmc/speech/ISpeechRecognition.h index 7cf09efcf7..e4c4fcb5f6 100644 --- a/xbmc/speech/ISpeechRecognition.h +++ b/xbmc/speech/ISpeechRecognition.h @@ -17,6 +17,8 @@ class ISpeechRecognitionListener; class ISpeechRecognition { public: + static std::shared_ptr<speech::ISpeechRecognition> CreateInstance(); + virtual ~ISpeechRecognition() = default; virtual void StartSpeechRecognition( |