Hello, Alex!
The record.py script at https://github.com/OpenAcousticDevices/Application-Notes/blob/master/Using_the_AudioMoth_USB_Microphone_Firmware_and_Hardware/record.py is not running. I have tried to fix it with no results. This is the error I get:
Expression 'paInvalidSampleRate' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 2048
Expression 'PaAlsaStreamComponent_InitialConfigure( &self->capture, inParams, self->primeBuffers, hwParamsCapture, &realSr )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 2718
Expression 'PaAlsaStream_Configure( stream, inputParameters, outputParameters, sampleRate, framesPerBuffer, &inputLatency, &outputLatency, &hostBufferSizeMode )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 2842
Traceback (most recent call last):
File "/home/pi/record.py", line 29, in <module>
stream = audio.open(format=audio_format, rate=sample_rate, channels=number_of_channels, input_device_index=device_index, input=True, frames_per_buffer=chunk_size)
File "/home/pi/.local/lib/python3.9/site-packages/pyaudio/__init__.py", line 639, in open
stream = PyAudio.Stream(self, *args, **kwargs)
File "/home/pi/.local/lib/python3.9/site-packages/pyaudio/__init__.py", line 441, in __init__
self._stream = pa.open(**arguments)
OSError: [Errno -9997] Invalid sample rate
Could you have a look? Any advice is appreciated!
Thanks!
Antonio.
Hi Antonio,
It seems like the error you're encountering is related to the PyAudio library not being able to configure the audio stream correctly. Specifically, the error message [Errno -9997] Invalid sample rate indicates that the sample rate you've specified in your script might not be supported by your device or there's a mismatch between the sample rate and the device's capabilities.
Here are a few steps you can try to resolve the issue:
1. Check the Sample Rate
Ensure that the sample_rate value in your script matches one of the supported sample rates of your audio input device. Common sample rates are 44100 Hz, 48000 Hz, etc.
You can try changing the sample_rate value in the script to a standard one like 44100 or 48000 and see if the error persists.
2. Check Available Sample Rates for Your Device
You can use the PyAudio library to list the supported sample rates for your device. Here's a quick snippet that can help you:
import pyaudio p = pyaudio.PyAudio() device_index = 0 # Replace with your actual device index info = p.get_device_info_by_index(device_index) print(f"Device name: {info['name']}") for rate in [8000, 11025, 16000, 22050, 32000, 44100, 48000, 88200, 96000, 192000]: try: p.is_format_supported(rate, input_device=info['index'], input_channels=info['maxInputChannels'], input_format=pyaudio.paInt16) print(f"Supported sample rate: {rate}") except ValueError: print(f"Unsupported sample rate: {rate}") p.terminate()
This script will print out the sample rates supported by your device. You can then adjust the sample_rate in your script to one of the supported values. geometry dash subzero
3. Check the Audio Device Configuration
If you are using a USB microphone or other external audio device, make sure it is configured correctly in your system. Sometimes, USB microphones have specific sample rates that they support, and trying to use an unsupported rate will cause this error.
You can also check the configuration using alsamixer or similar tools in Linux to ensure the device is set up correctly.