python - 我想在我的第一个 python 环境中从第二个 python 环境调用函数。这可能

我正在开发一个虚拟助手。我正在使用 google_speech_to_text 转换器,我无法继续输入音频。我认为如果有任何方法我可以使用两种环境,一种将用于监听和转换文本,另一种用于其余处理。

我不想更改我的 STT 引擎。我只想知道是否可以同时在环境之间切换。如果是,怎么做?

这是我的 input.py 文件:每当我需要进行音频输入时,我都会调用函数 start_listening():

import speech_recognition as sr
import output
import winsound

def start_listening():
    r = sr.Recognizer()
    with sr.Microphone() as source:
        # output.speak("Listening")
        r.adjust_for_ambient_noise(source)
        audio = r.record(source, duration=5)

        try:
            return r.recognize_google(audio)
        except:
            output.speak("Unable to Translate, speak again")
            start_listening()

这是我的 processing.py 文件:

import input as listener
import output as speak
import clock
import query_processor as mind
import rideBooking

#First Greeting at the startup , according to the time select the greeting
speak.speak(clock.get_part_of_day())

def searching_for_word(word,sentence):
    if word in sentence:
        return True
    else:
        return False

def main_organ():
    input = listener.start_listening()
    inputType = mind.classify(input)
    if inputType == 'whatever':
        #run different functions on different commands
        main_organ()


#run the app with the below code
if __name__ == "__main__":
    main_organ()

当处理开启时,应用程序无法收听。它只有在处理完全完成后才能开始监听。

最佳答案

您可以创建多个进程。

为此,导入 multiprocessing.Process.run模块和 recover the return value .

您可以使用 queue处理来自您的子流程的数据。

您不需要多个环境。

关于python - 我想在我的第一个 python 环境中从第二个 python 环境调用函数。这可能吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54936229/

相关文章:

android-studio - adb.exe start-server failed——必要时手

neo4j - 是否可以为在 UNWIND 期间创建的每个节点动态设置可变节点名称?

angular7 - 无法加载 server.component.html

amazon-web-services - 为通过 UserData 创建 AMI 准备 Windo

vuejs2 - 为什么激活的生命周期钩子(Hook)在第一次访问时没有被调用

python - 以编程方式将图片导入 Apple Photos 并修改 Exif 数据

python - PyCharm 导航到库源 - Typeshed Stubs\unittest 和

json - 将包含 json 数据的 pandas 数据框的列拆分为多个列

ansible - 如何获得 ansible playbook 运行更改的任务总数?

reactjs - 我如何将组件引用传递给 redux 存储