Last active
May 30, 2024 04:01
-
-
Save Alwinfy/1fa92218a8eeebbf5ab18b4921c637df to your computer and use it in GitHub Desktop.
audio DSP demo (WARNING: LOUD)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# requires `pip install pyaudio` | |
import pyaudio | |
# most DSP software on the market uses floats -1 to 1 | |
# we instead use ints 0 to 255, due to a quirk of pyaudio | |
single_rotation = [int(i * 255 / 99) for i in range(100)] | |
# or: | |
# single_rotation = [random.randint(0, 255) for i in range(100)] | |
# or: | |
# single_rotation = [(i < 50) * 255 for i in range(100)] | |
# duplicate a bunch | |
one_second = single_rotation * 441 | |
p = pyaudio.PyAudio() | |
stream = p.open(44100, channels=1, format=pyaudio.paUInt8, output=True) | |
stream.write(bytes(one_second)) | |
stream.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment