Skip to content

Improve the automatically-detected audio sample rate #8

Open
@pjckoch

Description

@pjckoch

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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions