GithubHelp home page GithubHelp logo

cristifati / pyaudio Goto Github PK

View Code? Open in Web Editor NEW
20.0 2.0 3.0 445 KB

A fork of https://people.csail.mit.edu/hubert/git/pyaudio.git. Last synchronized on 20231119.

Home Page: https://people.csail.mit.edu/hubert/pyaudio

License: MIT License

Makefile 0.82% Python 59.37% C 39.81%
audio portaudio python

pyaudio's Introduction

PyAudio

PyAudio provides Python bindings for PortAudio v19, the cross-platform audio I/O library. With PyAudio, you can easily use Python to play and record audio on a variety of platforms, such as GNU/Linux, Microsoft Windows, and Apple macOS.

PyAudio is distributed under the MIT License.

Installation

See the INSTALLATION file in the source distribution for details. In summary, install PyAudio using pip on most platforms.

Windows

python -m pip install pyaudio

This installs the precompiled PyAudio library with PortAudio v19 19.7.0 included. The library is compiled with support for Windows MME API, DirectSound, WASAPI, and WDM-KS. It does not include support for ASIO. If you require support for APIs not included, you will need to compile PortAudio and PyAudio.

macOS

Use Homebrew to install the prerequisite portaudio library, then install PyAudio using pip:

brew install portaudio
pip install pyaudio

GNU/Linux

Use the package manager to install PyAudio. For example, on Debian-based systems:

sudo apt install python3-pyaudio

Alternatively, if the latest version of PyAudio is not available, install it using pip. Be sure to first install development libraries for portaudio19 and python3.

Building from source

See the INSTALLATION file.

Documentation & Usage Examples

License

PyAudio is distributed under the MIT License. See LICENSE.txt.

pyaudio's People

Contributors

cgohlke avatar hubertpham avatar jmp-mit avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

pyaudio's Issues

record playback examples don't work on macos

I installed PyAudio 0.2.1.14, portaudio 19.7.0 on my macbook pro (Intel) running Ventura 13.3.1 and tried running the record and playback examples but I don't hear any anything when playing the wav file. Have others had this work successfully?

Unanticipated host error

