I'm trying to get Text-To-Speech included within the python-pyqt package.

It looks like the definition is simply missing a declaration for qtspeech 
(patch attached).  I updated the definition, the package builds, and I'm now 
able to import the QtTextToSpeech module.  However, I'm not able to find an 
engine, so I can't verify that it's working 100%.

To validate the new pyqt functionality, I'm trying to get TTS working using the 
python-pyside-2 package.  That definition already has qtspeech included and I 
assume it works.  Unfortunately, I can't get that to work either.

I've installed speech-dispatcher, espeak, espeak-ng, and festival.  I'm able to 
get TTS from the command-line (i.e. spd-say, speak, etc.).  However, no voices 
or engine are found by PyQt or PySide.  I've verified that the same program 
works on a separate Debian machine.  Is there some setup for speech-dispatcher 
that I'm missing?

import sys
from PySide2 import QtCore, QtWidgets, QtTextToSpeech


class MainWindow(QtWidgets.QMainWindow):

    def __init__(self):
        super().__init__()

        self.engine = None
        self.engine_name = None

        text ='''Every effort has been made to replicate this text as 
faithfully as
possible, including inconsistencies in spelling and hyphenation.  Some
corrections of spelling and punctuation have been made. They are
listed at the end of the text.'''

        self.text_edit = QtWidgets.QTextEdit()
        self.text_edit.setText(text)

        self.speak_button = QtWidgets.QPushButton('Speak once')
        self.speak_button.clicked.connect(self.on_speak_button_clicked)

        # Central widget
        layout = QtWidgets.QVBoxLayout()
        layout.addWidget(self.text_edit)
        layout.addWidget(self.speak_button)

        centralWidget = QtWidgets.QWidget()
        centralWidget.setLayout(layout)
        self.setCentralWidget(centralWidget)

        engineNames = QtTextToSpeech.QTextToSpeech.availableEngines()

        if len(engineNames) > 0:
            self.engine_name = engineNames[0]
            self.engine = QtTextToSpeech.QTextToSpeech(self.engine_name)

            voice = self.engine.availableVoices()[0]
            self.engine.setVoice(voice)
        else:
            self.speak_button.setEnabled(False)

    def on_speak_button_clicked(self):
        text = self.text_edit.toPlainText()
        self.engine.say(text)



if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    mainWin = MainWindow()
    mainWin.show()
    sys.exit(app.exec_())

Attachment: 0001-Add-qtspeech-to-python-pyqt.patch
Description: Binary data

Reply via email to