This merge request works around an annoying startup hang that I introduced when adding text-to-speech to NeoChat. The previous implementation was a QML singleton that used the `TextToSpeech` QML component. Unfortunately that component blocks the UI thread when first loading it, while it connects to speech-dispatcher. This MR just rewrites that singleton in C++, and moves initialization of QtTextToSpeech to the first time you read a message aloud. It doesn't fix the performance problem, but it at least stops it from affecting startup. In the future, I'd like to move speech operations to a background thread to completely mitigate the initialization freeze.
21 lines
445 B
C++
21 lines
445 B
C++
// SPDX-FileCopyrightText: 2025 Ritchie Frodomar <ritchie@kde.org>
|
|
// SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
|
|
|
#pragma once
|
|
|
|
#include <QObject>
|
|
#include <QQmlEngine>
|
|
#include <QtTextToSpeech>
|
|
|
|
class TextToSpeechHelper : public QObject
|
|
{
|
|
Q_OBJECT
|
|
QML_ELEMENT
|
|
QML_SINGLETON
|
|
|
|
public:
|
|
Q_INVOKABLE void speak(const QString &textToSpeak);
|
|
|
|
private:
|
|
QTextToSpeech *m_speech = nullptr;
|
|
}; |