KTextAddons

texttospeechconfiginterface.cpp
1/*
2 SPDX-FileCopyrightText: 2014-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "texttospeechconfiginterface.h"
8#include "textedittexttospeech_debug.h"
9#include <KLocalizedString>
10#include <QTextToSpeech>
11using namespace TextEditTextToSpeech;
12
13TextToSpeechConfigInterface::TextToSpeechConfigInterface(QObject *parent)
14 : QObject(parent)
15{
16}
17
18TextToSpeechConfigInterface::~TextToSpeechConfigInterface() = default;
19
20QVector<QVoice> TextToSpeechConfigInterface::availableVoices() const
21{
22 QVector<QVoice> voices;
23 if (mTextToSpeech) {
24 voices = mTextToSpeech->availableVoices();
25 } else {
26 qCWarning(TEXTEDITTEXTTOSPEECH_LOG) << "Text To Speech is not created. ";
27 }
28 return voices;
29}
30
31QStringList TextToSpeechConfigInterface::availableEngines() const
32{
33 if (mTextToSpeech) {
34 return mTextToSpeech->availableEngines();
35 }
36 qCWarning(TEXTEDITTEXTTOSPEECH_LOG) << "Text To Speech is not created. ";
37 return {};
38}
39
40QVector<QLocale> TextToSpeechConfigInterface::availableLocales() const
41{
42 if (mTextToSpeech) {
43 return mTextToSpeech->availableLocales();
44 }
45 qCWarning(TEXTEDITTEXTTOSPEECH_LOG) << "Text To Speech is not created. ";
46 return {};
47}
48
49QLocale TextToSpeechConfigInterface::locale() const
50{
51 if (mTextToSpeech) {
52 return mTextToSpeech->locale();
53 }
54 qCWarning(TEXTEDITTEXTTOSPEECH_LOG) << "Text To Speech is not created. ";
55 return {};
56}
57
58void TextToSpeechConfigInterface::setEngine(const QString &engineName)
59{
60 if (!mTextToSpeech || (mTextToSpeech && (mTextToSpeech->engine() != engineName))) {
61 delete mTextToSpeech;
62 mTextToSpeech = new QTextToSpeech(engineName, this);
63 }
64}
65
66void TextToSpeechConfigInterface::testEngine(const EngineSettings &engineSettings)
67{
68 if (!mTextToSpeech) {
69 qCWarning(TEXTEDITTEXTTOSPEECH_LOG) << "Text To Speech is not created. ";
70 return;
71 }
72 const int rate = engineSettings.rate;
73 const double rateDouble = rate / 100.0;
74 mTextToSpeech->setRate(rateDouble);
75 const int pitch = engineSettings.pitch;
76 const double pitchDouble = pitch / 100.0;
77 mTextToSpeech->setPitch(pitchDouble);
78 const int volume = engineSettings.volume;
79 const double volumeDouble = volume / 100.0;
80 mTextToSpeech->setVolume(volumeDouble);
81 mTextToSpeech->setLocale(QLocale(engineSettings.localeName));
82 mTextToSpeech->setVoice(engineSettings.voice);
83
84 // TODO change text ?
85 mTextToSpeech->say(i18n("Morning, this is the test for testing settings."));
86}
87
88QDebug operator<<(QDebug d, const TextEditTextToSpeech::TextToSpeechConfigInterface::EngineSettings &t)
89{
90 d << " Rate " << t.rate;
91 d << " pitch " << t.pitch;
92 d << " volume " << t.volume;
93 d << " voice " << t.voice;
94 d << " localeName " << t.localeName;
95 return d;
96}
97
98#include "moc_texttospeechconfiginterface.cpp"
QString i18n(const char *text, const TYPE &arg...)
QDebug operator<<(QDebug dbg, const DcrawInfoContainer &c)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:56:02 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.