Python 麦克风激活时Tkinter应用程序上的文本

Python 麦克风激活时Tkinter应用程序上的文本,python,tkinter,speech-recognition,speech,Python,Tkinter,Speech Recognition,Speech,我正在虚拟助手项目中工作,我希望我的mircophone一旦激活就可以说话,它会在tkinter应用程序上显示,用户可以“立即说话…”。这是我的代码中遇到的一个问题,当麦克风被激活时,文本会在正确的时间正确地打印在python控制台上,但当整个代码循环完成时,它会出现在tkniter应用程序上 请帮帮我 from tkinter import * import tkinter import speech_recognition as sr import playsound # to play

我正在虚拟助手项目中工作,我希望我的mircophone一旦激活就可以说话,它会在tkinter应用程序上显示,用户可以“立即说话…”。这是我的代码中遇到的一个问题,当麦克风被激活时,文本会在正确的时间正确地打印在python控制台上,但当整个代码循环完成时,它会出现在tkniter应用程序上

请帮帮我

from tkinter import *
import tkinter
import speech_recognition as sr 
import playsound # to play saved mp3 file 
from gtts import gTTS # google text to speech 
import os # to save/open files 

import winsound

def get_audio(): 
    rObject = sr.Recognizer() 
    #audio = '' 
    
    with sr.Microphone() as source:
        t1="Speak Now..."
        print(t1)
        winsound.Beep(1000,500)
        root.configure(background='green')
        Label(root,text=t1,font=('Arial',10)).pack(side='left')
        #rObject.pause_threshold = 1
        #audio = rObject.listen(source)
        #rObject.pause_threshold = 1
        # recording the audio using speech recognition 
        
        audio = rObject.listen(source) 
        print("Stop.") # limit 5 secs 
        
    try: 
        text = rObject.recognize_google(audio, language ='en-in') 
        print("You : ", text) 
        return text 

except Exception as e:
    print(e) 
    print("Unable to Recognize your voice.") 
    return "None"

return query

  

缩进在这段代码中是正确的,最后一条语句返回的是什么??是的,缩进在这段代码中是正确的。最后一条语句将返回以文本形式显示用户语音的查询。我的动机是代码能够理解tkinter应用程序中的相同文本,也能在tkinter应用程序中编写相同的文本。