这是一个异步问题吗?

问题描述 投票:-1回答:1

你好,我是编程新手,我面临着这个问题,只有在合成函数完成后,标签才会更新。我应该研究一下异步编程来解决这个问题吗?

self.responseText.config(text = res)和self.changePic(responseImagePath)是用来改变标签属性的。谢谢。

    def chatBot(self):

    audio_source.is_recording = True

    # STT
    stream.start_stream()

    recognize_using_websocket()

    # ASSISTANT
    message = assistant.message(
        assistant_id = CONFIG["assistant"]["assistant_id"],
        session_id = session,
        input = { 'text': recordedInput }
    ).get_result()

    print(message)
    res = message["output"]["generic"][0]["text"]
    self.responseText.config(text = res)
    print("Response: " + res)


    if imagePresence(message) == True:
        responseImagePath =  message["output"]["generic"][1]["source"]
        print("Response Image src: " + responseImagePath)
        self.changePic(responseImagePath)



    # TTS
    test_callback = MySynthesizeCallback()

    tts.synthesize_using_websocket(
        res,
        test_callback,
        accept = "audio/wav",
        voice = "en-US_AllisonVoice"
    )
python asynchronous tkinter
1个回答
0
投票

我和你一样,在需要异步编程的时候,我也是个很陌生的编程高手!因为我和你一样,在构建discord机器人的时候,也是需要异步编程的。看你的情况,我看函数块你所有的代码都要等到它完成。如果你学会了async python,你可以,我的理解是 "将你的程序分割成不同的任务"。

所以,我认为是的。但我可能不正确。

对不起,如果没有帮助

© www.soinside.com 2019 - 2024. All rights reserved.