File: texttospeechinterface.cpp

package info (click to toggle)
ktextaddons 1.9.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 17,856 kB
  • sloc: cpp: 62,045; ansic: 6,520; xml: 2,630; sh: 11; makefile: 7
file content (95 lines) | stat: -rw-r--r-- 2,851 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
   SPDX-FileCopyrightText: 2014-2026 Laurent Montel <montel@kde.org>

   SPDX-License-Identifier: LGPL-2.0-or-later
*/

#include "texttospeechinterface.h"
#include "texttospeech.h"

using namespace TextEditTextToSpeech;

class Q_DECL_HIDDEN TextEditTextToSpeech::TextToSpeechInterfacePrivate
{
public:
    TextToSpeechInterfacePrivate(TextToSpeechWidget *textToSpeechWidget)
        : mTextToSpeechWidget(textToSpeechWidget)
    {
    }

    TextToSpeechWidget *const mTextToSpeechWidget;
};

TextToSpeechInterface::TextToSpeechInterface(TextToSpeechWidget *textToSpeechWidget, QObject *parent)
    : QObject(parent)
    , d(new TextEditTextToSpeech::TextToSpeechInterfacePrivate(textToSpeechWidget))
{
    TextEditTextToSpeech::TextToSpeech::self(); // init
    connect(d->mTextToSpeechWidget, &TextEditTextToSpeech::TextToSpeechWidget::stateChanged, this, &TextToSpeechInterface::stateChanged);
    connect(TextEditTextToSpeech::TextToSpeech::self(),
            &TextEditTextToSpeech::TextToSpeech::stateChanged,
            d->mTextToSpeechWidget,
            &TextEditTextToSpeech::TextToSpeechWidget::slotStateChanged);

    connect(TextEditTextToSpeech::TextToSpeech::self(),
            &TextEditTextToSpeech::TextToSpeech::aboutToSynthesize,
            d->mTextToSpeechWidget,
            &TextEditTextToSpeech::TextToSpeechWidget::aboutToSynthesize);
}

TextToSpeechInterface::~TextToSpeechInterface() = default;

bool TextToSpeechInterface::isReady() const
{
    return TextEditTextToSpeech::TextToSpeech::self()->isReady();
}

void TextToSpeechInterface::say(const QString &text)
{
    intializePlay();
    TextEditTextToSpeech::TextToSpeech::self()->say(text);
}

void TextToSpeechInterface::intializePlay()
{
    d->mTextToSpeechWidget->setState(TextEditTextToSpeech::TextToSpeechWidget::Play);
    d->mTextToSpeechWidget->showWidget();
}

qsizetype TextToSpeechInterface::enqueue(const QString &text)
{
    intializePlay();
    return TextEditTextToSpeech::TextToSpeech::self()->enqueue(text);
}

double TextToSpeechInterface::volume() const
{
    return TextEditTextToSpeech::TextToSpeech::self()->volume();
}

void TextToSpeechInterface::setVolume(double value)
{
    TextEditTextToSpeech::TextToSpeech::self()->setVolume(value);
}

void TextToSpeechInterface::reloadSettings()
{
    TextEditTextToSpeech::TextToSpeech::self()->reloadSettings();
}

void TextToSpeechInterface::stateChanged(TextToSpeechWidget::State state)
{
    switch (state) {
    case TextToSpeechWidget::Stop:
        TextEditTextToSpeech::TextToSpeech::self()->stop();
        break;
    case TextToSpeechWidget::Play:
        TextEditTextToSpeech::TextToSpeech::self()->resume();
        break;
    case TextToSpeechWidget::Pause:
        TextEditTextToSpeech::TextToSpeech::self()->pause();
        break;
    }
}

#include "moc_texttospeechinterface.cpp"