PySide6.QtTextToSpeech.QTextToSpeech¶
- class QTextToSpeech¶
- The - QTextToSpeechclass provides a convenient access to text-to-speech engines. More…- Synopsis¶- Properties¶- engineᅟ- The engine used to synthesize text to speech
- engineCapabilitiesᅟ- The capabilities implemented by the current engine
- 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
 - Methods¶- def - __init__()
- def - allVoices()
- def - engine()
- def - errorReason()
- def - errorString()
- def - locale()
- def - pitch()
- def - rate()
- def - setEngine()
- def - state()
- def - voice()
- def - volume()
 - Slots¶- def - enqueue()
- def - pause()
- def - resume()
- def - say()
- def - setLocale()
- def - setPitch()
- def - setRate()
- def - setVoice()
- def - setVolume()
- def - stop()
 - Signals¶
- def - engineChanged()
- def - errorOccurred()
- def - localeChanged()
- def - pitchChanged()
- def - rateChanged()
- def - sayingWord()
- def - stateChanged()
- def - voiceChanged()
- def - volumeChanged()
 - 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().- Use - findVoices()to get a list of matching voices, or use- availableVoices()to get the list of voices that support the current locale. Change the- localeproperty, 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().- Not every engine supports all features. Use the - engineCapabilities()function to test which features are available, and adjust the usage of the class accordingly.- 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 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.Synthesizing - Text is being synthesized into PCM data. The synthesized() signal will be emitted with chunks of data. - 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 
 - class ErrorReason¶
- This enum describes the current error, if any, of the - QTextToSpeechengine.- 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 
 - class 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. - QTextToSpeech.BoundaryHint.Utterance - Stop speech when the current utterance is finished. An utterance is the block of text used in a call to - say()or- enqueue().- Note - These are hints to the engine. The current engine might not support all options. 
 - class Capability¶
- This enum describes the capabilities of a text-to-speech engine. - Constant - Description - QTextToSpeech.Capability.None_ - (inherits - enum.Flag) The engine implements none of the capabilities.- QTextToSpeech.Capability.Speak - The engine can play audio output from text. - QTextToSpeech.Capability.PauseResume - The engine can pause and then resume the audo output. - QTextToSpeech.Capability.WordByWordProgress - The engine emits the - sayingWord()signal for each word that gets spoken.- QTextToSpeech.Capability.Synthesize - The engine can - synthesizePCM audio data from text.- See also - Added in version 6.6. 
 - class SynthesizeOverload¶
 - Note - Properties can be used directly when - from __feature__ import true_propertyis used or via accessor functions otherwise.- property 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 localesand- available voices.- Access functions:
- Signal - engineChanged()
 
 - property engineCapabilitiesᅟ: Combination of QDBusConnection.ConnectionCapability¶
 - This property holds the capabilities implemented by the current engine. - See also - Access functions:
 - 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- findVoices()- Access functions:
- Signal - localeChanged()
 
 - property pitchᅟ: float¶
 - 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:
- Signal - pitchChanged()
 
 - property rateᅟ: float¶
 - 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:
- Signal - rateChanged()
 
 - property stateᅟ: QTextToSpeech.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(tr("Speech started...")) break elif state == QTextToSpeech.Ready: ui.statusbar.showMessage(tr("Speech stopped..."), 2000) break elif state == QTextToSpeech.Paused: ui.statusbar.showMessage(tr("Speech paused...")) break else: ui.statusbar.showMessage(tr("Speech error!")) break 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- voiceand- locale.- Access functions:
- Signal - stateChanged()
 
 - This property holds the voice that will be used for the speech.. - The voice needs to be one of the - voices availablefor 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.- See also - findVoices()- Access functions:
- Signal - voiceChanged()
 
 - property volumeᅟ: float¶
 - This property holds the current volume, ranging from 0.0 to 1.0.. - The default value is the platform’s default volume. - Access functions:
- Signal - volumeChanged()
 
 - Loads a text-to-speech engine from a plug-in that uses the default engine plug-in and constructs a - QTextToSpeechobject as the child of- parent.- The default engine is platform-specific. - If the engine initializes correctly, then the - stateof the engine will change to- Ready; note that this might happen asynchronously. If the plugin fails to load, then- statewill be set to- Error.- See also - __init__(engine[, parent=None])
- Parameters:
- engine – str 
- parent – - QObject
 
 
 - Loads a text-to-speech engine from a plug-in that matches parameter - engineand constructs a- QTextToSpeechobject as the child of- parent.- If - engineis empty, the default engine plug-in is used. The default engine is platform-specific.- If the engine initializes correctly, the - stateof the engine will be set to- Ready. If the plugin fails to load, or if the engine fails to initialize, the engine’s- statewill be set to- Error.- See also - __init__(engine, params[, parent=None])
- Parameters:
- engine – str 
- params – Dictionary with keys of type .QString and values of type QVariant. 
- parent – - QObject
 
 
 - Loads a text-to-speech engine from a plug-in that matches parameter - engineand constructs a- QTextToSpeechobject as the child of- parent, passing- paramsthrough to the engine.- If - engineis empty, the default engine plug-in is used. The default engine is platform-specific. Which key/value pairs in- paramsare supported depends on the engine. See the engine documentation for details. Unsupported entries will be ignored.- If the engine initializes correctly, the - stateof the engine will be set to- Ready. If the plugin fails to load, or if the engine fails to initialize, the engine’s- statewill be set to- Error.- See also - aboutToSynthesize(id)¶
