shichao-an / soundmeter

Simple real-time sound meter
https://soundmeter.shichao.io
BSD 2-Clause "Simplified" License
82 stars 27 forks source link

Soundmeter returning 0 #17

Open davepcollins83 opened 6 years ago

davepcollins83 commented 6 years ago

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.

shichao-an commented 6 years ago

Hi, maybe you should set pyaudio.paJACK instead of pyaudio.paALSA?

See also https://people.csail.mit.edu/hubert/pyaudio/docs/#details for reference.

davepcollins83 commented 6 years ago

Can you clarify what the value of pyaudio.pyJACK should be? What does this refer to?

shichao-an commented 6 years ago

Hi, sorry it seems #15 didn't actually pose the correct solution.

Those values pyaudio.paALSA, pyaudio.paJACK are just enumerations of host api types. See http://portaudio.com/docs/v19-doxydocs/portaudio_8h_source.html

To select different input device, I found https://stackoverflow.com/questions/36894315/how-to-select-a-specific-input-device-with-pyaudio

The input_device_index parameter of the Stream class sets the device number.

I'll see if I can change the code to add a feature to support input device.

shichao-an commented 6 years ago

@davepcollins83 per your original question, you said you can record from your USB device fine, which means the input device is correctly found, but output is 0. I think one cause can be the input volume is too small or muted. Can you try to increase your input volume of your USB mic and make sure it's not muted. Maybe you can search online how to do this using some command-line utilities.

davepcollins83 commented 6 years ago

The volume is definitely up. How would I set the stream_device_index value?

shichao-an commented 6 years ago

@davepcollins83 Hi, I added a config input_device_index in 63c382542c497f7c5236a956af8ea5f569e51217 which is used to specify index number.

Can you list your devices and find the index for the correct input device:

>>> import pyaudio
>>> p = pyaudio.PyAudio()
>>> for i in range(p.get_device_count()): print p.get_device_info_by_index(i)
...
{'defaultSampleRate': 44100.0, 'defaultLowOutputLatency': 0.01, 'defaultLowInputLatency': 0.0029705215419501135, 'maxInputChannels': 2L, 'structVersion': 2L, 'hostApi': 0L, 'index': 0, 'defaultHighOutputLatency': 0.1, 'maxOutputChannels': 0L, 'name': u'Built-in Microphone', 'defaultHighInputLatency': 0.013129251700680272}
...

Then, edit the config file ~/.soundmeter/config. For example, if the index is 1, edit the config to:

[soundmeter]
frames_per_buffer = 1024
audio_segment_length = 0.5
input_device_index = 1

And re-run soundmeter.

I just change code to the master branch. You can pip install it from master:

pip install git+https://github.com/shichao-an/soundmeter.git
davepcollins83 commented 6 years ago

Awesome, thanks for doing this so quickly. I'll try it when I get home this evening.