diff --git a/source/armarx/speech/CMakeLists.txt b/source/armarx/speech/CMakeLists.txt index cd0e3f850fad4f81057c8dafd4942b591d9f4981..cbcfad554211cc61d857836ce3e97a8fc24b4fa5 100644 --- a/source/armarx/speech/CMakeLists.txt +++ b/source/armarx/speech/CMakeLists.txt @@ -2,3 +2,6 @@ add_subdirectory(core) add_subdirectory(skills) add_subdirectory(components) + +add_subdirectory(gui) +add_subdirectory(qt_plugins) diff --git a/source/armarx/speech/gui/CMakeLists.txt b/source/armarx/speech/gui/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..9b652a4d275b8ab3f2fc6d4b51f32b01eac03041 --- /dev/null +++ b/source/armarx/speech/gui/CMakeLists.txt @@ -0,0 +1,56 @@ +# Comment in to add an ARON library. +# armarx_add_aron_library(gui_aron +# ARON_FILES +# aron/MyAronType.xml +# ) + +armarx_add_library(gui + SOURCES + RecognizedTextWidget.cpp + TextInputWidget.cpp + TextListenerWidget.cpp + TextToSpeechInputWidget.cpp + + memory/SpeechToTextInputWidget.cpp + memory/SpeechToTextDisplayWidget.cpp + memory/TextDisplayWidget.cpp + memory/TextToSpeechInputWidget.cpp + memory/TextToSpeechDisplayWidget.cpp + HEADERS + RecognizedTextWidget.h + TextInputWidget.h + TextListenerWidget.h + TextToSpeechInputWidget.h + + memory/SpeechToTextInputWidget.h + memory/SpeechToTextDisplayWidget.h + memory/TextDisplayWidget.h + memory/TextToSpeechInputWidget.h + memory/TextToSpeechDisplayWidget.h + DEPENDENCIES_PUBLIC + # ArmarXCore + ArmarXCoreInterfaces + ArmarXCore + + RobotAPIInterfaces + armem_gui + + armarx_speech::core + + Qt5::Core + Qt5::Widgets + # speech + # speech::gui_aron + # DEPENDENCIES_PRIVATE + # ... + # DEPENDENCIES_INTERFACE + # ... + # DEPENDENCIES_LEGACY_PUBLIC + # ... + # DEPENDENCIES_LEGACY_PRIVATE + # ... + # DEPENDENCIES_LEGACY_INTERFACE + # ... +) + +set_target_properties(gui PROPERTIES AUTOMOC ON) diff --git a/source/armarx/speech/gui/RecognizedTextWidget.cpp b/source/armarx/speech/gui/RecognizedTextWidget.cpp new file mode 100644 index 0000000000000000000000000000000000000000..78952bdf57e619fc5988268cab2e1d285132a39d --- /dev/null +++ b/source/armarx/speech/gui/RecognizedTextWidget.cpp @@ -0,0 +1,50 @@ +/* + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @package SpeechX::ArmarXObjects::gui + * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu ) + * @date 2021 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#include "RecognizedTextWidget.h" + +#include <SimoxUtility/json.h> + + +namespace armarx::speech::gui +{ + + RecognizedTextWidget::RecognizedTextWidget(const std::string& topicName) : + TextListenerWidget(topicName) + { + } + + RecognizedTextWidget::RecognizedTextWidget(QLineEdit* recognizedText, + const std::string& topicName) : + TextListenerWidget(recognizedText, topicName) + { + } + + void + RecognizedTextWidget::reportText(const std::string& text) + { + const nlohmann::json j = nlohmann::json::parse(text); + emit textChanged(QString::fromStdString(j.at("text").get<std::string>())); + } + + +} // namespace armarx::speech::gui diff --git a/source/armarx/speech/gui/RecognizedTextWidget.h b/source/armarx/speech/gui/RecognizedTextWidget.h new file mode 100644 index 0000000000000000000000000000000000000000..b96fc2ddc0847372c9e7bd55401e40e8d57dc6b5 --- /dev/null +++ b/source/armarx/speech/gui/RecognizedTextWidget.h @@ -0,0 +1,58 @@ +/* + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @package SpeechX::ArmarXObjects::gui + * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu ) + * @date 2021 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +#include <string> + +#include <armarx/speech/gui/TextListenerWidget.h> + + +class QLineEdit; + + +namespace armarx::speech::gui +{ + class RecognizedTextWidget : public TextListenerWidget + { + Q_OBJECT + using This = RecognizedTextWidget; + + public: + RecognizedTextWidget(const std::string& topicName = "Speech_Commands"); + RecognizedTextWidget(QLineEdit* recognizedText, + const std::string& topicName = "Speech_Commands"); + + + public slots: + + void reportText(const std::string& text) override; + + + signals: + + + private: + void init(); + }; + +} // namespace armarx::speech::gui diff --git a/source/armarx/speech/gui/TextInputWidget.cpp b/source/armarx/speech/gui/TextInputWidget.cpp new file mode 100644 index 0000000000000000000000000000000000000000..51e2626ae5e9ef6458cf5b3273b05851b6fbad12 --- /dev/null +++ b/source/armarx/speech/gui/TextInputWidget.cpp @@ -0,0 +1,125 @@ +/* + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @package SpeechX::ArmarXObjects::gui + * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu ) + * @date 2021 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#include "TextInputWidget.h" + +#include <QComboBox> +#include <QHBoxLayout> +#include <QLineEdit> +#include <QPushButton> +#include <QSettings> + +#include <ArmarXCore/core/ManagedIceObject.h> + + +namespace armarx::speech::gui +{ + + TextInputWidget::TextInputWidget(const QString& settingsApplication) : + settings("KIT", settingsApplication) + { + textInput = new QComboBox(); + textInput->setSizePolicy(QSizePolicy::Policy::MinimumExpanding, QSizePolicy::Policy::Fixed); + textInput->setMouseTracking(true); + textInput->setAcceptDrops(true); + textInput->setFocusPolicy(Qt::FocusPolicy::StrongFocus); + textInput->setInsertPolicy(QComboBox::InsertPolicy::InsertAtTop); + textInput->setEditable(true); + + sendButton = new QPushButton("Send"); + + setLayout(new QHBoxLayout()); + layout()->addWidget(textInput); + layout()->addWidget(sendButton); + + init(); + } + + TextInputWidget::~TextInputWidget() = default; + + + TextInputWidget::TextInputWidget(const QString& settingsApplication, + QComboBox* textInput, + QPushButton* sendButton) : + textInput(textInput), sendButton(sendButton), settings("KIT", settingsApplication) + { + init(); + } + + + void + TextInputWidget::init() + { + connect(sendButton, &QPushButton::clicked, this, QOverload<>::of(&This::sendCurrentText)); + + const QLineEdit* lineEdit = textInput->lineEdit(); + if (lineEdit != nullptr) + { + // This needs to be separate, since pressing enter automatically adds a new item to the model. + connect( + lineEdit, &QLineEdit::returnPressed, this, QOverload<>::of(&This::sendCurrentText)); + } + + history = settings.value("history", QStringList{}).toStringList(); + + textInput->addItem(""); + for (const QString& entry : history) + { + textInput->insertItem(textInput->count(), entry); + } + } + + + void + TextInputWidget::sendCurrentText() + { + QString currentText = textInput->currentText(); + if (currentText.isEmpty()) + { + return; + } + + int pos = textInput->findText(currentText, Qt::MatchExactly); + // Move item to first position, so that list is ordered by time + if (pos != -1) + { + textInput->removeItem(pos); + } + textInput->insertItem(0, currentText); + textInput->setCurrentIndex(0); + if (currentText.size() != 0) + { + history.push_front(currentText); + history.removeDuplicates(); + + while (history.size() >= 25) + { + history.removeLast(); + } + + settings.setValue("history", history); + } + + sendText(currentText); + } + +} // namespace armarx::speech::gui diff --git a/source/armarx/speech/gui/TextInputWidget.h b/source/armarx/speech/gui/TextInputWidget.h new file mode 100644 index 0000000000000000000000000000000000000000..97c289beb7aba8154cb414e3c7533425c74865ee --- /dev/null +++ b/source/armarx/speech/gui/TextInputWidget.h @@ -0,0 +1,90 @@ +/* + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @package SpeechX::ArmarXObjects::gui + * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu ) + * @date 2021 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +#include <QSettings> +#include <QWidget> + +#include <ArmarXCore/core/logging/Logging.h> + +#include <RobotAPI/libraries/armem_gui/lifecycle.h> + + +class QComboBox; +class QPushButton; + + +namespace armarx +{ + class ManagedIceObject; + class SimpleConfigDialog; +} // namespace armarx + +namespace armarx::speech::gui +{ + class TextInputWidget : + public QWidget, + public armarx::Logging, + public armarx::gui::LifecycleClient + { + Q_OBJECT + using This = TextInputWidget; + + public: + TextInputWidget(const QString& settingsApplication); + TextInputWidget(const QString& settingsApplication, + QComboBox* textInput, + QPushButton* sendButton); + ~TextInputWidget(); + + + signals: + + void initialized(); + void connected(); + void disconnected(); + + + private slots: + + void sendCurrentText(); + + virtual void sendText(QString text) = 0; + + signals: + + + private: + void init(); + + public: + QStringList history; + + + QComboBox* textInput; + QPushButton* sendButton; + + QSettings settings; + }; + +} // namespace armarx::speech::gui diff --git a/source/armarx/speech/gui/TextListenerWidget.cpp b/source/armarx/speech/gui/TextListenerWidget.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d814c8f44bd05db168a0703de5a1d252c8642cc3 --- /dev/null +++ b/source/armarx/speech/gui/TextListenerWidget.cpp @@ -0,0 +1,100 @@ +/* + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @package SpeechX::ArmarXObjects::gui + * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu ) + * @date 2021 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#include "TextListenerWidget.h" + +#include <QHBoxLayout> +#include <QLineEdit> + +#include <ArmarXCore/core/ManagedIceObject.h> + + +namespace armarx::speech::gui +{ + + TextListenerWidget::TextListenerWidget(const std::string& topicName) : _topicName(topicName) + { + _text = new QLineEdit(); + + setLayout(new QHBoxLayout()); + layout()->addWidget(_text); + + init(); + } + + TextListenerWidget::TextListenerWidget(QLineEdit* recognizedText, + const std::string& topicName) : + _topicName(topicName), _text(recognizedText) + { + init(); + } + + QLineEdit* + TextListenerWidget::text() const + { + return _text; + } + + std::string + TextListenerWidget::topicName() const + { + return _topicName; + } + + void + TextListenerWidget::init() + { + connect(this, &This::textChanged, _text, &QLineEdit::setText); + } + + + void + TextListenerWidget::onInit(ManagedIceObject& component) + { + (void)component; + } + + void + TextListenerWidget::onConnect(ManagedIceObject& component) + { + auto callback = [this](const speech::TextListener::Message& msg, speech::TextListener& /*unused*/) + { this->reportText(msg.text); }; + _textTistener = speech::TextListener::addNew(component, _topicName, callback); + } + + void + TextListenerWidget::onDisconnect(ManagedIceObject& component) + { + if (_textTistener) + { + speech::TextListener::remove(component, _textTistener); + _textTistener = nullptr; + } + } + + void + TextListenerWidget::reportText(const std::string& text) + { + emit textChanged(QString::fromStdString(text)); + } + +} // namespace armarx::speech::gui diff --git a/source/armarx/speech/gui/TextListenerWidget.h b/source/armarx/speech/gui/TextListenerWidget.h new file mode 100644 index 0000000000000000000000000000000000000000..904b0177c0ed56b987cc5c506d928c649e8214c3 --- /dev/null +++ b/source/armarx/speech/gui/TextListenerWidget.h @@ -0,0 +1,96 @@ +/* + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @package SpeechX::ArmarXObjects::gui + * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu ) + * @date 2021 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +#include <QSettings> +#include <QWidget> + +#include <ArmarXCore/core/logging/Logging.h> + +#include <RobotAPI/interface/speech/SpeechInterface.h> +#include <RobotAPI/libraries/armem_gui/lifecycle.h> + +#include <armarx/speech/core/TextListener.h> + + +class QLineEdit; + + +namespace armarx +{ + class ManagedIceObject; +} + +namespace armarx::speech::gui +{ + class TextListenerWidget : + public QWidget, + public armarx::Logging, + public armarx::gui::LifecycleClient + { + Q_OBJECT + using This = TextListenerWidget; + + public: + TextListenerWidget(const std::string& topicName); + TextListenerWidget(QLineEdit* recognizedText, const std::string& topicName); + + + using LifecycleClient::onConnect; + using LifecycleClient::onDisconnect; + using LifecycleClient::onInit; + void onInit(ManagedIceObject& component) override; + void onConnect(ManagedIceObject& component) override; + void onDisconnect(ManagedIceObject& component) override; + + + QLineEdit* text() const; + std::string topicName() const; + + + public slots: + + virtual void reportText(const std::string& text); + + + signals: + + void initialized(); + void connected(); + void disconnected(); + + void textChanged(const QString& text); + + + private: + void init(); + + + private: + std::string _topicName; + TextListenerPtr _textTistener; + + QLineEdit* _text; + }; + +} // namespace armarx::speech::gui diff --git a/source/armarx/speech/gui/TextToSpeechInputWidget.cpp b/source/armarx/speech/gui/TextToSpeechInputWidget.cpp new file mode 100644 index 0000000000000000000000000000000000000000..422043fe2a989b06679d2dcbecfb2d8fd1f7ce03 --- /dev/null +++ b/source/armarx/speech/gui/TextToSpeechInputWidget.cpp @@ -0,0 +1,75 @@ +/* + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @package SpeechX::ArmarXObjects::gui + * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu ) + * @date 2021 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#include "TextToSpeechInputWidget.h" + +#include <ArmarXCore/core/ManagedIceObject.h> + + +namespace armarx::speech::gui +{ + + TextToSpeechInputWidget::TextToSpeechInputWidget() : TextInputWidget("TextToSpeechInputWidget") + { + } + + + TextToSpeechInputWidget::TextToSpeechInputWidget(QComboBox* textInput, + QPushButton* sendButton) : + TextInputWidget("TextToSpeechInputWidget", textInput, sendButton) + { + } + + + void + TextToSpeechInputWidget::onInit(ManagedIceObject& component) + { + component.offeringTopic(ttsTopicName); + } + + + void + TextToSpeechInputWidget::onConnect(ManagedIceObject& component) + { + component.getTopic(ttsTopic, ttsTopicName); + } + + + void + TextToSpeechInputWidget::onDisconnect(ManagedIceObject& component) + { + (void)component; + ttsTopic = nullptr; + } + + + void + TextToSpeechInputWidget::sendText(QString text) + { + if (ttsTopic) + { + ARMARX_INFO << "Sending TTS text: '" << text.toStdString() << "'"; + ttsTopic->reportText(text.toStdString()); + } + } + +} // namespace armarx::speech::gui diff --git a/source/armarx/speech/gui/TextToSpeechInputWidget.h b/source/armarx/speech/gui/TextToSpeechInputWidget.h new file mode 100644 index 0000000000000000000000000000000000000000..a81603158f418aba2a398ac1435f78a22c50b6ee --- /dev/null +++ b/source/armarx/speech/gui/TextToSpeechInputWidget.h @@ -0,0 +1,72 @@ +/* + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @package SpeechX::ArmarXObjects::gui + * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu ) + * @date 2021 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + + +#include <RobotAPI/interface/speech/SpeechInterface.h> + +#include <armarx/speech/gui/TextInputWidget.h> + + +namespace armarx::speech::gui +{ + class TextToSpeechInputWidget : public TextInputWidget + { + Q_OBJECT + using This = TextToSpeechInputWidget; + + public: + TextToSpeechInputWidget(); + TextToSpeechInputWidget(QComboBox* textInput, QPushButton* sendButton); + + + using LifecycleClient::onConnect; + using LifecycleClient::onDisconnect; + using LifecycleClient::onInit; + void onInit(ManagedIceObject& component) override; + void onConnect(ManagedIceObject& component) override; + void onDisconnect(ManagedIceObject& component) override; + + + signals: + + void initialized(); + void connected(); + void disconnected(); + + + private slots: + + void sendText(QString text) override; + + + signals: + + + private: + public: + std::string ttsTopicName = "TextToSpeech"; + TextListenerInterfacePrx ttsTopic; + }; + +} // namespace armarx::speech::gui diff --git a/source/armarx/speech/gui/memory/SpeechToTextDisplayWidget.cpp b/source/armarx/speech/gui/memory/SpeechToTextDisplayWidget.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fbb3ff461a0c3b0c309747219feb8a9c29f9938b --- /dev/null +++ b/source/armarx/speech/gui/memory/SpeechToTextDisplayWidget.cpp @@ -0,0 +1,62 @@ +/* + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @package SpeechX::ArmarXObjects::gui + * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu ) + * @date 2021 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#include "SpeechToTextDisplayWidget.h" + +#include <RobotAPI/libraries/armem/core/MemoryID_operators.h> + + +namespace armarx::armem::speech::gui +{ + + void + SpeechToTextDisplayWidget::onConnect() + { + try + { + reader.connect(mns); + } + catch (const armem::error::ArMemError& e) + { + ARMARX_ERROR << "Failed to connect STT reader:\n" << e.what(); + return; + } + + mns.subscribe(reader.coreSegmentID, + [this](const std::vector<armem::MemoryID>& updatedSnapshotIDs) + { + ARMARX_VERBOSE << "Received " << updatedSnapshotIDs; + if (std::optional<std::string> text = + reader.getLatestText(updatedSnapshotIDs)) + { + emit textReceived(QString::fromStdString(text.value())); + } + }); + + // Initial fetch + if (std::optional<std::string> text = reader.getLatestText()) + { + emit textReceived(QString::fromStdString(text.value())); + } + } + +} // namespace armarx::armem::speech::gui diff --git a/source/armarx/speech/gui/memory/SpeechToTextDisplayWidget.h b/source/armarx/speech/gui/memory/SpeechToTextDisplayWidget.h new file mode 100644 index 0000000000000000000000000000000000000000..efabaecd91b6a8d20043de93100727f9d91e32ac --- /dev/null +++ b/source/armarx/speech/gui/memory/SpeechToTextDisplayWidget.h @@ -0,0 +1,59 @@ +/* + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @package SpeechX::ArmarXObjects::gui + * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu ) + * @date 2021 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +#include <RobotAPI/libraries/armem/client/MemoryNameSystem.h> + +#include <armarx/speech/core/stt/Reader.h> +#include <armarx/speech/gui/memory/TextDisplayWidget.h> + + +namespace armarx::armem::speech::gui +{ + + class SpeechToTextDisplayWidget : public TextDisplayWidget + { + Q_OBJECT + + public: + using TextDisplayWidget::TextDisplayWidget; + + using TextDisplayWidget::onConnect; + void onConnect() override; + + + private slots: + + + signals: + + + private: + void init(); + + + public: + armarx::armem::speech::stt::Reader reader; + }; + +} // namespace armarx::armem::speech::gui diff --git a/source/armarx/speech/gui/memory/SpeechToTextInputWidget.cpp b/source/armarx/speech/gui/memory/SpeechToTextInputWidget.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c51a228ae87e9d75fccb299fc5e251e2f0f773e8 --- /dev/null +++ b/source/armarx/speech/gui/memory/SpeechToTextInputWidget.cpp @@ -0,0 +1,91 @@ +/* + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @package SpeechX::ArmarXObjects::gui + * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu ) + * @date 2021 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#include "SpeechToTextInputWidget.h" + +#include <QLayout> +#include <QPushButton> + +#include <ArmarXCore/core/ManagedIceObject.h> + + +namespace armarx::armem::speech::gui +{ + + SpeechToTextInputWidget::SpeechToTextInputWidget(armem::client::MemoryNameSystem& mns) : + TextInputWidget("SpeechToTextInputWidget"), mns(mns) + { + stopButton = new QPushButton("Stop"); + init(); + } + + + SpeechToTextInputWidget::SpeechToTextInputWidget(armem::client::MemoryNameSystem& mns, + QComboBox* textInput, + QPushButton* sendButton, + QPushButton* stopButton) : + TextInputWidget("SpeechToTextInputWidget", textInput, sendButton), + mns(mns), + stopButton(stopButton) + { + init(); + } + + + void + SpeechToTextInputWidget::init() + { + layout()->addWidget(stopButton); + + connect(stopButton, &QPushButton::clicked, this, &This::sendStop); + } + + + void + SpeechToTextInputWidget::onConnect() + { + try + { + sttWriter.connect(mns); + } + catch (const armem::error::ArMemError& e) + { + ARMARX_ERROR << e.what(); + } + } + + + void + SpeechToTextInputWidget::sendText(QString text) + { + ARMARX_INFO << "Committing STT text '" << text.toStdString() << "'"; + sttWriter.commit(text.toStdString()); + } + + + void + SpeechToTextInputWidget::sendStop() + { + sendText("stop"); + } + +} // namespace armarx::armem::speech::gui diff --git a/source/armarx/speech/gui/memory/SpeechToTextInputWidget.h b/source/armarx/speech/gui/memory/SpeechToTextInputWidget.h new file mode 100644 index 0000000000000000000000000000000000000000..dd4fb00edd45fb3b8730e586e820a90c5d04c6e1 --- /dev/null +++ b/source/armarx/speech/gui/memory/SpeechToTextInputWidget.h @@ -0,0 +1,74 @@ +/* + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @package SpeechX::ArmarXObjects::gui + * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu ) + * @date 2021 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +#include <RobotAPI/libraries/armem/client/MemoryNameSystem.h> +#include <RobotAPI/libraries/armem/client/Writer.h> + +#include <armarx/speech/core/stt/Writer.h> +#include <armarx/speech/gui/TextInputWidget.h> + + +namespace armarx::armem::speech::gui +{ + + class SpeechToTextInputWidget : public armarx::speech::gui::TextInputWidget + { + Q_OBJECT + using This = SpeechToTextInputWidget; + + public: + SpeechToTextInputWidget(armem::client::MemoryNameSystem& mns); + SpeechToTextInputWidget(armem::client::MemoryNameSystem& mns, + QComboBox* textInput, + QPushButton* sendButton, + QPushButton* stopButton); + + + using TextInputWidget::onConnect; + using TextInputWidget::onDisconnect; + using TextInputWidget::onInit; + void onConnect() override; + + + private slots: + + void sendText(QString text) override; + void sendStop(); + + + signals: + + + private: + void init(); + + + public: + armem::client::MemoryNameSystem& mns; + armem::speech::stt::Writer sttWriter{"SpeechToTextInputWidget"}; + + QPushButton* stopButton; + }; + +} // namespace armarx::armem::speech::gui diff --git a/source/armarx/speech/gui/memory/TextDisplayWidget.cpp b/source/armarx/speech/gui/memory/TextDisplayWidget.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ce21597933b7516aefc84e0d886818d8075a8342 --- /dev/null +++ b/source/armarx/speech/gui/memory/TextDisplayWidget.cpp @@ -0,0 +1,63 @@ +/* + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @package SpeechX::ArmarXObjects::gui + * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu ) + * @date 2021 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#include "TextDisplayWidget.h" + +#include <QHBoxLayout> +#include <QLineEdit> + + +namespace armarx::armem::speech::gui +{ + + TextDisplayWidget::TextDisplayWidget(armem::client::MemoryNameSystem& mns) : mns(mns) + { + text = new QLineEdit(); + + setLayout(new QHBoxLayout()); + layout()->addWidget(text); + + init(); + } + + + TextDisplayWidget::TextDisplayWidget(armem::client::MemoryNameSystem& mns, QLineEdit* text) : + mns(mns), text(text) + { + init(); + } + + + void + TextDisplayWidget::setText(const QString& text) + { + this->text->setText(text); + } + + + void + TextDisplayWidget::init() + { + connect(this, &This::textReceived, this, &This::setText); + } + +} // namespace armarx::armem::speech::gui diff --git a/source/armarx/speech/gui/memory/TextDisplayWidget.h b/source/armarx/speech/gui/memory/TextDisplayWidget.h new file mode 100644 index 0000000000000000000000000000000000000000..c9d4e0b48d86a9105db5d167c60bf303c29176fe --- /dev/null +++ b/source/armarx/speech/gui/memory/TextDisplayWidget.h @@ -0,0 +1,87 @@ +/* + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @package SpeechX::ArmarXObjects::gui + * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu ) + * @date 2021 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +#include <QSettings> +#include <QWidget> + +#include <ArmarXCore/core/logging/Logging.h> + +#include <RobotAPI/libraries/armem/client/MemoryNameSystem.h> +#include <RobotAPI/libraries/armem_gui/lifecycle.h> + + +class QLineEdit; + + +namespace armarx::armem::speech::gui +{ + class TextDisplayWidget : + public QWidget, + public armarx::Logging, + public armarx::gui::LifecycleClient + { + Q_OBJECT + using This = TextDisplayWidget; + + public: + TextDisplayWidget(armem::client::MemoryNameSystem& mns); + TextDisplayWidget(armem::client::MemoryNameSystem& mns, QLineEdit* text); + + + public slots: + + void setText(const QString& text); + + + signals: + + void initialized(); + void connected(); + void disconnected(); + + + protected slots: + + signals: + + void textReceived(QString text); + + + private slots: + + + signals: + + + private: + void init(); + + + public: + armem::client::MemoryNameSystem& mns; + + QLineEdit* text; + }; + +} // namespace armarx::armem::speech::gui diff --git a/source/armarx/speech/gui/memory/TextToSpeechDisplayWidget.cpp b/source/armarx/speech/gui/memory/TextToSpeechDisplayWidget.cpp new file mode 100644 index 0000000000000000000000000000000000000000..54af6392cd01ca239f461f1337fdcbebd9022ac4 --- /dev/null +++ b/source/armarx/speech/gui/memory/TextToSpeechDisplayWidget.cpp @@ -0,0 +1,62 @@ +/* + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @package SpeechX::ArmarXObjects::gui + * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu ) + * @date 2021 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#include "TextToSpeechDisplayWidget.h" + +#include <RobotAPI/libraries/armem/core/MemoryID_operators.h> + + +namespace armarx::armem::speech::gui +{ + + void + TextToSpeechDisplayWidget::onConnect() + { + try + { + reader.connect(mns); + } + catch (const armem::error::ArMemError& e) + { + ARMARX_ERROR << "Failed to connect TTS reader:\n" << e.what(); + return; + } + + mns.subscribe(reader.coreSegmentID, + [this](const std::vector<armem::MemoryID>& updatedSnapshotIDs) + { + ARMARX_VERBOSE << "Received " << updatedSnapshotIDs; + if (std::optional<std::string> text = + reader.getLatestText(updatedSnapshotIDs)) + { + emit textReceived(QString::fromStdString(text.value())); + } + }); + + // Initial fetch + if (std::optional<std::string> text = reader.getLatestText()) + { + emit textReceived(QString::fromStdString(text.value())); + } + } + +} // namespace armarx::armem::speech::gui diff --git a/source/armarx/speech/gui/memory/TextToSpeechDisplayWidget.h b/source/armarx/speech/gui/memory/TextToSpeechDisplayWidget.h new file mode 100644 index 0000000000000000000000000000000000000000..28e75aa319c4d6aed0d0762506b8566e95d41bfe --- /dev/null +++ b/source/armarx/speech/gui/memory/TextToSpeechDisplayWidget.h @@ -0,0 +1,53 @@ +/* + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @package SpeechX::ArmarXObjects::gui + * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu ) + * @date 2021 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +#include <RobotAPI/libraries/armem/client/MemoryNameSystem.h> + +#include <armarx/speech/core/tts/Reader.h> +#include <armarx/speech/gui/memory/TextDisplayWidget.h> + + +namespace armarx::armem::speech::gui +{ + + class TextToSpeechDisplayWidget : public TextDisplayWidget + { + Q_OBJECT + + public: + using TextDisplayWidget::TextDisplayWidget; + + using TextDisplayWidget::onConnect; + void onConnect() override; + + + private: + void init(); + + + public: + armem::speech::tts::Reader reader; + }; + +} // namespace armarx::armem::speech::gui diff --git a/source/armarx/speech/gui/memory/TextToSpeechInputWidget.cpp b/source/armarx/speech/gui/memory/TextToSpeechInputWidget.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9be45b404247b7ca2d7a057e283fc88f6d473342 --- /dev/null +++ b/source/armarx/speech/gui/memory/TextToSpeechInputWidget.cpp @@ -0,0 +1,66 @@ +/* + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @package SpeechX::ArmarXObjects::gui + * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu ) + * @date 2021 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#include "TextToSpeechInputWidget.h" + +#include <ArmarXCore/core/ManagedIceObject.h> + + +namespace armarx::armem::speech::gui +{ + + TextToSpeechInputWidget::TextToSpeechInputWidget(armem::client::MemoryNameSystem& mns) : + TextInputWidget("TextToSpeechInputWidget"), mns(mns) + { + } + + + TextToSpeechInputWidget::TextToSpeechInputWidget(armem::client::MemoryNameSystem& mns, + QComboBox* textInput, + QPushButton* sendButton) : + TextInputWidget("TextToSpeechInputWidget", textInput, sendButton), mns(mns) + { + } + + + void + TextToSpeechInputWidget::onConnect() + { + try + { + ttsWriter.connect(mns); + } + catch (const armem::error::ArMemError& e) + { + ARMARX_ERROR << e.what(); + } + } + + + void + TextToSpeechInputWidget::sendText(QString text) + { + ARMARX_INFO << "Committing TTS text '" << text.toStdString() << "'"; + ttsWriter.commit(text.toStdString()); + } + +} // namespace armarx::armem::speech::gui diff --git a/source/armarx/speech/gui/memory/TextToSpeechInputWidget.h b/source/armarx/speech/gui/memory/TextToSpeechInputWidget.h new file mode 100644 index 0000000000000000000000000000000000000000..ec031972579e286d14e6965a6ca7b542864a4795 --- /dev/null +++ b/source/armarx/speech/gui/memory/TextToSpeechInputWidget.h @@ -0,0 +1,67 @@ +/* + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @package SpeechX::ArmarXObjects::gui + * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu ) + * @date 2021 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +#include <RobotAPI/libraries/armem/client/MemoryNameSystem.h> +#include <RobotAPI/libraries/armem/client/Writer.h> + +#include <armarx/speech/core/tts/Writer.h> +#include <armarx/speech/gui/TextInputWidget.h> + + +namespace armarx::armem::speech::gui +{ + + class TextToSpeechInputWidget : public armarx::speech::gui::TextInputWidget + { + Q_OBJECT + using This = TextToSpeechInputWidget; + + public: + TextToSpeechInputWidget(armem::client::MemoryNameSystem& mns); + TextToSpeechInputWidget(armem::client::MemoryNameSystem& mns, + QComboBox* textInput, + QPushButton* sendButton); + + + using TextInputWidget::onConnect; + using TextInputWidget::onDisconnect; + using TextInputWidget::onInit; + void onConnect() override; + + + private slots: + + void sendText(QString text) override; + + + signals: + + + private: + public: + armem::client::MemoryNameSystem& mns; + armem::speech::tts::Writer ttsWriter{"TextToSpeechInputWidget"}; + }; + +} // namespace armarx::armem::speech::gui diff --git a/source/armarx/speech/qt_plugins/CMakeLists.txt b/source/armarx/speech/qt_plugins/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..0f093ec5c20c1ccf2e0806efe3d4529cc15ebbc4 --- /dev/null +++ b/source/armarx/speech/qt_plugins/CMakeLists.txt @@ -0,0 +1,2 @@ + +add_subdirectory(speech_memory_gui) \ No newline at end of file diff --git a/source/armarx/speech/qt_plugins/speech_memory_gui/CMakeLists.txt b/source/armarx/speech/qt_plugins/speech_memory_gui/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..9f3b2bddd11d3eed22d32879507d608ff4f3fe07 --- /dev/null +++ b/source/armarx/speech/qt_plugins/speech_memory_gui/CMakeLists.txt @@ -0,0 +1,23 @@ +armarx_add_qt_plugin(speech_memory_gui + WIDGET_CONTROLLER + armarx::speech::qt_plugins::speech_memory_gui::WidgetController + + SOURCES + WidgetController.cpp + + HEADERS + WidgetController.h + + UI_FILES + Widget.ui + + DEPENDENCIES + # ArmarXGui + SimpleConfigDialog # For the simple config dialog. + + armem + armem_gui + + armarx_speech::core + armarx_speech::gui +) diff --git a/source/armarx/speech/qt_plugins/speech_memory_gui/Widget.ui b/source/armarx/speech/qt_plugins/speech_memory_gui/Widget.ui new file mode 100644 index 0000000000000000000000000000000000000000..da6096acb7cce80e37f3bd9e3874680f1993bac7 --- /dev/null +++ b/source/armarx/speech/qt_plugins/speech_memory_gui/Widget.ui @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>armarx::speech::qt_plugins::speech_memory_gui::Widget</class> + <widget class="QWidget" name="speech_memory_gui"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>400</width> + <height>300</height> + </rect> + </property> + <property name="windowTitle"> + <string>speech_memory_gui</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <layout class="QFormLayout" name="formLayout"/> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui> diff --git a/source/armarx/speech/qt_plugins/speech_memory_gui/WidgetController.cpp b/source/armarx/speech/qt_plugins/speech_memory_gui/WidgetController.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5fd5c4b85d81f84897c2fb054565fbec7087f5e7 --- /dev/null +++ b/source/armarx/speech/qt_plugins/speech_memory_gui/WidgetController.cpp @@ -0,0 +1,164 @@ +/* + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * \package speech::qt_plugins::WidgetController + * \author Naumann ( uhxkb at student dot kit dot edu ) + * \date 2023 + * \copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#include "WidgetController.h" + +#include <ArmarXGui/libraries/SimpleConfigDialog/SimpleConfigDialog.h> + +#include <RobotAPI/libraries/armem_gui/gui_utils.h> + +#include <armarx/speech/gui/RecognizedTextWidget.h> +#include <armarx/speech/gui/TextListenerWidget.h> +#include <armarx/speech/gui/TextToSpeechInputWidget.h> +#include <armarx/speech/gui/memory/SpeechToTextDisplayWidget.h> +#include <armarx/speech/gui/memory/SpeechToTextInputWidget.h> +#include <armarx/speech/gui/memory/TextToSpeechDisplayWidget.h> +#include <armarx/speech/gui/memory/TextToSpeechInputWidget.h> + + +namespace armarx::speech::qt_plugins::speech_memory_gui +{ + + QString + WidgetController::GetWidgetName() + { + return "Speech.SpeechMemoryGui"; + } + + + WidgetController::WidgetController() + { + widget.setupUi(getWidget()); + + { + QFormLayout* dialogLayout = widget.formLayout; + speechToTextInput = new armem::speech::gui::SpeechToTextInputWidget(mns); + dialogLayout->addRow("Speech to Text Input", speechToTextInput); + + speechToTextDisplay = new armem::speech::gui::SpeechToTextDisplayWidget(mns); + dialogLayout->addRow("Speech to Text Display", speechToTextDisplay); + + textToSpeechInput = new armem::speech::gui::TextToSpeechInputWidget(mns); + dialogLayout->addRow("Text to Speech Input", textToSpeechInput); + + textToSpeechDisplay = new armem::speech::gui::TextToSpeechDisplayWidget(mns); + dialogLayout->addRow("Text to Speech Output", textToSpeechDisplay); + + generatedRobotAction = new gui::TextListenerWidget("RobotAction"); + dialogLayout->addRow("Generated Robot Action", generatedRobotAction); + + + armarx::gui::connectLifecycle(&lifecycleServer, speechToTextInput); + armarx::gui::connectLifecycle(&lifecycleServer, speechToTextDisplay); + armarx::gui::connectLifecycle(&lifecycleServer, textToSpeechInput); + armarx::gui::connectLifecycle(&lifecycleServer, textToSpeechDisplay); + armarx::gui::connectLifecycle(&lifecycleServer, generatedRobotAction); + } + } + + + WidgetController::~WidgetController() = default; + + constexpr auto configKeyMns = "SpeechMemoryGui.MemoryNameSystem"; + + void + WidgetController::loadSettings(QSettings* settings) + { + mnsName = settings->value(QString::fromStdString(configKeyMns), "MemoryNameSystem") + .toString() + .toStdString(); + } + + void + WidgetController::saveSettings(QSettings* settings) + { + settings->setValue(QString::fromStdString(configKeyMns), QString::fromStdString(mnsName)); + } + + + QPointer<QDialog> + WidgetController::getConfigDialog(QWidget* parent) + { + if (configDialog == nullptr) + { + configDialog = new SimpleConfigDialog(parent); + configDialog->addProxyFinder<armarx::armem::mns::MemoryNameSystemInterfacePrx>( + {configKeyMns, "MemoryNameSystem", "MemoryNameSystem"}); + } + return qobject_cast<QDialog*>(configDialog); + } + + + void + WidgetController::configured() + { + if (configDialog != nullptr) + { + mnsName = configDialog->getProxyName(configKeyMns); + if (mnsName.empty()) + { + mnsName = "MemoryNameSystem"; + } + } + } + + + void + WidgetController::onInitComponent() + { + if (!mnsName.empty()) + { + usingProxy(mnsName); + } + + emit lifecycleServer.initialized(this); + } + + + void + WidgetController::onConnectComponent() + { + if (!mnsName.empty()) + { + armem::mns::MemoryNameSystemInterfacePrx mnsProxy; + getProxy(mnsProxy, mnsName); + mns = armem::client::MemoryNameSystem(mnsProxy, this); + } + + emit lifecycleServer.connected(this); + } + + void + WidgetController::onDisconnectComponent() + { + + emit lifecycleServer.disconnected(this); + } + + void + WidgetController::memoryUpdated(const armem::data::MemoryIDs& updatedSnapshotIDs, + const Ice::Current& /*iceCurrent*/) + { + mns.updated(updatedSnapshotIDs); + } + +} // namespace armarx::speech::qt_plugins::speech_memory_gui diff --git a/source/armarx/speech/qt_plugins/speech_memory_gui/WidgetController.h b/source/armarx/speech/qt_plugins/speech_memory_gui/WidgetController.h new file mode 100644 index 0000000000000000000000000000000000000000..c1567a0db0ec37aa3013e2e5d29f1e65dec9b39a --- /dev/null +++ b/source/armarx/speech/qt_plugins/speech_memory_gui/WidgetController.h @@ -0,0 +1,141 @@ +/* + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @package speech::qt_plugins::WidgetController + * @author Naumann ( uhxkb at student dot kit dot edu ) + * @date 2023 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ +#pragma once + +#include <ArmarXCore/core/system/ImportExportComponent.h> + +#include <ArmarXGui/libraries/ArmarXGuiBase/ArmarXComponentWidgetController.h> +#include <ArmarXGui/libraries/ArmarXGuiBase/ArmarXGuiPlugin.h> +#include <ArmarXGui/libraries/SimpleConfigDialog/SimpleConfigDialog.h> + +#include <RobotAPI/libraries/armem/client/MemoryNameSystem.h> +#include <RobotAPI/libraries/armem_gui/lifecycle.h> + +#include <armarx/speech/qt_plugins/speech_memory_gui/ui_Widget.h> + +namespace armarx::speech::gui +{ + class TextListenerWidget; +} // namespace armarx::speech::gui + +namespace armarx::armem::speech::gui +{ + class SpeechToTextInputWidget; + class SpeechToTextDisplayWidget; + class TextToSpeechInputWidget; + class TextToSpeechDisplayWidget; +} // namespace armarx::memory::speech::gui + +namespace armarx::speech::qt_plugins::speech_memory_gui +{ + + /** + \page speech-GuiPlugins-speech_memory_gui speech_memory_gui + \brief The speech_memory_gui allows visualizing ... + + \image html speech_memory_gui.png + The user can + + API Documentation \ref WidgetController + + \see speech_memory_guiGuiPlugin + */ + + + /** + * \class speech_memory_guiGuiPlugin + * \ingroup ArmarXGuiPlugins + * \brief speech_memory_guiGuiPlugin brief description + * + * Detailed description + */ + + /** + * \class WidgetController + * \brief WidgetController brief one line description + * + * Detailed description + */ + class ARMARXCOMPONENT_IMPORT_EXPORT WidgetController : + public armarx::ArmarXComponentWidgetControllerTemplate<WidgetController>, + public armem::client::MemoryListenerInterface + { + Q_OBJECT + + public: + /// Controller constructor. + explicit WidgetController(); + /// Controller destructor. + ~WidgetController() override; + + //// @see ArmarXWidgetController::loadSettings() + void loadSettings(QSettings* settings) override; + /// @see ArmarXWidgetController::saveSettings() + void saveSettings(QSettings* settings) override; + + QPointer<QDialog> getConfigDialog(QWidget* parent) override; + void configured() override; + + /** + * Returns the Widget name displayed in the ArmarXGui to create an + * instance of this class. + */ + static QString GetWidgetName(); + + /// @see armarx::Component::onInitComponent() + void onInitComponent() override; + + /// @see armarx::Component::onConnectComponent() + void onConnectComponent() override; + + /// @see armarx::Component::onDisconnectComponent() + void onDisconnectComponent() override; + + public: + void memoryUpdated(const armarx::armem::data::MemoryIDs& updatedSnapshotIDs, + const Ice::Current& /*iceCurrent*/) override; + + + public slots: + /* QT slot declarations */ + + + signals: + /* QT signal declarations */ + + + private: + /// Widget Form + Ui::Widget widget; + armarx::gui::LifecycleServer lifecycleServer; + QPointer<SimpleConfigDialog> configDialog; + + std::string mnsName = "MemoryNameSystem"; + armem::client::MemoryNameSystem mns; + + armem::speech::gui::SpeechToTextInputWidget* speechToTextInput; + armem::speech::gui::SpeechToTextDisplayWidget* speechToTextDisplay; + armem::speech::gui::TextToSpeechInputWidget* textToSpeechInput; + armem::speech::gui::TextToSpeechDisplayWidget* textToSpeechDisplay; + gui::TextListenerWidget* generatedRobotAction; + }; +} // namespace armarx::speech::qt_plugins::speech_memory_gui