我可以通过终端访问内部麦克风输入级别吗?


10

我有兴趣将旧的MacBook用作婴儿音频监视器。我想象的工作流程是在婴儿搅拌或抱怨时为MacBook中的内置麦克风设置噪声阈值,并在达到阈值时使用消息向我或我的妻子发短信。

当我在“系统偏好设置”中查看时,可以看到Input level麦克风正在拾取噪音,但是如何在Terminal中获得可量化的数字?

我在网上看到osascript -e "get volume settings"要访问一个数值,以设置麦克风的灵敏度,但是我找不到在任何给定时间访问输入声音的方法。

有什么想法吗?


Shell脚本真的是您想怎么做吗?
蒂莫西·穆勒-哈德

我愿意接受其他建议...
CephBirk'1

Answers:


14

使用命令行工具,您可以执行以下操作:

  • 安装brew
  • 更新和医生冲泡
  • 使用brew安装portaudio,ffmpeg和所有依赖项

    brew install portaudio
    brew install ffmpeg
  • 通过下载get-pip.py(直接链接)并执行来安装pip

    sudo python ~/Downloads/get-pip.py
  • 安装声级计

    sudo pip install soundmeter
  • 运行声级计。要获得帮助,请使用-h开关:

    soundmeter -h
    optional arguments:
      -h, --help            show this help message and exit
      -c, --collect         collect RMS values to determine thresholds
      -s SECONDS, --seconds SECONDS
                            time in seconds to run the meter (default forever)
      -a {stop,exec-stop,exec}, --action {stop,exec-stop,exec}
                            triggered action
      -t [+|-]THRESHOLD [NUM ...], --trigger [+|-]THRESHOLD [NUM ...]
                            trigger condition (threshold RMS and number of times)
      -e SCRIPT, --exec SCRIPT
                            shell script to execute upon trigger
      -d, --daemonize       run the meter in the background
      --log [LOGFILE]       log the meter (default to ~/.soundmeter/log)
      -v, --verbose         verbose mode
      --segment SECONDS     audio segment length recorded in seconds (defaults to
                            0.5)

只需运行soundmeter将输出RMS值。定义阈值后,您可以使用-e开关触发外壳程序脚本操作(它本身可能会触发AppleScript脚本)。

输入soundmeter --segment 0.1 --log观看在线电视节目(哥伦比亚的气候变化和咖啡种植-阿拉比卡咖啡豆的末期)将显示以下内容:

2017-01-25 18:16:02,289 24
2017-01-25 18:16:02,665 24
2017-01-25 18:16:03,037 31
2017-01-25 18:16:03,399 3
2017-01-25 18:16:03,769 15
2017-01-25 18:16:04,142 11
2017-01-25 18:16:04,524 9
2017-01-25 18:16:04,891 7
2017-01-25 18:16:05,257 7
2017-01-25 18:16:05,632 0
2017-01-25 18:16:06,001 7
2017-01-25 18:16:06,384 0
2017-01-25 18:16:06,745 2
2017-01-25 18:16:07,113 10
2017-01-25 18:16:07,491 14
2017-01-25 18:16:07,860 6
2017-01-25 18:16:08,223 0
2017-01-25 18:16:08,609 13
2017-01-25 18:16:08,973 16
2017-01-25 18:16:09,347 7
2017-01-25 18:16:09,720 26
2017-01-25 18:16:10,091 1
2017-01-25 18:16:10,464 38  an Arabica bean died here
2017-01-25 18:16:10,835 13
2017-01-25 18:16:11,204 Stopped

只是要确认:这是麦克风输入电平,而不是电视流的声音电平,因为上述安装在VM guest虚拟机中运行,并且在托管Mac上的电视流已经过测试-但未进行任何记录,这会提高RMS值200以上!


要在触发事件之后发送消息,请执行以下操作-更改<user_name>为OS X的短用户名,并更改为以下<telephone_number>相应的电话号码:

  • 创建一个目录并更改为:

    mkdir ~/.soundmeter
    cd ~/.soundmeter
  • 创建一个AppleScript:

    nano sendMessage.applescript

    内容:

    on run {targetBuddyPhone, targetMessage}
        tell application "Messages"
            set targetService to 1st service whose service type = iMessage
            set targetBuddy to buddy targetBuddyPhone of targetService
            send targetMessage to targetBuddy
        end tell
    end run
  • 创建一个shell脚本:

    nano sendMessage.sh

    内容:

    #!/bin/bash
    
    osascript /Users/<user_name>/.soundmeter/sendMessage.applescript <telephone_number> "Another Arabica bean died"

    并更改权限:

    chmod 755 sendMessage.sh
  • 现在,使用以下命令启动声级计:

    soundmeter -t +38 -a exec -e /Users/<user_name>/.soundmeter/sendMessage.sh

    这应该向您的(iPhone)电话号码发送一条消息。请注意,您无法向自己发送iMessage。将其发送给别名可能有效。其他类似的(Apple)脚本在这里可用:仅在提供的服务中,如何发送带有applescript的消息文本?


1
喜欢答案!做得好!:)
Monomeeth
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.