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()
在处理过程中,应用程序无法收听。只有在处理完全完成后才能开始监听。
解决方案
推荐阅读
- prism - Prism View Navigation 在带有重音符号的注册名称上失败
- wordpress - Display attribute images ( Woocommerce )
- javascript - 如何为轮播映射一组子项?
- parse-platform - Parse-server get photo from postman (post-data)
- javascript - mobx: determine that data are added (deleted or modified) to the storage
- scala - 编写可变参数 Scala 谓词方法
- angular - Enable/Disable input field in mat-table when checkbox is selected (Angular 8)
- python - xlwings:如何仅通过 UDF 将 matplotlib 图表附加到 excel 工作表上
- reactjs - Grommet MaskedInput 不适用于多个输入
- sql - SQLBase 联合不适用于别名。为什么?