When I attempt to use the library I get an error. The error message is:
lProject\test.py", line 11, in
stream = p.open(
^^^^^^^
File "C:\Users\lenny\AppData\Local\Programs\Python\Python311\Lib\site-packages\pyaudio_init_.py", line 639, in open
stream = PyAudio.Stream(self, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\lenny\AppData\Local\Programs\Python\Python311\Lib\site-packages\pyaudio_init_.py", line 441, in init
self._stream = pa.open(**arguments)
^^^^^^^^^^^^^^^^^^^^
OSError: [Errno -9999] Unanticipated host error

The code I am trying to run is:
import pyaudio
import wave

FRAMES_PER_BUFFER = 512
FORMAT = pyaudio.paInt16
CHANNELS = 1
RATE = 16000

p = pyaudio.PyAudio()

stream = p.open(
format=FORMAT,
channels=CHANNELS,
rate=RATE,
input=True,
frames_per_buffer=FRAMES_PER_BUFFER

)

print("Start recording")

seconds = 5
frames = []

for i in range(0, int(RATE/FRAMES_PER_BUFFER*seconds)):
try:
data = stream.read(FRAMES_PER_BUFFER)
frames.append(data, FRAMES_PER_BUFFER)
except:
print("Life is lemons i like melons and pasta")

stream.stop_stream()
stream.close()

p.terminate()

obj = wave.open("output.wav", "wb")
obj.setnchannels(CHANNELS)
obj.setsampwidth(p.get_sample_size)
obj.setframerate(RATE)
obj.writeframes(b"".join(frames))
obj.close()

I am using windows 11 with python 3.11.5 and pyaudio 0.2.13

Can someone please help?

Regression from 0.2.13 to 0.2.14

In 0.2.14 I get the following error on MacOS:

||PaMacCore (AUHAL)|| AUHAL component not found.Traceback (most recent call last):
  File "/Users/adev/src/audio_engineering/tools/player.py", line 58, in <module>
    play(args.path, args.output_device, args.volume)
  File "/Users/adev/src/audio_engineering/tools/player.py", line 32, in play
    stream = p.open(
  File "/Users/adev/miniconda3/lib/python3.10/site-packages/pyaudio/__init__.py", line 639, in open
    stream = PyAudio.Stream(self, *args, **kwargs)
  File "/Users/adev/miniconda3/lib/python3.10/site-packages/pyaudio/__init__.py", line 441, in __init__
    self._stream = pa.open(**arguments)
OSError: [Errno -9999] Unanticipated host error

All is well on 0.2.13, something has broken in 0.2.14. My version of portaudio hasn't changed (portaudio: stable 19.7.0)

Audio scaling problem

I use a Raspberry Pi and a HiFiBerry DAC + ADC pro to do some test on audio. There is no Auto Gain Control on the HiFiberry so this shouldn't be the problem. I need to simultaneously play a sine wave and record it at the input via a loopback. I am able to record the signal but the signal is significantly higher than what I send in. When i send a sine wave with max value of 1 I get a max of 1.395 and when plotted it seems the entire signal is higher than what I send out. I do need an exact copy of what I get at the input because I need to do gain calculation and manually scaling isn't something I can do. I will attach the code if someone wants to look at it. Has anyone else ran into this?
test.txt

Py 12 support?

Works great on 11 but are you doing anything to port to 12 or is there a workaround?

(.venv) PS C:\Users\DanielRoy\Documents\GitHub\ProjectProdigi\3.12> pip install pyaudio
Collecting pyaudio
Using cached PyAudio-0.2.13.tar.gz (46 kB)
Installing build dependencies ... done
Getting requirements to build wheel ... error
error: subprocess-exited-with-error

× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> [33 lines of output]
Traceback (most recent call last):
File "c:\Users\DanielRoy\Documents\GitHub\ProjectProdigi\3.12.venv\Lib\site-packages\pip_vendor\pyproject_hooks_in_process_in_process.py", line 353, in
main()
File "c:\Users\DanielRoy\Documents\GitHub\ProjectProdigi\3.12.venv\Lib\site-packages\pip_vendor\pyproject_hooks_in_process_in_process.py", line 335, in main
json_out['return_val'] = hook(**hook_input['kwargs'])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\Users\DanielRoy\Documents\GitHub\ProjectProdigi\3.12.venv\Lib\site-packages\pip_vendor\pyproject_hooks_in_process_in_process.py", line 112, in get_requires_for_build_wheel
backend = _build_backend()
^^^^^^^^^^^^^^^^
File "c:\Users\DanielRoy\Documents\GitHub\ProjectProdigi\3.12.venv\Lib\site-packages\pip_vendor\pyproject_hooks_in_process_in_process.py", line 77, in build_backend
obj = import_module(mod_path)
^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\Python312\Lib\importlib_init
.py", line 90, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "", line 1381, in _gcd_import
File "", line 1354, in _find_and_load
File "", line 1304, in _find_and_load_unlocked
File "", line 488, in _call_with_frames_removed
File "", line 1381, in _gcd_import
File "", line 1354, in _find_and_load
File "", line 1325, in _find_and_load_unlocked
File "", line 929, in load_unlocked
File "", line 994, in exec_module
File "", line 488, in call_with_frames_removed
File "C:\Users\DanielRoy\AppData\Local\Temp\pip-build-env-k9y76732\overlay\Lib\site-packages\setuptools_init
.py", line 16, in
import setuptools.version
File "C:\Users\DanielRoy\AppData\Local\Temp\pip-build-env-k9y76732\overlay\Lib\site-packages\setuptools\version.py", line 1, in
import pkg_resources
File "C:\Users\DanielRoy\AppData\Local\Temp\pip-build-env-k9y76732\overlay\Lib\site-packages\pkg_resources_init
.py", line 2191, in
register_finder(pkgutil.ImpImporter, find_on_path)
^^^^^^^^^^^^^^^^^^^
AttributeError: module 'pkgutil' has no attribute 'ImpImporter'. Did you mean: 'zipimporter'?
[end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.

Dynamic Detection of Reconnected Microphone in PyAudio

Hello,

I'm encountering a challenge with PyAudio where it fails to detect a microphone that's reconnected after being disconnected. The issue persists even after reinitializing the PyAudio instance. Specifically, when the microphone is unplugged and then plugged back in during the program's runtime, PyAudio does not update its device list to include the reconnected microphone. This results in errors such as "Invalid number of channels" when trying to access the microphone.

Here's a brief overview of the problem:

Environment: Win11 python3.9
PyAudio Version: 0.2.13
Issue: PyAudio does not dynamically update the list of audio devices upon reconnection of the microphone.
Current Behavior: The microphone, once disconnected and reconnected, is not recognized by PyAudio without restarting the entire program.
Expected Behavior: PyAudio should update its device list and allow access to the microphone after it's reconnected.
I've tried the following:

Reinitializing the PyAudio instance after detecting the disconnection.
Creating a new PyAudio instance to refresh the device list.
Using a loop to periodically check for device availability.
Despite these efforts, the reconnected microphone is only recognized after restarting the program. I would greatly appreciate any insights or suggestions on how to resolve this issue.

Thank you in advance for your assistance!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.