File: texttospeechutil.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 (67 lines) | stat: -rw-r--r-- 2,456 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
/*
   SPDX-FileCopyrightText: 2022-2026 Laurent Montel <montel@kde.org>

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

#include "texttospeechutil.h"

#include <KConfig>
#include <KConfigGroup>
#include <QIODevice>

using namespace Qt::Literals::StringLiterals;
QString TextEditTextToSpeech::TextToSpeechUtil::textToSpeechConfigFileName()
{
    return u"texttospeechrc"_s;
}

QString TextEditTextToSpeech::TextToSpeechUtil::textToSpeechConfigGroupName()
{
    return u"Settings"_s;
}

TextEditTextToSpeech::TextToSpeechUtil::TextToSpeechSettings TextEditTextToSpeech::TextToSpeechUtil::loadSettings()
{
    TextEditTextToSpeech::TextToSpeechUtil::TextToSpeechSettings settings;
    KConfig config(TextEditTextToSpeech::TextToSpeechUtil::textToSpeechConfigFileName());
    const KConfigGroup grp = config.group(TextEditTextToSpeech::TextToSpeechUtil::textToSpeechConfigGroupName());
    settings.engineName = grp.readEntry("engine");
    settings.rate = grp.readEntry("rate", 50);
    settings.volumeValue = grp.readEntry("volume", 0);
    settings.localeName = grp.readEntry("localeName");
    settings.pitch = grp.readEntry("pitch", 0);
    QByteArray ba = grp.readEntry("voice", QByteArray());
    QDataStream s(&ba, QIODevice::ReadOnly);
    s.setVersion(QDataStream::Qt_5_15);
    s >> settings.voice;
    return settings;
}

void TextEditTextToSpeech::TextToSpeechUtil::writeConfig(const TextEditTextToSpeech::TextToSpeechUtil::TextToSpeechSettings &settings)
{
    KConfig config(TextEditTextToSpeech::TextToSpeechUtil::textToSpeechConfigFileName());
    KConfigGroup grp = config.group(TextEditTextToSpeech::TextToSpeechUtil::textToSpeechConfigGroupName());
    grp.writeEntry("volume", settings.volumeValue);
    grp.writeEntry("rate", settings.rate);
    grp.writeEntry("pitch", settings.pitch);
    grp.writeEntry("localeName", settings.localeName);
    // qDebug() << " engineName " << engineName;
    grp.writeEntry("engine", settings.engineName);
    QByteArray ba;
    QDataStream s(&ba, QIODevice::WriteOnly);
    s.setVersion(QDataStream::Qt_5_15);
    s << settings.voice;
    grp.writeEntry("voice", ba);
}

QDebug operator<<(QDebug d, const TextEditTextToSpeech::TextToSpeechUtil::TextToSpeechSettings &t)
{
    d << "voice " << t.voice;
    d << "engineName " << t.engineName;
    d << "localeName " << t.localeName;
    d << "rate " << t.rate;
    d << "pitch " << t.pitch;
    d << "volumeValue " << t.volumeValue;
    return d;
}