Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the automatically-detected audio sample rate #8

Open
pjckoch opened this issue Aug 5, 2018 · 0 comments
Open

Improve the automatically-detected audio sample rate #8

pjckoch opened this issue Aug 5, 2018 · 0 comments
Assignees

Comments

@pjckoch
Copy link

pjckoch commented Aug 5, 2018

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.

@swharden swharden self-assigned this Sep 29, 2018
@swharden swharden changed the title SWHear(): testrate from valid_low_rate() not used in valid_test() Improve the automatically-detected audio sample rate Sep 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants