I'm using Azure speech recognition and I want to create my own speech to text app and I want to show the text on PyQt5 window.
I still can't figure out how can I get the recognized text as an output to be displayed...
I got this code from another source and it was using tinkter to show the text on a window and I want to do the same thing
The source of the original code:
https://github.com/jimbobbennett/TwitchCaptioner/blob/master/captioner.py
This is the code of what I'm trying to do!
`
import sys
from PyQt5.QtWidgets import QApplication
from PyQt5.QtWidgets import QVBoxLayout
from PyQt5.QtWidgets import QPushButton
from PyQt5.QtWidgets import QWidget
from PyQt5.QtWidgets import QLabel
import math
import time
import azure.cognitiveservices.speech as speechsdk
import config
from PyQt5.QtWidgets import *
from azure.cognitiveservices.speech import SpeechConfig
def recognizing(args):
global labelText
labelText.set(args.result.text)
resultReco = args.result.text
print(resultReco)
def recognized(args):
global f
if args.result.text.strip() != '':
f.write(args.result.text + "
")
speech_key, service_region = "", "" # key and service region goes here
speech_config = speechsdk.SpeechConfig(subscription=speech_key, region=service_region)
speech_recognizer = speechsdk.SpeechRecognizer(speech_config=speech_config)
result = speech_recognizer.recognizing.connect(recognizing)
speech_recognizer.recognized.connect(recognized)
speech_recognizer.start_continuous_recognition()
app = QApplication(sys.argv)
window = QWidget()
window.setWindowTitle("WindowTitle")
layout = QVBoxLayout()
label = QLabel(result)
layout.addWidget(label)
window.setLayout(layout)
window.show()
sys.exit(app.exec_())
`
The output now!:
update ..................................................................................................................................................................
I'm trying to go for another approach ...... I'm trying to implement one-shot recognition but I can't understand how to update the text in the label as I'm talking......
here is my code
import config
import azure.cognitiveservices.speech as speechsdk
import time
import wave
import sys
from PyQt5 import QtCore, QtWidgets
from PyQt5.QtWidgets import QApplication
from PyQt5.QtWidgets import QVBoxLayout
from PyQt5.QtWidgets import QPushButton
from PyQt5.QtWidgets import QWidget
from PyQt5.QtWidgets import QLabel
import math
from PyQt5.QtWidgets import *
from azure.cognitiveservices.speech import SpeechConfig
speech_key, service_region = "", "" # speech key and region goes here
speech_config = speechsdk.SpeechConfig(subscription=speech_key, region=service_region)
speech_recognizer = speechsdk.SpeechRecognizer(speech_config=speech_config)
def speech_to_Print():
# section of code for audio input
result = speech_recognizer.recognize_once()
sentence = result.text # register the text from speech into sentence field
print(sentence)
return sentence
class QRecognizer(QtCore.QObject):
textChanged = QtCore.pyqtSignal(str)
def __init__(self, key, region, parent=None):
super().__init__(parent)
config = speechsdk.SpeechConfig(subscription=key, region=region)
self._recognizer = speechsdk.SpeechRecognizer(speech_config=config)
def main():
import sys
app = QtWidgets.QApplication(sys.argv)
speech_key, service_region = "", "" # speech key and region goes here
qrecognizer = QRecognizer(speech_key, service_region)
w = QtWidgets.QWidget()
while True:
newSentence = speech_to_Print()
label = QtWidgets.QLabel(newSentence)
qrecognizer.textChanged.connect(label.setText)
lay = QtWidgets.QVBoxLayout(w)
lay.addWidget(label)
w.show()
sys.exit(app.exec_())
if __name__ == "__main__":
main()
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…