- Parameters:
- id – int 
 
 - This signal gets emitted just before the engine starts to synthesize the speech audio for - id. The- idis the value returned by a call to- enqueue(), Applications can use this signal to make last-minute changes to- voiceattributes, or to track the process of text enqueued via- enqueue().- static availableEngines()¶
- Return type:
- list of strings 
 
 - Gets the list of supported text-to-speech engine plug-ins. - See also - Returns the list of locales that are supported by the active - engine.- See also - availableVoices()- findVoices()- Returns the list of voices available for the current - locale.- engine()¶
- Return type:
- str 
 - See also 
 - Getter of property - engineᅟ.- engineCapabilities()¶
- Return type:
- Combination of - Capability
 
 - engineChanged(engine)¶
- Parameters:
- engine – str 
 
 - Notification signal of property - engineᅟ.- enqueue(text)¶
- Parameters:
- text – str 
- Return type:
- int 
 
 - Adds - utteranceto the queue of texts to be spoken, and starts speaking. Returns the index of the text in the queue, or -1 in case of an error.- If the engine’s - stateis currently- Ready,- utterancewill be spoken immediately. Otherwise, the engine will start to speak- utteranceonce it has finished speaking the current text.- Each time the engine proceeds to the next text entry in the queue, the - aboutToSynthesize()signal gets emitted. This allows applications to keep track of the progress, and to make last-minute changes to voice attributes.- Calling - stop()clears the queue. To pause the engine at the end of a text, use the- Utteranceboundary hint.- See also - say()- stop()- aboutToSynthesize()- synthesize()- errorOccurred(error, errorString)¶
- Parameters:
- error – - ErrorReason
- errorString – str 
 
 
 - This signal is emitted after an error occurred and the - statehas been set to- Error. The- reasonparameter specifies the type of error, and the- errorStringprovides a human-readable error description.- ErrorReasonis not a registered metatype, so for queued connections, you will have to register it with Q_DECLARE_METATYPE() and qRegisterMetaType().- See also - errorReason()- errorString()- Creating Custom Qt Types- errorReason()¶
- Return type:
 
 - Returns the reason why the engine has reported an error. - See also - errorString()¶
- Return type:
- str 
 
 - Returns the current engine error message. - See also - locale()¶
- Return type:
 - See also 
 - Getter of property - localeᅟ.- Notification signal of property - localeᅟ.- pause([boundaryHint=QTextToSpeech.BoundaryHint.Default])¶
- Parameters:
- boundaryHint – - BoundaryHint
 
 - Pauses the current speech at - boundaryHint.- Whether the - boundaryHintis respected depends on the- engine.- See also - resume()- PauseResume- pitch()¶
- Return type:
- float 
 - See also 
 - Getter of property - pitchᅟ.- pitchChanged(pitch)¶
- Parameters:
- pitch – float 
 
 - Notification signal of property - pitchᅟ.- Getter of property - rateᅟ.- rateChanged(rate)¶
- Parameters:
- rate – float 
 
 - Notification signal of property - rateᅟ.- resume()¶
 - Resume speaking after - pause()has been called.- Note - On Android, resuming paused speech will restart from the beginning. This is a limitation of the underlying text-to-speech engine. - See also - say(text)¶
- Parameters:
- text – str 
 
 - Warning - This section contains snippets that were automatically translated from C++ to Python and may contain errors. - Starts speaking 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 - stateproperty, and is set to- Speakingonce the reading starts. When the reading is done,- statewill be set to- Ready.- sayingWord(word, id, start, length)¶
- Parameters:
- word – str 
- id – int 
- start – int 
- length – int 
 
 
 - This signal is emitted when the - word, which is the slice of text indicated by- startand- lengthin the utterance- id, gets played to the audio device.- setEngine(engine[, params=QVariantMap()])¶
- Parameters:
- engine – str 
- params – Dictionary with keys of type .QString and values of type QVariant. 
 
- Return type:
- bool 
 
 - Sets the engine used by this - QTextToSpeechobject to- engine, passing- paramsthrough to the engine constructor.- Returns whether - enginecould be set successfully.- Which key/value pairs in - paramsare supported depends on the engine. See the engine documentation for details. Unsupported entries will be ignored.- See also - Setter of property - localeᅟ.- Setter of property - pitchᅟ.- Setter of property - rateᅟ.- Setter of property - voiceᅟ.- Setter of property - volumeᅟ.- Getter of property - stateᅟ.- Notification signal of property - stateᅟ.- stop([boundaryHint=QTextToSpeech.BoundaryHint.Default])¶
- Parameters:
- boundaryHint – - BoundaryHint
 
 - Stops the current reading at - boundaryHint, and clears the queue of pending texts.- The reading cannot be resumed. Whether the - boundaryHintis respected depends on the engine.- voice()¶
- Return type:
 - See also 
 - Getter of property - voiceᅟ.- Notification signal of property - voiceᅟ.- volume()¶
- Return type:
- float 
 - See also 
 - Getter of property - volumeᅟ.- volumeChanged(volume)¶
- Parameters:
- volume – float 
 
 - Notification signal of property - volumeᅟ.