我想在我的第一个 python 环境中从第二个 python 环境调用函数。这可能吗?
I want to call functions from second python environment in my my first python environment. Is this possible?
我正在开发一个虚拟助手。我正在使用 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()
当处理处于开启状态时,应用程序无法收听。只有在处理完全完成后才能start_listening。
您可以创建多个进程。
为此,请导入 multiprocessing.Process.run
module and recover the return value。
您可以使用 queue 来处理来自子进程的数据。
您不需要多个环境。
我正在开发一个虚拟助手。我正在使用 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()
当处理处于开启状态时,应用程序无法收听。只有在处理完全完成后才能start_listening。
您可以创建多个进程。
为此,请导入 multiprocessing.Process.run
module and recover the return value。
您可以使用 queue 来处理来自子进程的数据。
您不需要多个环境。