生成频率为 x 的音调持续时间 y 并保持其他代码在音调期间执行



在高层次上,我试图实现FFT分析数据记录的自动化。现在,我正在使用音调发生器生成恒定音调,然后记录系统的输出。录制完成后,提示音停止。对整个频域重复此操作。之后,所有数据都通过各种分析步骤(例如FFT(进行处理。所有这些都是在Python3中完成

的。

我一直在尝试在这个过程中自动化无聊的东西,我想去掉手动频率扫描。

我需要的是生成持续时间 y 的频率 x 的音调。启用提示音后,我需要代码执行才能继续录制。

到目前为止,在我搜索中,我找到了winsound。但是winsound.beep不适用于winsound的异步选项,我想避免使用录制的信号。现在我没主意了。有人可以帮助我吗?

示例代码:

import winsound
winsound.Beep(500,1000)
print('this is not simultaneously printed with the sound playing')

@furas 感谢您的反馈,以及您使用线程的建议 我已经设法进行了概念验证。我在这里提供反馈和我的基本代码,以防其他人遇到这个问题。 导入线程 导入时间 导入日志记录 导入盈声

logging.basicConfig(level=logging.DEBUG,
                    format='(%(threadName)-10s) %(message)s',
                    )
def makeTone(freq,dur):
    logging.debug('Starting Sound with f=%sHz for t=%ss',freq,dur)
    winsound.Beep(freq,dur)
    logging.debug('Sound stopped')
def recorder():
    logging.debug('Startrecording')
    time.sleep(3)
    logging.debug('Stoprecording')
frequency = 500 #Hz
duration = 5000 #ms
makeTone = threading.Thread(name='makeTone', target=makeTone,args=(frequency, duration))
recorder = threading.Thread(name='recorder', target=recorder)
makeTone.start()
recorder.start()

相关内容

最新更新