Python-GUI-examples icon indicating copy to clipboard operation
Python-GUI-examples copied to clipboard

Improve the automatically-detected audio sample rate

Open pjckoch opened this issue 7 years ago • 0 comments

Hi, first of all thanks for publishing. It's a great starting point and saved me some time in my own project.

One thing I noticed: in valid_low_rate() we are looping through [44100] to find a testrate

for testrate in [44100]:
    if self.valid_test(device,testrate):
         return testrate

Then, in valid_test(), we want to open a stream to see if the given testrate works with the given device. However, we are not opening the stream with the given testrate, but with the defaultSampleRate of the device.

stream=self.p.open(format=pyaudio.paInt16,channels=1,
                                input_device_index=device,frames_per_buffer=self.chunk,
                                rate=int(self.info["defaultSampleRate"]),input=True)

I suggest not to look for the lowest possible rate, but only test the user-specified rate. If it is not working or the user didn't specify it, I recommend testing the defaultSampleRate of the device (which should probably work) and then setting self.rate to this value.

pjckoch avatar Aug 05 '18 10:08 pjckoch