QTextToSpeech Class
The QTextToSpeech class provides a convenient access to text-to-speech engines More...
Header: | #include <QTextToSpeech> |
qmake: | QT += texttospeech |
Inherits: | QObject |
Public Types
enum | State { Ready, Speaking, Paused, BackendError } |
Properties
- 1 property inherited from QObject
Public Functions
QTextToSpeech(QObject *parent = nullptr) | |
QTextToSpeech(const QString &engine, QObject *parent = nullptr) | |
QVector<QLocale> | availableLocales() const |
QVector<QVoice> | availableVoices() const |
QLocale | locale() const |
double | pitch() const |
double | rate() const |
State | state() const |
QVoice | voice() const |
double | volume() const |
- 31 public functions inherited from QObject
Public Slots
void | pause() |
void | resume() |
void | say(const QString &text) |
void | setLocale(const QLocale &locale) |
void | setPitch(double pitch) |
void | setRate(double rate) |
void | setVoice(const QVoice &voice) |
void | setVolume(double volume) |
void | stop() |
- 1 public slot inherited from QObject
Signals
void | localeChanged(const QLocale &locale) |
void | pitchChanged(double pitch) |
void | rateChanged(double rate) |
void | stateChanged(QTextToSpeech::State state) |
void | voiceChanged(const QVoice &voice) |
void | volumeChanged(int volume) |
- 2 signals inherited from QObject
Static Public Members
QStringList | availableEngines() |
- 11 static public members inherited from QObject
Additional Inherited Members
- 9 protected functions inherited from QObject
Detailed Description
The QTextToSpeech class provides a convenient access to text-to-speech engines
Use say() to start synthesizing text. It is possible to specify the language with setLocale(). To select between the available voices use setVoice(). The languages and voices depend on the available synthesizers on each platform. On Linux by default speech-dispatcher is used.
Member Type Documentation
enum QTextToSpeech::State
Constant | Value | Description |
---|---|---|
QTextToSpeech::Ready | 0 | The synthesizer is ready to start a new text. This is also the state after a text was finished. |
QTextToSpeech::Speaking | 1 | The current text is being spoken. |
QTextToSpeech::Paused | 2 | The sythetization was paused and can be resumed with resume(). |
QTextToSpeech::BackendError | 3 | The backend was unable to synthesize the current string. |
Property Documentation
locale : QLocale
This property holds the current locale in use. By default, the system locale is used.
Access functions:
QLocale | locale() const |
void | setLocale(const QLocale &locale) |
Notifier signal:
void | localeChanged(const QLocale &locale) |
pitch : double
This property holds the voice pitch in the range -1.0 to 1.0. The default of 0.0 is normal speech pitch.
Access functions:
double | pitch() const |
void | setPitch(double pitch) |
Notifier signal:
void | pitchChanged(double pitch) |
rate : double
This property holds the current voice rate in the range -1.0 to 1.0. The default value of 0.0 is normal speech flow.
Access functions:
double | rate() const |
void | setRate(double rate) |
Notifier signal:
void | rateChanged(double rate) |
state : const State
This property holds the current state of the speech synthesizer. Use say() to start synthesizing text with the current voice and locale.
Access functions:
State | state() const |
Notifier signal:
void | stateChanged(QTextToSpeech::State state) |
voice : QVoice
This property holds the current voice used for the speech.
Access functions:
QVoice | voice() const |
void | setVoice(const QVoice &voice) |
Notifier signal:
void | voiceChanged(const QVoice &voice) |
volume : int
This property holds the current volume in the range 0.0 to 1.0. The default value is the platform's default volume.
Access functions:
double | volume() const |
void | setVolume(double volume) |
Notifier signal:
void | volumeChanged(int volume) |
Member Function Documentation
QTextToSpeech::QTextToSpeech(QObject *parent = nullptr)
Loads a text-to-speech engine from a plug-in that uses the default engine plug-in and constructs a QTextToSpeech object as the child of parent.
The default engine may be platform-specific.
If loading the plug-in fails, QTextToSpeech::state() will return QTextToSpeech::BackendError.
See also availableEngines().
QTextToSpeech::QTextToSpeech(const QString &engine, QObject *parent = nullptr)
Loads a text-to-speech engine from a plug-in that matches parameter engine and constructs a QTextToSpeech object as the child of parent.
If engine is empty, the default engine plug-in is used. The default engine may be platform-specific.
If loading the plug-in fails, QTextToSpeech::state() will return QTextToSpeech::BackendError.
See also availableEngines().
[static]
QStringList QTextToSpeech::availableEngines()
Gets the list of supported text-to-speech engine plug-ins.
QVector<QLocale> QTextToSpeech::availableLocales() const
Gets a vector of locales that are currently supported. Note on some platforms these can change when the backend changes synthesizers for example.
QVector<QVoice> QTextToSpeech::availableVoices() const
Gets a vector of voices available for the current locale.
Note: if no locale has been set, the system locale is used.
[slot]
void QTextToSpeech::pause()
Pause the current speech.
Note: this function depends on the platform and backend and may not work at all, take several seconds until it takes effect or may pause instantly. Some synthesizers will look for a break that they can later resume from, such as a sentence end.
Note: Due to Android platform limitations, pause() stops the current utterance, while resume() starts the previously queued utterance from the beginning.
See also resume().
[slot]
void QTextToSpeech::resume()
Resume speaking after pause() has been called.
See also pause().
[slot]
void QTextToSpeech::say(const QString &text)
Start synthesizing the text. This function will start the asynchronous speaking of the text. The current state is available using the state property. Once the synthetization is done, a stateChanged() signal with the Ready state will be emitted.
[slot]
void QTextToSpeech::setLocale(const QLocale &locale)
Sets the locale to a given locale if possible. The default is the system locale.
Note: Setter function for property locale.
See also locale().
[slot]
void QTextToSpeech::setVoice(const QVoice &voice)
Sets the voice to use.
Note: On some platforms setting the voice changes other voice attributes such as locale, pitch, etc. in which case signals are emitted for these changes.
Note: Setter function for property voice.
See also voice().
[slot]
void QTextToSpeech::stop()
Stop the currently speaking text.
© 2017 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.