Versatile I/O library for Python, providing easy access to audio, video, and input device capabilities.
Project description
🎮 pamiq-io
pamiq-io is a versatile I/O library for Python, providing easy access to audio, video, and input device capabilities for interactive applications, simulations, and AI projects, made for P-AMI<Q>.
✨ Features
- 🎤 Audio input/output via SoundCard
- 📹 Video input via OpenCV
- 🎛️ OSC (Open Sound Control) communication
- ⌨️ Keyboard simulation
- 🖱️ Mouse simulation
🔧 Requirements
- Python 3.12+
- Linux (due to Inputtino and other dependencies)
- OBS Studio (for video capture)
- PulseAudio (for audio)
📦 Installation
Using pip
# Install build dependencies first
sudo apt install git cmake build-essential pkg-config libevdev-dev
# Inputtino is not published to pypi, so install manually.
pip install "git+https://github.com/games-on-whales/inputtino.git#subdirectory=bindings/python&branch=stable"
# You may need ninja
pip install ninja
# Install the base package
pip install pamiq-io
# For demo scripts, include the demo extras
sudo apt install libsndfile1
pip install pamiq-io[demo]
Development installation
# Install build dependencies
sudo apt install git cmake build-essential pkg-config libevdev-dev libsndfile1
# Clone and setup
git clone https://github.com/MLShukai/pamiq-io.git
cd pamiq-io
make venv # Sets up virtual environment with all dependencies
🧰 Command-Line Tools
pamiq-io includes several helpful command-line tools:
# List available video input devices
pamiq-io-show-opencv-available-input-devices
# List available audio input devices
pamiq-io-show-soundcard-available-input-devices
# List available audio output devices
pamiq-io-show-soundcard-available-output-devices
🛠️ Setup
OBS Virtual Camera
-
Install OBS Studio following the official installation instructions:
- Visit https://obsproject.com
- Follow the installation guide for Linux (typically using a PPA for Ubuntu-based distributions)
-
If the virtual camera functionality is not available after installing OBS, you may need to install v4l2loopback:
sudo apt install v4l2loopback-dkms sudo modprobe v4l2loopback
-
In OBS, start the virtual camera (Tools → Start Virtual Camera)
-
(Optional) To find the virtual camera device, you can install v4l-utils:
sudo apt install v4l-utils v4l2-ctl --list-devices | grep -A 1 'OBS Virtual Camera' | grep -oP '\t\K/dev.*'
🐳 Docker
A Docker configuration is provided for easy development and deployment.
Basic usage:
# Build a basic image with required dependencies
FROM ubuntu:24.04
# Install dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
python3 python3-pip \
git cmake build-essential pkg-config libevdev-dev \
libopencv-dev \
libsndfile1 \
pulseaudio \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Install pamiq-io
RUN pip install pamiq-io[demo]
# For development, you may want to check our devcontainer configuration:
# https://github.com/MLShukai/pamiq-io/blob/main/.devcontainer/Dockerfile
When running the container, you need privileged access for hardware devices:
docker run --privileged -it your-pamiq-image
⚠️ Note: The
--privilegedflag is required for hardware access to input devices.
PulseAudio in Docker
To use audio inside Docker, you need to set up PulseAudio properly:
docker run --privileged -it \
-v ${XDG_RUNTIME_DIR}/pulse/native:${XDG_RUNTIME_DIR}/pulse/native \
-v $HOME/.config/pulse/cookie:/root/.config/pulse/cookie \
-e PULSE_SERVER=unix:${XDG_RUNTIME_DIR}/pulse/native \
-e PULSE_COOKIE=/root/.config/pulse/cookie \
your-pamiq-image
📚 Usage
Video Input
from pamiq_io.video import OpenCVVideoInput
# List available video devices
from pamiq_io.video.input.opencv import show_video_devices
show_video_devices()
# Capture from camera using default parameters
video_input = OpenCVVideoInput(camera=0)
frame = video_input.read()
# Capture with specific resolution
video_input = OpenCVVideoInput(camera=0, width=640, height=480, fps=30.0)
frame = video_input.read()
# Capture with mixed parameters (use default width, but specify height)
video_input = OpenCVVideoInput(camera=0, width=None, height=720, fps=None)
frame = video_input.read()
Audio Input
from pamiq_io.audio import SoundcardAudioInput
# List available audio input devices
from pamiq_io.audio.input.soundcard import show_all_input_devices
show_all_input_devices()
# Capture audio
audio_input = SoundcardAudioInput(sample_rate=44100, channels=2)
audio_data = audio_input.read(frame_size=1024)
Audio Output
from pamiq_io.audio import SoundcardAudioOutput
import numpy as np
# List available audio output devices
from pamiq_io.audio.output.soundcard import show_all_output_devices
show_all_output_devices()
# Play a simple sine wave
sample_rate = 44100
duration = 1.0 # seconds
t = np.linspace(0, duration, int(sample_rate * duration), endpoint=False)
sine_wave = np.sin(2 * np.pi * 440 * t).reshape(-1, 1).astype(np.float32) # 440Hz
audio_output = SoundcardAudioOutput(sample_rate=sample_rate, channels=1)
audio_output.write(sine_wave)
OSC Communication
from pamiq_io.osc import OscOutput, OscInput
# Send OSC messages
osc_output = OscOutput(host="127.0.0.1", port=9001)
osc_output.send("/test/address", 42)
# Receive OSC messages
def handler(value):
print(f"Received: {value}")
osc_input = OscInput(host="127.0.0.1", port=9001)
osc_input.add_handler("/test/address", handler)
osc_input.start(blocking=False)
Keyboard and Mouse Simulation
from pamiq_io.keyboard import InputtinoKeyboardOutput, KeyCode
from pamiq_io.mouse import InputtinoMouseOutput
# Keyboard simulation
keyboard = InputtinoKeyboardOutput()
keyboard.press(KeyCode.CTRL, KeyCode.C) # Press Ctrl+C
keyboard.release(KeyCode.CTRL, KeyCode.C) # Release Ctrl+C
# Mouse simulation
mouse = InputtinoMouseOutput()
mouse.move(100, 50) # Move 100 pixels right, 50 pixels down
mouse.press("left")
mouse.release("left")
🧪 Demo Scripts
The repo includes several demo scripts to help you get started:
# Audio demos
python demos/soundcard_audio_input.py --list-devices
python demos/soundcard_audio_output.py --frequency 440 --duration 3
# Video demos
python demos/opencv_video_input.py --camera 0 --output frame.png
# OSC demos
python demos/osc_io.py
# Input simulation demos
python demos/inputtino_keyboard_output.py
python demos/inputtino_mouse_output.py --radius 100 --duration 5
📝 License
This project is licensed under the MIT License - see the LICENSE file for details.
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Run tests (
make test) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pamiq_io-0.2.0.tar.gz.
File metadata
- Download URL: pamiq_io-0.2.0.tar.gz
- Upload date:
- Size: 54.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a43f8e1d8e768b594c88e24e8e6d5c4f8722f90caab096cbfc480e5e3fd41d4c
|
|
| MD5 |
4c41b85c9f675427e057df106867ea38
|
|
| BLAKE2b-256 |
9b2b47ee26c2b329890f534c1f454c0ec16600d0188513d9dcb77b37bddc4d6a
|
Provenance
The following attestation bundles were made for pamiq_io-0.2.0.tar.gz:
Publisher:
publish-to-pypi.yml on MLShukai/pamiq-io
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pamiq_io-0.2.0.tar.gz -
Subject digest:
a43f8e1d8e768b594c88e24e8e6d5c4f8722f90caab096cbfc480e5e3fd41d4c - Sigstore transparency entry: 202379576
- Sigstore integration time:
-
Permalink:
MLShukai/pamiq-io@fe6e4d6313c85fc5d4d990b3c8227b4c017969d5 -
Branch / Tag:
refs/tags/0.2.0 - Owner: https://github.com/MLShukai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@fe6e4d6313c85fc5d4d990b3c8227b4c017969d5 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pamiq_io-0.2.0-py3-none-any.whl.
File metadata
- Download URL: pamiq_io-0.2.0-py3-none-any.whl
- Upload date:
- Size: 19.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
04e86b5afbbe6070bae921848a2ac5d18284aa4649b014f897345d6bf56e8c6e
|
|
| MD5 |
335dcb34f780ae9f46236914049ea7ff
|
|
| BLAKE2b-256 |
487e76fb4ad0e1d75114bd46b4a4d49dd5cc89eb7cf5e95a6db9dd56c13c0974
|
Provenance
The following attestation bundles were made for pamiq_io-0.2.0-py3-none-any.whl:
Publisher:
publish-to-pypi.yml on MLShukai/pamiq-io
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pamiq_io-0.2.0-py3-none-any.whl -
Subject digest:
04e86b5afbbe6070bae921848a2ac5d18284aa4649b014f897345d6bf56e8c6e - Sigstore transparency entry: 202379580
- Sigstore integration time:
-
Permalink:
MLShukai/pamiq-io@fe6e4d6313c85fc5d4d990b3c8227b4c017969d5 -
Branch / Tag:
refs/tags/0.2.0 - Owner: https://github.com/MLShukai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@fe6e4d6313c85fc5d4d990b3c8227b4c017969d5 -
Trigger Event:
push
-
Statement type: