Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for microphone direct input #30

Open
zhulik opened this issue Mar 9, 2020 · 3 comments
Open

Support for microphone direct input #30

zhulik opened this issue Mar 9, 2020 · 3 comments

Comments

@zhulik
Copy link

zhulik commented Mar 9, 2020

This is how I can easily use ffmpeg to detect noise using a microphone directly:
ffmpeg -f alsa -i hw:0,0 -af silencedetect=n=-40dB:d=1 -f null -

It seems like it is impossible to build such command using ffmpeg_noise HA integration, because haffpeg always puts input to the first place.

This is what I tried:

- platform: ffmpeg_noise
  input: "hw:0,0"
  extra_arguments: -f alsa
  initial_state: true
  duration: 1
  reset: 20
  peak: -40

And it didn't work because the command haffmpeg built was
'ffmpeg', '-i', 'hw:0,0', '-vn', '-f', 'alsa', '-filter:a', 'silencedetect=n=-40dB:d=1', '-f', 'null', '-']

As you can see, -f alsa follows after -i hw:0,0, so ffmpeg can't recognize the input.

I know that it's possible to stream data from microphone using rtp and then process it as described here, but I also know that it adds a lot of complications to the systemd configuration and it is not very efficient because the streaming constantly uses 10-15% of my CPU.

How difficult it would be to add support for direct microphone input?

@black-roland
Copy link

black-roland commented Jun 17, 2020

@zhulik I'm not sure if this is still relevant 🙂 but you can try passing alsa related arguments to the input option. For example, I'm using this config with my mic:

- platform: ffmpeg_noise
  input: -f alsa -ac 1 -i hw:1,0
  extra_arguments: '-hide_banner -nostats -filter:a highpass=f=6000'
  peak: -22
  reset: 20

@zhulik
Copy link
Author

zhulik commented Jun 18, 2020

@black-roland Thanks, I'll try it

@stskrp
Copy link

stskrp commented Oct 22, 2020

Works for me with such configuration:

 - platform: ffmpeg_noise
    input: -f alsa -channels 1 -i hw:1  
    extra_arguments: -filter:a highpass=f=99,lowpass=f=250  
    initial_state: true  
    duration: 2  
    reset: 3  
    peak: -45

But there is an issue, it stops working after some time (~1h), nothing in logs, binary_sensor is all time in "Clear" state, and microphone itself is in busy state (means process is running, but not piped to Home Assistant?)
This is output when I try to run ffmpeg command in HASS container cmd:
[alsa @ 0x7f8ddd7940] cannot open audio device hw:1 (Resource busy) hw:1: I/O error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants