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

Fix problem with pyaudio overflows on OSX #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

e-yes
Copy link

@e-yes e-yes commented Dec 23, 2023

For some reason pyaudio on Mac OS X throws an exception

OSError                                   Traceback (most recent call last)
Cell In[2], [line 43](vscode-notebook-cell:?execution_count=2&line=43)
     [38](vscode-notebook-cell:?execution_count=2&line=38) start_time = time.time()
     [40](vscode-notebook-cell:?execution_count=2&line=40) while True:
     [41](vscode-notebook-cell:?execution_count=2&line=41)     
     [42](vscode-notebook-cell:?execution_count=2&line=42)     # binary data
---> [43](vscode-notebook-cell:?execution_count=2&line=43)     data = stream.read(CHUNK )
     [45](vscode-notebook-cell:?execution_count=2&line=45)     # convert data to integers, make np array, then offset it by 127
     [46](vscode-notebook-cell:?execution_count=2&line=46)     data_int = struct.unpack(str(2 * CHUNK) + 'B', data)

File [/opt/homebrew/lib/python3.12/site-packages/pyaudio/__init__.py:570](https://file+.vscode-resource.vscode-cdn.net/opt/homebrew/lib/python3.12/site-packages/pyaudio/__init__.py:570), in PyAudio.Stream.read(self, num_frames, exception_on_overflow)
    [567](https://file+.vscode-resource.vscode-cdn.net/opt/homebrew/lib/python3.12/site-packages/pyaudio/__init__.py:567) if not self._is_input:
    [568](https://file+.vscode-resource.vscode-cdn.net/opt/homebrew/lib/python3.12/site-packages/pyaudio/__init__.py:568)     raise IOError("Not input stream",
    [569](https://file+.vscode-resource.vscode-cdn.net/opt/homebrew/lib/python3.12/site-packages/pyaudio/__init__.py:569)                   paCanNotReadFromAnOutputOnlyStream)
--> [570](https://file+.vscode-resource.vscode-cdn.net/opt/homebrew/lib/python3.12/site-packages/pyaudio/__init__.py:570) return pa.read_stream(self._stream, num_frames,
    [571](https://file+.vscode-resource.vscode-cdn.net/opt/homebrew/lib/python3.12/site-packages/pyaudio/__init__.py:571)                       exception_on_overflow)

OSError: [Errno -9981] Input overflowed

Disable pyaudio exceptions completely. I haven't checked corner cases like real overflows on Linux, but seems this change is harmless.

@e-yes
Copy link
Author

e-yes commented Dec 23, 2023

Fixes #5

@smith-kyle
Copy link

I'm a little late to the party, but I noticed you all aren't using a notebook review tool and wanted to invite you to review this pull request with GitNotebooks: https://gitnotebooks.com/markjay4k/Audio-Spectrum-Analyzer-in-Python/pull/22

It lets you do things like comment on rendered markdown and code cells, so might be an easy win for your PR reviews.

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

Successfully merging this pull request may close these issues.

2 participants