python - Python:While循环中导入函数的奇怪问题

标签 python audio

所以我有一个难题。让我们从我的代码的相关片段开始。

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/

相关文章:

python - 在 Mac OS X 上使用 pyenv 安装 PyYaml;找不到文件 : python. exe

python - 如何使用 PYTHON 从以下列表中提取手机名称?

swift 3 FFT 获取声音频率 m4a

android - Superpowered SDK - 监控麦克风输入

c - Windows 中低级音频的最佳 API?

python - `along a specific axis`操作是如何实现的?

python - PyQt4 中的多列(可能使用 QTreeWidget)

audio - 将 video/webm;codecs=vp9 转换为 .flac

python - 使用 pyDub 分割长音频文件

Python:类中的字典变量