'How to generate text in a new line in text edit? [duplicate]
I am creating a speech-to-text generator gui in pyqt5. The program takes input from microphone and sets the text of the text area accordingly but everytime the user takes an input, the whole text of the text edit changes. Is there any method as how to generate the second input in a new line in the text edit. Below is the code I am using.
This is the coding part for the text edit portion
self.text_area = QtWidgets.QTextEdit(self.centralwidget)
self.text_area.setGeometry(QtCore.QRect(10, 240, 621, 171))
font = QtGui.QFont()
font.setPointSize(10)
self.text_area.setFont(font)
self.text_area.setObjectName("text_area")
This is the method for recording
def record(self):
r = sr.Recognizer()
try:
with sr.Microphone() as source:
audio = r.listen(source)
MyText = r.recognize_google(audio)
MyText = MyText.lower()
self.text_area.setText(MyText)
except Exception as e4:
print(e4)
Solution 1:[1]
You want to add the new text to the existing
allText=self.text_area.toPlainText()+myText
self.text_area.setText(allText)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
