shichao-an / soundmeter Goto Github PK
View Code? Open in Web Editor NEWSimple real-time sound meter
Home Page: https://soundmeter.shichao.io
License: BSD 2-Clause "Simplified" License
Simple real-time sound meter
Home Page: https://soundmeter.shichao.io
License: BSD 2-Clause "Simplified" License
Hi,
I'm trying to use Soundmeter with a USB mic on Raspberry pi. If I run arecord -l
I get the following output:
**** List of CAPTURE Hardware Devices ****
card 1: Device [USB PnP Sound Device], device 0: USB Audio [USB Audio]
Subdevices: 1/1
Subdevice #0: subdevice #0
I can record from the USB mic fine, but when I run Soundmeter I just get "0" as the output. I've tried creating a script to select the input as per issue #15 modified to the following:
from soundmeter.meter import Meter
from soundmeter.cli import get_meter_kwargs, setup_user_dir
import pyaudio
def main():
pyaudio.paALSA = 0
setup_user_dir()
kwargs = get_meter_kwargs()
meter = Meter(**kwargs)
meter.start()
if __name__ == '__main__':
main()
But I'm now stuck! Grateful for any suggestions.
hi,
I'd like to use something like ${XDG_CONFIG_HOME}/soundmeter/rc.conf
as the configuration folder/file. Could you please check that path fist?
thanks for this tool! I use it to control mpd in a woodworking shop to have some music now and then, only when there's little noise.
Probably more of a feature request than an issue, couldn't work out where else to ask sorry..
hello
thank you for this open-software it's really nice
I Work on Raspberry Pi and his Apache server but i have an issue when i launch soundmeter using a php script, the program runs but i don't have the display of the RMS value, i tried a lot of things; like changing permission, groups ... and nothing works. Do you what could be the issue ?
Hi,
I'd like to integrate the readout from soundmeter into a nodeJS app I'm building.
I'm actually not very familiar with Python so I wasn't able to figure exactly how to query which file in soundmeter using python-shell for example to retrieve the RMS value.
Right now I'm running soundmeter straight from the terminal. But ultimately I'd be calling it from my nodeJS app and use the value there.
Any advice ?
Thanks
Hi, when I import soundmeter into my flask app, I believe it's breaking the default Ctrl+C behaviour because the sigint_handler doesn't raise KeyboardInterrupt. I believe if you simply adding raise KeyboardInterrupt
to the end of sigint_handler, this would work correctly again. However, not sure if this was intentional or if it'll mess up daemonized mode.
Am I correct? Is this something worth fixing? If so, I can make the PR if it helps
When I tried to run a script I made, I got this message:
cannot execute binary file: Exec format error
I can run the script without any problem directly from the console, but the trigger function always get that error.
I am using raspbian if that helps.
I currently have the daemon running (soundmeter -d --segment 5 --log sound.csv) on a Raspberry Pi 3b. The program logs every 5 (or 4.9?) seconds to the log file. Great! However, I haven't gotten it to be able to run for more then a few hours at a time. I'd like it to run indefinitely.
My thoughts: I download the log file to my web server (I use my server to pull the file from my Pi using lftp sftp://user:pass@home-ip:1234 -e "get sound.csv; bye") periodically. It seems that it is at that time that the soundmeter daemon quits. There is no log showing any errors that I can find. (/var/log - messages, syslog, error, etc.)
I'm guessing that when I pull the file, soundmeter cannot access the log to write the new data and it quits.
My thoughts were to quick copy the file on the Pi (cp sound.csv sound1.csv), and then download that new file via sftp, but I think even that stopped soundmeter from logging!
Question: Am I correct in thinking that this is why the program quits? (Because I am accessing the log file when it might be trying to write to it?) Can you think of any solutions that might work? Is there a way that the program can debug this for me and show me a log as to why it quits?
(My next plan .. set up a cron job to run the logger for 6 hours with the --seconds 21600 switch, download the log file at that time, delete the log file and start the daemon again .. but that seems to be a little overkill)
Great program -- I'm having fun experimenting with it!
Hi there,
I am using your script for the first time and I have connected a USB webcam, when using alsa I can record from the mic without any issues but when I try using your script I get an error saying that there is an invalid number of channels. So I am trying to overwrite the config, I created the config file and added a section but I get the following error:
Traceback (most recent call last):
File "/usr/local/bin/soundmeter", line 11, in
load_entry_point('soundmeter==0.1.5', 'console_scripts', 'soundmeter')()
File "/usr/local/lib/python2.7/dist-packages/soundmeter-0.1.5-py2.7.egg/soundmeter/meter.py", line 321, in main
m = Meter(**kwargs)
File "/usr/local/lib/python2.7/dist-packages/soundmeter-0.1.5-py2.7.egg/soundmeter/meter.py", line 56, in init
self.config = Config(profile)
File "/usr/local/lib/python2.7/dist-packages/soundmeter-0.1.5-py2.7.egg/soundmeter/settings.py", line 59, in init
raise Exception('No section named "%s" in config' % section)
Exception: No section named "test" in config
I added the config file in ~/.soundmeter/ but it doesn't work. Any idea why?
Great software! My built in mic in my MacBook Pro works just fine, but when I plug in a USB mic, I get this error:
Traceback (most recent call last):
File "/usr/local/bin/soundmeter", line 8, in
load_entry_point('soundmeter==0.1.2', 'console_scripts', 'soundmeter')()
File "/Library/Python/2.7/site-packages/soundmeter-0.1.2-py2.7.egg/soundmeter/meter.py", line 304, in main
m = Meter(**kwargs)
File "/Library/Python/2.7/site-packages/soundmeter-0.1.2-py2.7.egg/soundmeter/meter.py", line 65, in init
frames_per_buffer=FRAMES_PER_BUFFER)
File "build/bdist.macosx-10.9-intel/egg/pyaudio.py", line 747, in open
File "build/bdist.macosx-10.9-intel/egg/pyaudio.py", line 442, in init
IOError: [Errno Invalid number of channels] -9998
Any idea??
I tried to use SoundMeter on Raspberry Pi 3 model B with external UBS microphone.
Installation was completed without any problems. But, when executioned, I faced following error.
Probably, this error occured due to my Raspberry Pi 3 board's sound input channel is '1' for external USB microphone and no sound channel on channel number '0' which supporsed to be default number.
So please anyone help me to use soundmeter by changing audio input channel number to the appropriate one ('1')?
thank you,
~# python -m speech_recognition
ALSA lib pcm_dsnoop.c:638:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dmix.c:1099:(snd_pcm_dmix_open) unable to open slave
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm_dsnoop.c:638:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dmix.c:1099:(snd_pcm_dmix_open) unable to open slave
ALSA lib pcm_dmix.c:1099:(snd_pcm_dmix_open) unable to open slave
Traceback (most recent call last):
File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
"main", fname, loader, pkg_name)
File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/usr/local/lib/python2.7/dist-packages/speech_recognition/main.py", line 4, in
m = sr.Microphone()
File "/usr/local/lib/python2.7/dist-packages/speech_recognition/init.py", line 86, in init
device_info = audio.get_device_info_by_index(device_index) if device_index is not None else audio.get_default_input_device_info()
File "/usr/local/lib/python2.7/dist-packages/pyaudio.py", line 949, in get_default_input_device_info
device_index = pa.get_default_input_device()
IOError: No Default Input Device Available
what to do ?anyone can fix this
Hi, I want to get the value of RMS in decibels, any idea of the formula to use ?
I tried using soundmeter today on a Raspberry Pi running Raspbian. It's a Debian like distribution and installation worked without any problems by following the normal Debian/Ubuntu installation instructions. The soundmeter functionality I expect seems to work fine. However, it always complains about jack server not running. Specifically, here's an example:
$ soundmeter --collect --seconds 10
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
Collecting RMS values...
19 Timeout
Collected result:
min: 18
max: 27
avg: 19
I can make that warning go away if I run jackd with the dummy driver:
terminal1$ jackd -d dummy
jackdmp 1.9.10
Copyright 2001-2005 Paul Davis and others.
Copyright 2004-2014 Grame.
jackdmp comes with ABSOLUTELY NO WARRANTY
This is free software, and you are welcome to redistribute it
under certain conditions; see the file COPYING for details
JACK server starting in realtime mode with priority 10
self-connect-mode is "Don't restrict self connect requests"
terminal2$ soundmeter --collect --seconds 10
Collecting RMS values...
17 Timeout
Collected result:
min: 16
max: 20
avg: 17
I'm filing this issue because I'm not sure what the implications are of running an instance of jackd with the dummy driver. Since it seems like soundmeter doesn't actually need a jack server to function, is it possible to add a fix somewhere in soundmeter itself?
Hello,
I'm working on a project that starts two scripts using cronjob at the same time. One should record the audio while the other take the RMS values. Is it possible parallelize RMS capture using soundmeter and recording audio at the same time with the same input audio device?
Hi,
I'm trying to run soundmeter indefinitely on my Mac Mini using the command soundmeter -t +XXX 2 -a exec-stop -e xyz.sh
When I started this last night and checked on it this morning, soundmeter seemed to have crashed and executed the script although the trigger was never reached. I got the following error in terminal:
1549 Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/bin/soundmeter", line 11, in
load_entry_point('soundmeter==0.1.5', 'console_scripts', 'soundmeter')()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/soundmeter/meter.py", line 322, in main
m.start()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/soundmeter/meter.py", line 124, in start
record.send(True) # Record stream `AUDIO_SEGMENT_LENGTH' long
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/soundmeter/meter.py", line 95, in record
data = self.stream.read(self.config.FRAMES_PER_BUFFER)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pyaudio.py", line 608, in read
return pa.read_stream(self._stream, num_frames, exception_on_overflow)
OSError: [Errno -9981] Input overflowed
Any idea what could be causing that and how to prevent it?
My intention is to run soundmeter to detect input from a record player and then automatically configure the sound output to play on my speakers (done in the shell script). The script works, but due to the failure, the speakers got misconfigured and the automation stops...
I tried this with python3 on osx 10.11 and ran into a few errors, here they are in received order:
SyntaxError: Missing parentheses in call to 'print'
ImportError: No module named 'StringIO'
ImportError: No module named 'ConfigParser'
TypeError: object() takes no parameters
NameError: name 'xrange' is not defined
all standard python2 -> python3 conversion issues, which I worked through with some quick fixes, and finally got to this attempt:
$ soundmeter --collect --seconds 10
2016-06-03 20:24:59.760 Python[6027:183774] 20:24:59.759 WARNING: 140: This application, or a library it uses, is using the deprecated Carbon Component Manager for hosting Audio Units. Support for this will be removed in a future release. Also, this makes the host incompatible with version 3 audio units. Please transition to the API's in AudioComponent.h.
Collecting RMS values...
Traceback (most recent call last):
File "/usr/local/bin/soundmeter", line 11, in <module>
sys.exit(main())
File "/usr/local/lib/python3.5/site-packages/soundmeter/meter.py", line 311, in main
m.start()
File "/usr/local/lib/python3.5/site-packages/soundmeter/meter.py", line 116, in start
self.record() # Record stream in `AUDIO_SEGMENT_LENGTH' long
File "/usr/local/lib/python3.5/site-packages/soundmeter/meter.py", line 90, in record
data = self.stream.read(FRAMES_PER_BUFFER)
File "/usr/local/lib/python3.5/site-packages/pyaudio.py", line 608, in read
return pa.read_stream(self._stream, num_frames, exception_on_overflow)
OSError: [Errno -9981] Input overflowed
Which didn't seem like a standard error, so I moved to another osx to try python2, and ran in to issue #7, but that is a separate issue...
I get the below error when running soundmeter on my raspberry pi.
It doesn't take long to get the error (a few seconds up to a few minutes).
pi@pi3three:~ $ soundmeter
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
123 Traceback (most recent call last):
File "/usr/local/bin/soundmeter", line 11, in
sys.exit(main())
File "/usr/local/lib/python3.4/dist-packages/soundmeter/meter.py", line 320, in main
m.start()
File "/usr/local/lib/python3.4/dist-packages/soundmeter/meter.py", line 122, in start
record.send(True) # Record stream 'AUDIO_SEGMENT_LENGTH' long
File "/usr/local/lib/python3.4/dist-packages/soundmeter/meter.py", line 94, in record
data = self.stream.read(FRAMES_PER_BUFFER)
File "/usr/lib/python3/dist-packages/pyaudio.py", line 605, in read
return pa.read_stream(self._stream, num_frames)
OSError: [Errno Input overflowed] -9981
Can you please tell me, how to run it on Pycharm?
I'm using soundmeter running on a raspberry pi to monitor my smoke detector and so need to set up the trigger to distinguish the loud intermittent noise of the smoke detector. It is working well and much more stable than my previous attempts attaching a sound sensor to the GPIO. However, I haven't got the triggering parameters optimised yet.
If I set up something to detect a few consecutive events with a suitable threshold and audio_segment_length it will work but it will also be triggered by a similar intensity (or louder) short noise above the threshold (eg a door slamming).
It I set it up to detect a longer run of consecutive events it will not be triggered by the door slam but will not be triggered by the smoke alarm (due to the intermittent beeping)
If I set up something to detect a few consecutive events with a lower threshold and a longer segment it will work but it will also be triggered by a continuous noise above the threshold (eg the spin cycle on my washer)
I can't get a compromise between the two to work that avoids the false triggers.
What would be ideal would be if the trigger logic could be set to determine x out of y events that were above the threshold. Would that be easy to implement within soundmeter?
with thanks
I am working on a project. I need to write algorithm to do real time sampling the sound (about 5s) which is picked up from microphone. the code will return the plot (time vs. amplitude), and also the numpy array of the sound. Can you guys help me with the code? thank you
Hi, thanks for creating this -- I have a problem I'm trying to solve and it seems this may be a perfect solution. One question though.
Have you done at work to see how precisely soundmeter can detect two audio peaks, e.g. to what what precision in time?
The problem I'm trying to solve is to measure audio latency as audio travels from one cell phone to another. I've done this so far by using audacity to record and measure the audio peaks and determine the time between them. I'm trying to determine with a precision down to about 50ms as I measure different audio routing options.
I did a quick test (which I realize isn't optimal) and I'm seeing there is about a 650ms between executions. Before I dig into how much I can reduce this, I wanted to see if you had any experience with this.
Here's what I tried so far:
I'm running soundmeter as follows:
soundmeter --trigger +3000 1 --action exec --exec ./measure
Measure is a script that does this:
cd /Users/brooksc/grid/latency
TIME=$(gdate +%s.%N)
LAST=$(cat last)
echo $TIME > last
echo $TIME - $LAST | bc
So it calculates the time from the last execution to now.
My next step is to capture the timecode in python and avoid the time to execute the external program.
FYI - the shortest delay I've heard between two cell phones is about 500ms. But as I'm trying to measure whether a particular call is 700ms or 850ms between audio peaks -- the accuracy of measuring time between peaks is critical.
Thanks again for creating this!
Hi everyone,
I have created a Python script to launch notifications with Pushover.
The script is called "pushover.py" and is located in the /home/pi folder.
It works well when I type :
$ sudo python pushover.py
But when I try to launch :
$ soundmeter --trigger +300 --action exec --exec pushover.py
I receive the following error message when the 300 threshold is reached :
"Can't run shell script [Errno 2] No such file or directory"
What am I missing here ?
Where should I put the 'pushover.py" file to solve this ?
Many thanks in advance for your help.
I created profiles to set a input_device_index
- The issue I'm having is that that number seems to change frequently, presumably every time I plug/unplug different inputs.
My entire need in the profile is consistency, so I can just run soundmeter --profile mic1
and know it's listening to that input. But since sometimes Mic1 is on index 3 and sometimes it's on index 5, it requires me to manually find the index and change the profile every time.
Am I missing something?
Hi there,
I'm trying to get your soundmeter working on a Raspberry Pi Zero W.
I'm getting the following error when I try do anything:
Expression 'parameters->channelCount <= maxChans' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 1514
Expression 'ValidateParameters( inputParameters, hostApi, StreamDirection_In )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 2818
Traceback (most recent call last):
File "/usr/local/bin/soundmeter", line 11, in
load_entry_point('soundmeter==0.1.5', 'console_scripts', 'soundmeter')()
File "/usr/local/lib/python2.7/dist-packages/soundmeter/meter.py", line 321, in main
m = Meter(**kwargs)
File "/usr/local/lib/python2.7/dist-packages/soundmeter/meter.py", line 66, in init
frames_per_buffer=self.config.FRAMES_PER_BUFFER)
File "/usr/local/lib/python2.7/dist-packages/pyaudio.py", line 750, in open
stream = Stream(self, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/pyaudio.py", line 441, in init
self._stream = pa.open(**arguments)
IOError: [Errno -9998] Invalid number of channels
I have no experience with Python, so not sure what I'm looking at here.
I want to adjust this code to to loop recording. saying, it will record for 5s, then sleep for 5s, and then it will start to record again. Can you guys help me to adjust the code? thank you
import pyaudio
import wave
FORMAT = pyaudio.paInt16
CHANNELS = 2
RATE = 44100
CHUNK = 1024
RECORD_SECONDS = 5
WAVE_OUTPUT_FILENAME = "file.wav"
audio = pyaudio.PyAudio()
stream = audio.open(format=FORMAT, channels=CHANNELS,
rate=RATE, input=True,
frames_per_buffer=CHUNK)
print "recording..."
frames = []
for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)):
data = stream.read(CHUNK)
frames.append(data)
print "finished recording"
stream.stop_stream()
stream.close()
audio.terminate()
waveFile = wave.open(WAVE_OUTPUT_FILENAME, 'wb')
waveFile.setnchannels(CHANNELS)
waveFile.setsampwidth(audio.get_sample_size(FORMAT))
waveFile.setframerate(RATE)
waveFile.writeframes(b''.join(frames))
waveFile.close()
If you encounter issues when installing Python dependencies, the following may help:
If you see the following error:
src/_portaudiomodule.c:29:10: fatal error: 'portaudio.h' file not found
#include "portaudio.h"
^
1 error generated.
error: command 'cc' failed with exit status 1
After installing portaudio with Homebrew:
brew install portaudio
Try the following command to install pyaudio:
pip install --global-option='build_ext' --global-option='-I/usr/local/include' --global-option='-L/usr/local/lib' pyaudio
See https://stackoverflow.com/a/33821084 for details.
If you see such error while installing-daemon:
i = p.rfind('/') + 1
AttributeError: 'NoneType' object has no attribute 'rfind'
Try this:
pip install docutils
Then install python-daemon:
pip install python-daemon
See https://stackoverflow.com/a/44539260 for details.
This depends on the fix of pydub to accept Python 3 bytes
data
Please would it be possible to allow other applications still use the same microphone when soundmeter is running
Currently it seems it's having exclusive access to audio input it's working on:
arecord -f S16_LE -d 20 -r 44100 -D hw:1,0 /dev/shm/test2.wav
arecord: main:828: audio open error: Device or resource busy
When I stop soundmeter , acrecord works just fine.
Raspbian 10 / alsa-base 1.0.27+1 / alsa-utils 1.1.8-2
lsusb | grep Audio
Bus 001 Device 004: ID 0d8c:0014 C-Media Electronics, Inc. Audio Adapter (Unitek Y-247A)
arecord -l
**** List of CAPTURE Hardware Devices ****
card 1: Device [USB Audio Device], device 0: USB Audio [USB Audio]
Subdevices: 0/1
Subdevice #0: subdevice #0
Hi,
Sorry this is more a question than an issue really, I can't seem to find how you specify which input the program is listening to ?
I wanted to specify an entrance like "pyaudio.paJACK = 12" but I couldn't even find where you call pyaudio from...
Best regards
I'm getting the following error with osx 10.11 python 2.7.10
$ soundmeter --collect --seconds 10 -v
Traceback (most recent call last):
File "/usr/local/bin/soundmeter", line 9, in <module>
load_entry_point('soundmeter==0.1.3', 'console_scripts', 'soundmeter')()
File "/Library/Python/2.7/site-packages/soundmeter/meter.py", line 310, in main
m = Meter(**kwargs)
File "/Library/Python/2.7/site-packages/soundmeter/meter.py", line 66, in __init__
frames_per_buffer=FRAMES_PER_BUFFER)
File "/Library/Python/2.7/site-packages/pyaudio.py", line 750, in open
stream = Stream(self, *args, **kwargs)
File "/Library/Python/2.7/site-packages/pyaudio.py", line 441, in __init__
self._stream = pa.open(**arguments)
IOError: [Errno -9996] Invalid input device (no default output device)
On OS X 10.10 El Capitan, the following warnings will show up when running soundmeter
:
2016-01-09 22:21:11.616 python2.7[2268:35440] 22:21:11.614 WARNING: 140: This application, or a library it uses, is using the deprecated Carbon Component Manager for hosting Audio Units. Support for this will be removed in a future release. Also, this makes the host incompatible with version 3 audio units. Please transition to the API's in AudioComponent.h.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.