QTextToSpeech#
The QTextToSpeech
class provides a convenient access to text-to-speech engines. More…
Synopsis#
Functions#
def
availableLocales
()def
availableVoices
()def
engine
()def
errorReason
()def
errorString
()def
locale
()def
pitch
()def
rate
()def
setEngine
(engine[, params=QVariantMap()])def
state
()def
voice
()def
volume
()
Slots#
Signals#
def
engineChanged
(engine)def
errorOccurred
(error, errorString)def
localeChanged
(locale)def
pitchChanged
(pitch)def
rateChanged
(rate)def
stateChanged
(state)def
voiceChanged
(voice)def
volumeChanged
(volume)
Static functions#
def
availableEngines
()
Detailed Description#
Use say()
to start synthesizing text, and stop()
, pause()
, and resume()
to control the reading of the text.
The list of voices the engine supports for the current language is returned by availableVoices()
. Change the language using setLocale()
, using one of the availableLocales()
that is a good match for the language that the input text is in, and for the accent of the desired voice output. This will change the list of available voices on most platforms. Then use one of the available voices in a call to setVoice()
.
Note
Which locales and voices the engine supports depends usually on the Operating System configuration. E.g. on macOS, end users can install voices through the Accessibility panel in System Preferences.
- class PySide6.QtTextToSpeech.QTextToSpeech([parent=None])#
PySide6.QtTextToSpeech.QTextToSpeech(engine[, parent=None])
PySide6.QtTextToSpeech.QTextToSpeech(engine, params[, parent=None])
- Parameters
params –
engine – str
parent –
PySide6.QtCore.QObject
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 is platform-specific.
If the engine initializes correctly, then the state
of the engine will change to Ready
; note that this might happen asynchronously. If the plugin fails to load, then state
will be set to Error
.
See also
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 is platform-specific.
If the engine initializes correctly, the state
of the engine will be set to Ready
. If the plugin fails to load, or if the engine fails to initialize, the engine’s state
will be set to Error
.
See also
Loads a text-to-speech engine from a plug-in that matches parameter engine
and constructs a QTextToSpeech
object as the child of parent
, passing params
through to the engine.
If engine
is empty, the default engine plug-in is used. The default engine is platform-specific. Which key/value pairs in params
are supported depends on the engine. See the engine documentation for details. Unsupported entries will be ignored.
If the engine initializes correctly, the state
of the engine will be set to Ready
. If the plugin fails to load, or if the engine fails to initialize, the engine’s state
will be set to Error
.
See also
- PySide6.QtTextToSpeech.QTextToSpeech.State#
This enum describes the current state of the text-to-speech engine.
Constant
Description
QTextToSpeech.Ready
The synthesizer is ready to start a new text. This is also the state after a text was finished.
QTextToSpeech.Speaking
Text is being spoken.
QTextToSpeech.Paused
The synthesis was paused and can be resumed with
resume()
.QTextToSpeech.Error
An error has occurred. Details are given by
errorReason()
.See also
ErrorReason
errorReason()
errorString()
- PySide6.QtTextToSpeech.QTextToSpeech.ErrorReason#
This enum describes the current error, if any, of the QTextToSpeech
engine.
Constant
Description
QTextToSpeech.ErrorReason.NoError
No error has occurred.
QTextToSpeech.ErrorReason.Initialization
The backend could not be initialized, e.g. due to a missing driver or operating system requirement.
QTextToSpeech.ErrorReason.Configuration
The given backend configuration is inconsistent, e.g. due to wrong voice name or parameters.
QTextToSpeech.ErrorReason.Input
The given text could not be synthesized, e.g. due to invalid size or characters.
QTextToSpeech.ErrorReason.Playback
Audio playback failed e.g. due to missing audio device, wrong format or audio streaming interruption.
Use errorReason()
to obtain the current error and errorString()
to get the related error message.
See also
- PySide6.QtTextToSpeech.QTextToSpeech.BoundaryHint#
describes when speech should be stopped and paused.
Constant
Description
QTextToSpeech.BoundaryHint.Default
Uses the engine specific default behavior.
QTextToSpeech.BoundaryHint.Immediate
The engine should stop playback immediately.
QTextToSpeech.BoundaryHint.Word
Stop speech when the current word is finished.
QTextToSpeech.BoundaryHint.Sentence
Stop speech when the current sentence is finished.
Note
These are hints to the engine. The current engine might not support all options.
- static PySide6.QtTextToSpeech.QTextToSpeech.availableEngines()#
- Return type
list of strings
Gets the list of supported text-to-speech engine plug-ins.
See also
- PySide6.QtTextToSpeech.QTextToSpeech.availableLocales()#
- Return type
Returns the list of locales that are supported by the active engine
.
- PySide6.QtTextToSpeech.QTextToSpeech.availableVoices()#
- Return type
Returns the list of voices available for the current locale
.
Note
If no locale has been set, the system locale is used.
- PySide6.QtTextToSpeech.QTextToSpeech.engine()#
- Return type
str
This property holds the engine used to synthesize text to speech..
Changing the engine stops any ongoing speech.
On most platforms, changing the engine will update the list of available locales
and available voices
.
- PySide6.QtTextToSpeech.QTextToSpeech.engineChanged(engine)#
- Parameters
engine – str
- PySide6.QtTextToSpeech.QTextToSpeech.errorOccurred(error, errorString)#
- Parameters
error –
ErrorReason
errorString – str
This signal is emitted after an error occurred and the state
has been set to Error
. The reason
parameter specifies the type of error, and the errorString
provides a human-readable error description.
ErrorReason
is not a registered metatype, so for queued connections, you will have to register it with Q_DECLARE_METATYPE()
and qRegisterMetaType()
.
- PySide6.QtTextToSpeech.QTextToSpeech.errorReason()#
- Return type
Returns the reason why the engine has reported an error.
See also
- PySide6.QtTextToSpeech.QTextToSpeech.errorString()#
- Return type
str
Returns the current engine error message.
See also
- PySide6.QtTextToSpeech.QTextToSpeech.locale()#
- Return type
This property holds the current locale in use..
By default, the system locale is used.
On some platforms, changing the locale will update the list of available voices
, and if the current voice is not available with the new locale, a new voice will be set.
See also
- PySide6.QtTextToSpeech.QTextToSpeech.localeChanged(locale)#
- Parameters
locale –
PySide6.QtCore.QLocale
- PySide6.QtTextToSpeech.QTextToSpeech.pause([boundaryHint=QTextToSpeech.BoundaryHint.Default])#
- Parameters
boundaryHint –
BoundaryHint
Pauses the current speech at boundaryHint
.
Whether the boundaryHint
is respected depends on the engine
.
See also
- PySide6.QtTextToSpeech.QTextToSpeech.pitch()#
- Return type
double
This property holds the voice pitch, ranging from -1.0 to 1.0..
The default of 0.0 is the normal speech pitch.
- PySide6.QtTextToSpeech.QTextToSpeech.pitchChanged(pitch)#
- Parameters
pitch –
double
- PySide6.QtTextToSpeech.QTextToSpeech.rate()#
- Return type
double
This property holds the current voice rate, ranging from -1.0 to 1.0..
The default value of 0.0 is normal speech flow.
- PySide6.QtTextToSpeech.QTextToSpeech.rateChanged(rate)#
- Parameters
rate –
double
- PySide6.QtTextToSpeech.QTextToSpeech.resume()#
Resume speaking after pause()
has been called.
See also
- PySide6.QtTextToSpeech.QTextToSpeech.say(text)#
- Parameters
text – str
Starts synthesizing the text
.
This function starts sythesizing the speech asynchronously, and reads the text to the default audio output device.
Note
All in-progress readings are stopped before beginning to read the recently synthesized text.
The current state is available using the state
property, and is set to Speaking
once the reading starts. When the reading is done, state
will be set to Ready
.
- PySide6.QtTextToSpeech.QTextToSpeech.setEngine(engine[, params=QVariantMap()])#
- Parameters
engine – str
params –
- Return type
bool
Sets the engine used by this QTextToSpeech
object to engine
, passing params
through to the engine constructor.
Returns whether engine
could be set successfully.
Which key/value pairs in params
are supported depends on the engine. See the engine documentation for details. Unsupported entries will be ignored.
See also
- PySide6.QtTextToSpeech.QTextToSpeech.setLocale(locale)#
- Parameters
locale –
PySide6.QtCore.QLocale
This property holds the current locale in use..
By default, the system locale is used.
On some platforms, changing the locale will update the list of available voices
, and if the current voice is not available with the new locale, a new voice will be set.
See also
- PySide6.QtTextToSpeech.QTextToSpeech.setPitch(pitch)#
- Parameters
pitch –
double
This property holds the voice pitch, ranging from -1.0 to 1.0..
The default of 0.0 is the normal speech pitch.
- PySide6.QtTextToSpeech.QTextToSpeech.setRate(rate)#
- Parameters
rate –
double
This property holds the current voice rate, ranging from -1.0 to 1.0..
The default value of 0.0 is normal speech flow.
- PySide6.QtTextToSpeech.QTextToSpeech.setVoice(voice)#
- Parameters
voice –
PySide6.QtTextToSpeech.QVoice
This property holds the voice that will be used for the speech..
The voice needs to be one of the voices available
for the engine.
On some platforms, setting the voice changes other voice attributes such as locale
, pitch
, and so on. These changes trigger the emission of signals.
- PySide6.QtTextToSpeech.QTextToSpeech.setVolume(volume)#
- Parameters
volume –
double
This property holds the current volume, ranging from 0.0 to 1.0..
The default value is the platform’s default volume.
This property holds the current state of the speech synthesizer..
Use say()
to start synthesizing text with the current voice
and locale
.
- PySide6.QtTextToSpeech.QTextToSpeech.stop([boundaryHint=QTextToSpeech.BoundaryHint.Default])#
- Parameters
boundaryHint –
BoundaryHint
Stops the current reading at boundaryHint
.
The reading cannot be resumed. Whether the boundaryHint
is respected depends on the engine.
- PySide6.QtTextToSpeech.QTextToSpeech.voice()#
- Return type
This property holds the voice that will be used for the speech..
The voice needs to be one of the voices available
for the engine.
On some platforms, setting the voice changes other voice attributes such as locale
, pitch
, and so on. These changes trigger the emission of signals.
- PySide6.QtTextToSpeech.QTextToSpeech.voiceChanged(voice)#
- Parameters
voice –
PySide6.QtTextToSpeech.QVoice
- PySide6.QtTextToSpeech.QTextToSpeech.volume()#
- Return type
double
This property holds the current volume, ranging from 0.0 to 1.0..
The default value is the platform’s default volume.
- PySide6.QtTextToSpeech.QTextToSpeech.volumeChanged(volume)#
- Parameters
volume –
double