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

SWHear: input_device_index not used in stream_start #5

Open
TimeTravel-0 opened this issue Mar 16, 2017 · 1 comment
Open

SWHear: input_device_index not used in stream_start #5

TimeTravel-0 opened this issue Mar 16, 2017 · 1 comment
Assignees

Comments

@TimeTravel-0
Copy link

In SWHear.py, there is possibility to set the device by id in constructor/init. This id is verified (valid_input_devices function). Actually half of this class deals with selecting the right audio source. Finally, in stream_start, the following parameter to self.p.open() is missing:

input_device_index=self.device

...leading to opening the default (?) audio device, not the one specified.

So I suggest the following change in swhear.py:

replace self.stream=self.p.open(format=pyaudio.paInt16,channels=1, rate=self.rate,input=True,frames_per_buffer=self.chunk)
with self.stream=self.p.open(format=pyaudio.paInt16,channels=1, rate=self.rate,input=True,frames_per_buffer=self.chunk, input_device_index=self.device)
in line 146ff.

Btw. thanks for providing the audio/fft/graph sample. It is a nice starting point for visualizing the data captured by my "analog accelerometer connected to usb sound card" setup

@swharden swharden self-assigned this Sep 29, 2018
@swharden
Copy link
Owner

@TimeTravel-0 Thanks for bringing this to my attention! (albeit delayed attention)

To restate the problem, the sound card test function opens the stream using input_device_index:

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)

... but when the card is actually opened for the main program, input_device_index is not defined:

self.stream=self.p.open(format=pyaudio.paInt16,channels=1,
rate=self.rate,input=True,frames_per_buffer=self.chunk)

I'm about to rewrite this file, so when I do I will fix this issue by using a method to open the stream which returns the stream itself. This way there will only be one open() line in the program. I'll close this ticket when it's resolved.

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