Real-time AI image generation service using StreamDiffusion, controllable via OSC and sharing textures via Spout.
A real-time image generation service using StreamDiffusion, controllable via OSC (Open Sound Control) and communicating via Spout for GPU-accelerated texture sharing.
Platform: Windows only (requires Spout)
- OSC Control: Receive prompts and control commands via OSC
- Spout I/O: GPU-accelerated texture sharing for real-time communication
- Prompt Caching: Fast prompt switching without model reset
- Real-time Generation: Continuous img2img generation loop
- Flexible Resolution: Supports any resolution (default 512×512, configurable via command line)
Client Application (Processing, TouchDesigner, Cinder, etc.)
↓ Spout: "SourceImage" (input texture)
↓ OSC: /prompt "your prompt here"
StreamDiffusion Spout Service
↓ StreamDiffusion Pipeline (SD-Turbo)
↓ Spout: "StreamDiffusion" (generated image)
Client Application receives & displays
- Windows (Spout is Windows-only)
- Python 3.9+
- CUDA-capable GPU (NVIDIA)
Recommended directory structure: Clone both repositories as siblings:
your-workspace/
├── StreamDiffusion/ # Official StreamDiffusion repo
└── streamdiffusion_spout_service/ # This service
Steps:
-
Clone and install StreamDiffusion
# Clone StreamDiffusion library git clone https://github.com/cumulo-autumn/StreamDiffusion.git cd StreamDiffusion pip install . cd ..
-
Clone this repository
git clone https://github.com/olwal/streamdiffusion-spout-service.git cd streamdiffusion_spout_service -
Install PyTorch with CUDA support
# For CUDA 11.8 (adjust cu118 to your CUDA version: cu117, cu121, etc.) pip install torch torchvision --index-url https://download.pytorch.org/whl/cu118 -
Install remaining dependencies
pip install -r requirements.txt
After installation, run the service:
# If you cloned as siblings (recommended):
python main.py
# If StreamDiffusion is elsewhere, specify the path:
python main.py --streamdiffusion-path /path/to/StreamDiffusion
# On Windows, use forward slashes or quote backslashes:
python main.py --streamdiffusion-path ../StreamDiffusion
python main.py --streamdiffusion-path "..\StreamDiffusion"
# Or set environment variable:
export STREAMDIFFUSION_PATH=/path/to/StreamDiffusion
python main.pySend OSC commands (from another terminal or application):
/prompt "a beautiful landscape"
/start
Note: If running directly from source without installing the package, Python automatically adds src/ to the path.
# Start with default settings
python main.py
# Or use the included batch file (Windows)
start.bat
# Custom settings
python main.py --model stabilityai/sd-turbo --width 512 --height 512 --osc-port 7000--streamdiffusion-path PATH Path to StreamDiffusion repo (default: ../StreamDiffusion or $STREAMDIFFUSION_PATH)
--osc-ip IP OSC server IP (default: 127.0.0.1)
--osc-port PORT OSC server port (default: 7000)
--spout-in NAME Spout receiver name (default: SourceImage)
--spout-out NAME Spout sender name (default: StreamDiffusion)
--model MODEL Model ID or path (default: stabilityai/sd-turbo)
--lora LORA LoRA name:scale pairs (e.g. "lora1:0.5,lora2:0.7")
--width W Image width (default: 512, can be any size)
--height H Image height (default: 512, can be any size)
--acceleration TYPE Acceleration: none, xformers, tensorrt (default: xformers)
--delta FLOAT Delta noise multiplier (default: 0.5)
--verbose LEVEL Verbosity: 0=quiet, 1=startup, 2=+OSC, 3=+frames (default: 1)
--quiet Quiet mode (verbose=0)
Send OSC messages to control the service (default port: 7000):
/prompt "your prompt here"
/start or /s - Start continuous generation
/stop or /S - Stop continuous generation
/trigger or /t - Trigger single generation
/p - Enable Spout output
/P - Disable Spout output
/x - Restart Spout connections
/verbose 2 - Set verbosity level (0-3)
/v - Cycle through verbosity levels
/von - Verbose on (level 2)
/voff - Quiet mode (level 0)
from pythonosc import udp_client
client = udp_client.SimpleUDPClient("127.0.0.1", 7000)
# Set prompt and start generation
client.send_message("/prompt", "a beautiful mountain landscape, sunset")
client.send_message("/start", [])Using oscsend (from liblo-tools):
oscsend localhost 7000 /prompt s "a beautiful landscape"
oscsend localhost 7000 /startYou may see this warning at startup:
A matching Triton is not available, some optimizations will not be enabled.
Error caught was: No module named 'triton'
This is safe to ignore. Triton is an optional NVIDIA optimization library. The daemon will work fine without it using xformers acceleration instead.
To suppress the warning (optional):
pip install tritonNote: Triton only works on Linux. On Windows, this warning is expected and harmless.
# Restart Spout connections via OSC
# Send: /x
# Or check Spout sender list in your client application# Enable verbose mode to see OSC messages
python main.py --verbose 2
# Check OSC port matches your client application (default: 7000)# Use smaller model or reduce batch size
# Already using minimal frame_buffer_size=1 in diffusion_engine.pyIf you get "StreamDiffusion utils not found", you have several options:
# Option 1: Use command-line argument
python main.py --streamdiffusion-path /path/to/StreamDiffusion
# Option 2: Set environment variable (persists for session)
export STREAMDIFFUSION_PATH=/path/to/StreamDiffusion
python main.py
# Option 3: Ensure sibling directory structure (default)
your-workspace/
├── StreamDiffusion/
└── streamdiffusion_spout_service/streamdiffusion_spout_service/
├── src/
│ └── streamdiffusion_spout_service/ # Main package
│ ├── __init__.py
│ ├── config.py # Configuration & global state
│ ├── osc_server.py # OSC command handling
│ ├── diffusion_engine.py # StreamDiffusion integration
│ ├── spout_handler.py # Spout I/O
│ └── utils.py # Helper functions
├── main.py # Entry point (handles path resolution)
├── requirements.txt # Python dependencies
├── setup.py # Package setup
├── LICENSE # MIT License
└── README.md # This file
Note: The service dynamically imports utils/wrapper.py from the StreamDiffusion repository at runtime (Apache 2.0 license). The path is automatically resolved—no manual setup needed.
This project builds upon:
- StreamDiffusion - Real-time diffusion pipeline (Apache 2.0 License)
- Spout - GPU texture sharing for Windows
- python-osc - OSC protocol implementation
Open source creative coding frameworks with Spout support:
- openFrameworks - C++ creative toolkit, Spout via ofxSpout
- Cinder - C++ library for creative coding, Spout via Cinder-Spout2
- Processing - Creative coding in Java, Spout via Spout for Processing
Commercial applications:
- TouchDesigner - Node-based visual programming for real-time projects
MIT License
Issues and pull requests welcome! This is an early-stage project, so feedback is appreciated.