python录音中断触发_如何在不确定的持续时间内以python录制音频并允许暂停和恢复功能?...

这篇博客探讨了如何使用Python实现一个音频录制应用程序,该应用能够在用户按下暂停或停止按钮时记录WAV文件。重点在于如何在不知道录音长度的情况下避免内存溢出,并实现暂停和恢复功能。通过使用sound-device和sound-file库,博主提出了一个解决方案,当用户暂停时,将当前录音保存为单独的WAV文件,恢复时开始新的录音,最后在用户停止时合并所有录音文件。
摘要由CSDN通过智能技术生成

I'm writing a Python app to record audio as a WAV file until a user presses pause or stop. After pausing the audio, the user should also be able to resume recording. Additionally:

The app can't know how long the recording will be beforehand

The app should avoid running out of memory (since the recording could be very long). For example, it could write to the WAV file in real-time to prevent storing the growing recording in memory.

What's a good approach for this problem? Can you please provide some code snippets for your solution?

With

I don't know how big to make the array (since I don't know the recording duration)

What would I do when the array fills up?

How would I incorporate 'pause' and 'resume' features? Sound-file has only read and write methods.

Is there a better way to stop the stream than using a KeyBoardInterrupt?

Could I create different recording after every 'pause' and combine the WAV files after the user clicks 'stop'?

I tried using Threading.Event() to block the recording thread to mimic a pause feature, but the recording kept writing to the file

My attempt at sound-device approach

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值