#pyaudio

Jochie 👨🏻‍💻🏳️‍🌈jochie@strangeweb.page
2025-02-17

Today's minor software victory involves arm-wrestling with the portaudio wrapper for Python.

The hotplug branch (referenced in github.com/PortAudio/portaudio) of the C level portaudio code seems to be a dead-end, so that's a bumner.

Experimentally I observed that calling terminate() twice on the PyAudio() object gets me a fresh list without restarting the program (a TUI) even though, as far as I can tell, I only call open() once. Some ref-count bug?

I'll take the win 🔊

#Python #PyAudio #PortAudio

2025-01-12

Writing your own #audio analyzer using pyaudio-analysis journals.plos.org/plosone/arti
(possibly in combination with #pyaudio)
#python #audioanalysis

Both PyAudio and SoundDevice are Python libraries for audio input and output. What makes them different?

PyAudio provides direct bindings to the PortAudio library, giving you more control over audio parameters and access to lower-level functionality.

SoundDevice offers a simpler, more Pythonic interface that works seamlessly with NumPy arrays, making it convenient for processing audio data. SoundDevice is also actively maintained.

#python #pyaudio #sounddevice #NumPy

I spent a few hours on New Years Eve trying to listen to my USB microphone using Python3, PyQt5 and pyAudio. I can play WAV files using pyAudio, but fetching my microphone is becoming a bit challenging.

Lets see if I can get this working New Years Day. Time to read the documentation.
people.csail.mit.edu/hubert/py

#Linux #python #python3 #pyqt #pyqt5 #pyaudio #portaudio #USB #USB3 #microphone #WAV

Alexandre B A Villares 🐍villares@ciberlandia.pt
2023-04-09

I have created this discussion at the #py5 forum... To collect #PyAudio or other audio examples, If anyone else wants to post other experiments...

github.com/py5coding/py5genera

wink wink @kantel @TomLarrow @ericof @rzeta0
#Python #CreativeCoding

Alexandre B A Villares 🐍villares@ciberlandia.pt
2023-04-09

Tomorrow or maybe during the week I should read this tutorial mixing #Python #PyAudio and #PySimpleGUI ... k3no.medium.com/integrating-py

Alexandre B A Villares 🐍villares@ciberlandia.pt
2023-04-09

As usual, I have no idea of what I'm doing 😂​ #Python #Processing #py5 + #PyAudio microphone listening

# Code on the left, window with a row of varying circles on the right. In the blue background image, XFCE mouse logo.

import py5
import pyaudio
import numpy as np

"""Simple Blocking Stream PyAudio"""
CHUNK = 128  # Samples: 1024,  512, 256, 128
RATE = 44100  # Equivalent to Human Hearing at around 40 kHz
INTERVAL = 0.1  # Sampling Interval in Seconds
# If you are having trouble  making sense of the above, this might help:
# CHUNK: How many slices of sound
# RATE: How Fast these slices are captured
# INTERVAL: How much time to listen
p = pyaudio.PyAudio() # INIT PyAudio Instance
stream = p.open(format=pyaudio.paInt16,  # OPEN/Configure Stream:
                channels=1, rate=RATE,
                input=True, frames_per_buffer=CHUNK)
range_size = int(INTERVAL*RATE/CHUNK)

def setup():
    py5.size(400, 400)
    py5.no_fill()

def draw():
    py5.background(240)
    for i in range(range_size):  # STREAN INTERVAL
        data = np.frombuffer(stream.read(CHUNK), dtype=np.int16)
        v = np.amax(data)
        py5.circle(i * py5.width / range_size, py5.height / 2, v / 10)
        
def exiting():
    stream.stop_stream()
    stream.close()
    p.terminate()

py5.run_sketch()
Holly A. Gultianoaxoaxonic@synapse.cafe
2023-03-12

Tone generation with #Python turns out to be relatively simple. I found this short code on a blog raw.githubusercontent.com/make [edit: the variable Fs might need to be changed to sampling_rate in the non-sine waves]

which can be tweaked fairly intuitively (er, for me, someone who has been playing music for over 20 years): change "samples" number for different length files, add more for loops for different sequences, use different functions for different waveforms.

Since the waveforms are generated by values in lists being packed into byte sequences, I imagine someone could use spike data (maybe transformed a bit to be in range [-128, 127]) instead of something that generates a sinewave or whatever.

My original idea was to have the spikes trigger a wav file to be played, to make a spiking drum machine, which seems possible with #pygame, #pyaudio, or a module called playsound, but I realized it would require stitching them together and also generating silence, so I went for the simpler method that's more like a synthesizer

Client Info

Server: https://mastodon.social
Version: 2025.07
Repository: https://github.com/cyevgeniy/lmst