Skip to content

Instantly share code, notes, and snippets.

@ylxdzsw
Created March 8, 2019 07:09
Show Gist options
  • Save ylxdzsw/870480ddfac85e920231905a8691b6ea to your computer and use it in GitHub Desktop.
Save ylxdzsw/870480ddfac85e920231905a8691b6ea to your computer and use it in GitHub Desktop.
show noise level
using Statistics
const p = run(pipeline(`arecord -f cd -t raw`, stdout=Pipe()), wait=false)
close(p.out.in)
while true
sleep(0.1)
x = reinterpret(Int16, readavailable(p.out))
x = @. 20log(10, abs(max(x, typemin(Int16) + one(Int16))) / typemax(Int16))
println(mean(x))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment