QTextToSpeech#

The QTextToSpeech class provides a convenient access to text-to-speech engines. More

Inheritance diagram of PySide6.QtTextToSpeech.QTextToSpeech

Synopsis#

Properties#

  • engine - The engine used to synthesize text to speech

  • locale - The current locale in use

  • pitch - The voice pitch, ranging from -1.0 to 1.0

  • rate - The current voice rate, ranging from -1.0 to 1.0

  • state - The current state of the speech synthesizer

  • voice - The voice that will be used for the speech

  • volume - The current volume, ranging from 0.0 to 1.0

Functions#

Slots#

Signals#

Static functions#

Note

This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE

Detailed Description#

Warning

This section contains snippets that were automatically translated from C++ to Python and may contain errors.

Use say() to start reading text to the default audio device, and stop() , pause() , and resume() to control the reading of the text.

ui.speakButton.clicked.connect(m_speech, [this]{
    m_speech.say(ui.plainTextEdit.toPlainText())
})        ui.stopButton.clicked.connect(m_speech, [this]{
    m_speech.stop()
})        ui.pauseButton.clicked.connect(m_speech, [this]{
    m_speech.pause()
})        ui.resumeButton.clicked.connect(m_speech.resume)

To synthesize text into PCM data for further processing, use synthesize().

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:

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 .

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 .

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 .

Note

Properties can be used directly when from __feature__ import true_property is used or via accessor functions otherwise.

property PᅟySide6.QtTextToSpeech.QTextToSpeech.engine: 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 .

Access functions:
property PᅟySide6.QtTextToSpeech.QTextToSpeech.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

voice

Access functions:
property PᅟySide6.QtTextToSpeech.QTextToSpeech.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.

Access functions:
property PᅟySide6.QtTextToSpeech.QTextToSpeech.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.

Access functions:
property PᅟySide6.QtTextToSpeech.QTextToSpeech.state: State#

Warning

This section contains snippets that were automatically translated from C++ to Python and may contain errors.

This property holds the current state of the speech synthesizer..

def stateChanged(self, state):

    if state == QTextToSpeech.Speaking:
        ui.statusbar.showMessage("Speech started...")
     elif state == QTextToSpeech.Ready:
        ui.statusbar.showMessage("Speech stopped...", 2000)
    elif state == QTextToSpeech.Paused:
        ui.statusbar.showMessage("Speech paused...")
else:
        ui.statusbar.showMessage("Speech error!")
    ui.pauseButton.setEnabled(state == QTextToSpeech.Speaking)
    ui.resumeButton.setEnabled(state == QTextToSpeech.Paused)
    ui.stopButton.setEnabled(state == QTextToSpeech.Speaking or state == QTextToSpeech.Paused)

Use say() to start synthesizing text with the current voice and locale .

Access functions:
property PᅟySide6.QtTextToSpeech.QTextToSpeech.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.

Access functions:
property PᅟySide6.QtTextToSpeech.QTextToSpeech.volume: double#

This property holds the current volume, ranging from 0.0 to 1.0..

The default value is the platform’s default volume.

Access functions:
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

errorOccurred()

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

engine

PySide6.QtTextToSpeech.QTextToSpeech.availableLocales()#

Returns the list of locales that are supported by the active engine .

PySide6.QtTextToSpeech.QTextToSpeech.availableVoices()#

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

See also

setEngine()

Getter of property engine .

PySide6.QtTextToSpeech.QTextToSpeech.engineChanged(engine)#
Parameters:

engine – str

Notification signal of property engine .

PySide6.QtTextToSpeech.QTextToSpeech.errorOccurred(error, errorString)#
Parameters:

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:

ErrorReason

Returns the reason why the engine has reported an error.

PySide6.QtTextToSpeech.QTextToSpeech.errorString()#
Return type:

str

Returns the current engine error message.

See also

errorOccurred()

PySide6.QtTextToSpeech.QTextToSpeech.locale()#
Return type:

PySide6.QtCore.QLocale

See also

setLocale()

Getter of property locale .

PySide6.QtTextToSpeech.QTextToSpeech.localeChanged(locale)#
Parameters:

localePySide6.QtCore.QLocale

Notification signal of property locale .

PySide6.QtTextToSpeech.QTextToSpeech.pause([boundaryHint=QTextToSpeech.BoundaryHint.Default])#
Parameters:

boundaryHintBoundaryHint

Pauses the current speech at boundaryHint.

Whether the boundaryHint is respected depends on the engine .

See also

resume()

PySide6.QtTextToSpeech.QTextToSpeech.pitch()#
Return type:

double

See also

setPitch()

Getter of property pitch .

PySide6.QtTextToSpeech.QTextToSpeech.pitchChanged(pitch)#
Parameters:

pitchdouble

Notification signal of property pitch .

PySide6.QtTextToSpeech.QTextToSpeech.rate()#
Return type:

double

See also

setRate()

Getter of property rate .

PySide6.QtTextToSpeech.QTextToSpeech.rateChanged(rate)#
Parameters:

ratedouble

Notification signal of property rate .

PySide6.QtTextToSpeech.QTextToSpeech.resume()#

Resume speaking after pause() has been called.

See also

pause()

PySide6.QtTextToSpeech.QTextToSpeech.say(text)#
Parameters:

text – str

Warning

This section contains snippets that were automatically translated from C++ to Python and may contain errors.

Starts synthesizing the text.

This function starts sythesizing the speech asynchronously, and reads the text to the default audio output device.

ui.speakButton.clicked.connect(m_speech, [this]{
    m_speech.say(ui.plainTextEdit.toPlainText())
})

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

engine()

PySide6.QtTextToSpeech.QTextToSpeech.setLocale(locale)#
Parameters:

localePySide6.QtCore.QLocale

See also

locale()

Setter of property locale .

PySide6.QtTextToSpeech.QTextToSpeech.setPitch(pitch)#
Parameters:

pitchdouble

See also

pitch()

Setter of property pitch .

PySide6.QtTextToSpeech.QTextToSpeech.setRate(rate)#
Parameters:

ratedouble

See also

rate()

Setter of property rate .

PySide6.QtTextToSpeech.QTextToSpeech.setVoice(voice)#
Parameters:

voicePySide6.QtTextToSpeech.QVoice

See also

voice()

Setter of property voice .

PySide6.QtTextToSpeech.QTextToSpeech.setVolume(volume)#
Parameters:

volumedouble

See also

volume()

Setter of property volume .

PySide6.QtTextToSpeech.QTextToSpeech.state()#
Return type:

State

Getter of property state .

PySide6.QtTextToSpeech.QTextToSpeech.stateChanged(state)#
Parameters:

stateState

Notification signal of property state .

PySide6.QtTextToSpeech.QTextToSpeech.stop([boundaryHint=QTextToSpeech.BoundaryHint.Default])#
Parameters:

boundaryHintBoundaryHint

Stops the current reading at boundaryHint.

The reading cannot be resumed. Whether the boundaryHint is respected depends on the engine.

See also

say() pause()

PySide6.QtTextToSpeech.QTextToSpeech.voice()#
Return type:

PySide6.QtTextToSpeech.QVoice

See also

setVoice()

Getter of property voice .

PySide6.QtTextToSpeech.QTextToSpeech.voiceChanged(voice)#
Parameters:

voicePySide6.QtTextToSpeech.QVoice

Notification signal of property voice .

PySide6.QtTextToSpeech.QTextToSpeech.volume()#
Return type:

double

See also

setVolume()

Getter of property volume .

PySide6.QtTextToSpeech.QTextToSpeech.volumeChanged(volume)#
Parameters:

volumedouble

Notification signal of property volume .