python mac程序结束发出声音_捕获的Mac OS X系统的音频输出与Python

I've been trying to "hijack" the Mac OS X system audio using PyAudio and save to a wav in python. That is, I do not want to record from an input device such as a microphone. I want to grab the sound output from any or all applications.

I have followed the tutorials on the PyAudio site but these do not appear to cover my use case and when I try to read from the output stream I unsurprisingly get the paCanNotReadFromAnOutputOnlyStream exception. Fair enough! Is there a way to do what I am proposing with the PyAudio or other FOSS Python Library?

解决方案

I found that an open-source project called SoundFlower got me quickly to the place I needed to be.

I installed the SoundFlower package from Google Code.

Opened System Preferences -> Sound

Chose Soundflower as my Output device

Chose Soundflower as my Input device

I was then able to record system audio from the default device using PyAudio. No sound comes from the speakers/headphones in this situation though. I wonder if you could use Jack OS X to route audio out of SoundFlower to the system audio out.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
os 模块是 Python 中用于访问操作系统功能的一个模块,它提供了一种便携式的方法来使用操作系统相关的功能,例如读写文件、创建进程等。下面是 os 模块的一些常用功能及用法: 1. 获取当前工作目录:os.getcwd() ```python import os print(os.getcwd()) # 打印当前工作目录 ``` 2. 改变当前工作目录:os.chdir(path) ```python import os os.chdir('/Users/username/Desktop') # 将当前工作目录改变为桌面 ``` 3. 列出目录下的所有文件和子目录:os.listdir(path) ```python import os print(os.listdir('/Users/username/Desktop')) # 列出桌面下的所有文件和子目录 ``` 4. 创建目录:os.mkdir(path) ```python import os os.mkdir('/Users/username/Desktop/new_dir') # 在桌面上创建一个名为 new_dir 的文件夹 ``` 5. 删除目录:os.rmdir(path) ```python import os os.rmdir('/Users/username/Desktop/new_dir') # 删除桌面上的名为 new_dir 的文件夹 ``` 6. 判断路径是否为文件:os.path.isfile(path) ```python import os print(os.path.isfile('/Users/username/Desktop/test.txt')) # 判断桌面上的 test.txt 是否为文件 ``` 7. 判断路径是否为目录:os.path.isdir(path) ```python import os print(os.path.isdir('/Users/username/Desktop/new_dir')) # 判断桌面上的 new_dir 是否为目录 ``` 8. 判断路径是否存在:os.path.exists(path) ```python import os print(os.path.exists('/Users/username/Desktop/test.txt')) # 判断桌面上的 test.txt 是否存在 ``` 9. 删除文件:os.remove(path) ```python import os os.remove('/Users/username/Desktop/test.txt') # 删除桌面上的 test.txt 文件 ``` 总之,os 模块提供了很多强大的功能,可以让我们更加方便地操作文件和目录,同时也可以更好地与操作系统进行交互。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值