所以我有一个难题。让我们从我的代码的相关片段开始。
from RECORD import recordSystem
recTime = 30 #Amount of time(seconds) I want to record the audio input
while True: #I want to keep this active while system is running
#Standard raspberry Pi input sensors.
if(GPIO.input(LedPin4) == GPIO.LOW and GPIO.input(LedPin5) == GPIO.HIGH:
recordSystem(recTime) #when condition is met run the code.
因此,我尝试运行的功能来自我编写的另一个脚本。而且有效。它记录模拟音频并在我的项目文件夹中创建一个.wav文件。这段代码的问题在于,它昨天可以正常工作,而现在却找不到。没有任何改变或感动。它只是不想工作。发生的情况是循环开始,并且当满足条件时,该功能会正确启动,并且我在编译器中收到“录制”通知。但是它永远不会停止录制。
当我在循环外执行以下操作时:
recordSystem(recTime)
该功能正常运行,没有任何问题。因此,它必须在循环内调用函数。但是,一段时间以来它一直没有任何问题。
谁能给我最好的客人,说明可能会发生什么?
非常感激!
最佳答案
在break
之后添加recordSystem(recTime)
语句应该可以解决问题!我还修复了缩进,并从代码中删除了一个额外的(
:
from RECORD import recordSystem
recTime = 30 #Amount of time(seconds) I want to record the audio input
while True: #I want to keep this active while system is running
#Standard raspberry Pi input sensors.
if GPIO.input(LedPin4) == GPIO.LOW and GPIO.input(LedPin5) == GPIO.HIGH:
recordSystem(recTime) #when condition is met run the code.
break
关于python - Python:While循环中导入函数的奇怪问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46835902/