It is a function to tts after overwriting the textedit value to the txt file. However, if textedit is executed in a blank state, a 'No text to speak' error message is displayed and it is terminated. I tried to open messagebox use 'if-statement' if textedit is empty. but doesn't work. I'll appreciate for your help.
def btstart(self):
text = self.textEdit.toPlainText()
with open('log.txt', 'w') as file:
file.write(text)
if str(text != ""):
file = open("log.txt", "r").read().replace("\n", " ")
tts = gTTS(text = str(file),lang='ko',slow = False)
tts.save("voice.mp3")
pygame.init()
pygame.mixer.music.load('./voice.mp3')
pygame.mixer.music.play()
clock = pygame.time.Clock()
while pygame.mixer.music.get_busy():
clock.tick(60)
pygame.event.poll()
os.remove("./voice.mp3")
if not self.thread.isRunning():
self.bt_start.setEnabled(False)
self.thread.start()
elif str(text == ""):
self.msg.setIcon(QMessageBox.Information)
self.msg.setWindowTitle('empty text')
self.msg.setText('input text')
self.msg.setStandardButtons(QMessageBox.close)
self.msg.exec_()
Aucun commentaire:
Enregistrer un commentaire