ush - Ultrasonic Shell
ush (ultrasonic shell) is a terminal program that enables communication between devices using ultrasonic sound waves. Send text messages, engage in real-time chat, or transfer files using audio frequencies above human hearing range (18-22 kHz).
Features
- Text Messaging: Send and receive text messages via ultrasonic audio
- Interactive Chat: Real-time chat mode for back-and-forth conversations
- File Transfer: Send files by breaking them into audio packets
- Cross-Platform: Works on macOS, Linux, and Windows
- Robust Protocol: Built-in error detection with CRC checksums
- Noise Filtering: Signal processing to handle noisy environments
- Audio Recording: Save/load transmissions as WAV files for debugging
Quick Start
Installation
Basic Usage
Send a message (Device A):
Listen for messages (Device B):
Requirements
- Audio devices: Working microphone and speakers/headphones
- Rust: 1.70+ (2021 edition)
- Operating System: macOS, Linux, or Windows
Usage Examples
Basic Communication
Send a simple message:
Listen with a 30-second timeout:
Send message multiple times for reliability:
Interactive Chat Mode
Start a chat session:
Chat with automatic acknowledgments:
File Transfer
Send a small file:
Send with custom chunk size and delay:
Receive a file:
Audio Debugging
Save transmitted audio for analysis:
Process audio from a file instead of live:
Testing and Diagnostics
Test the complete encoding/decoding pipeline:
List available audio devices:
Generate a test tone:
Measure background noise:
Advanced Options
Use custom frequencies:
Apply noise filtering:
Verbose logging:
Configuration
Audio Settings
--sample-rate: Audio sample rate (default: 44100 Hz)--freq-0: Frequency for bit '0' (default: 18000 Hz)--freq-1: Frequency for bit '1' (default: 20000 Hz)
Protocol Settings
The protocol uses:
- Modulation: FSK (Frequency Shift Keying)
- Symbol Duration: 10ms per bit
- Error Detection: CRC-32 checksums
- Framing: Preamble + start/end delimiters
Performance
Typical performance characteristics:
- Data rate: ~50-100 characters per second
- Frequency range: 18-22 kHz (above human hearing)
- Detection range: 2-10 meters (depending on environment)
- Latency: ~100-500ms end-to-end
Troubleshooting
Common Issues
"No audio device found"
- Ensure microphone/speakers are connected and working
- Check system audio permissions
- Try
ush test devicesto list available devices
"Failed to decode message"
- Increase volume on sending device
- Reduce background noise
- Use
--filteroption for noisy environments - Try
--repeat 3to send message multiple times
"Timeout waiting for signal"
- Check that devices are within range (~2-10 meters)
- Ensure audio frequencies aren't blocked by speaker/mic limitations
- Verify both devices are using same frequency settings
Audio Quality Tips
- Environment: Use in quiet environments when possible
- Distance: Keep devices 2-10 meters apart for best results
- Volume: Set speaker volume to 50-80% (not maximum)
- Hardware: Use external speakers/microphones for better range
- Interference: Avoid other ultrasonic sources (some motion sensors, etc.)
Debug Mode
Monitor live audio for debugging:
Performance Testing
Run comprehensive tests:
Benchmark encoding/decoding speed:
Architecture
Module Structure
src/
├── main.rs # CLI entry point and command routing
├── lib.rs # Library exports and module declarations
├── app.rs # Main application logic and coordination
├── cli.rs # Command-line interface definitions
├── audio.rs # Cross-platform audio I/O with cpal
├── modulation.rs # FSK encoding/decoding with FFT
├── protocol.rs # Message framing and error detection
└── error.rs # Centralized error handling
Key Dependencies
- cpal: Cross-platform audio I/O
- rustfft: Fast Fourier Transform for demodulation
- hound: WAV file reading/writing
- clap: Command-line argument parsing
- tokio: Async runtime for non-blocking I/O
- crc: CRC checksum calculation
Protocol Stack
Application Layer │ Text messages, files, chat
Protocol Layer │ Framing, sequencing, CRC checksums
Modulation Layer │ FSK (Frequency Shift Keying)
Physical Layer │ Ultrasonic audio (18-22 kHz)
Building from Source
Prerequisites
# Install Rust toolchain
|
# Install system dependencies (Linux only)
# Ubuntu/Debian:
# CentOS/RHEL:
Build Commands
# Debug build
# Release build (optimized)
# Run tests
# Run with logging
RUST_LOG=debug
# Generate documentation
Cross-Compilation
Build for different platforms:
# Add targets
# Cross-compile
Development
Running Tests
# Unit tests
# Integration tests
# Specific test
# With output
Adding New Features
- Fork the repository
- Create a feature branch
- Write tests first (TDD approach)
- Implement the feature
- Run full test suite
- Submit a pull request
Code Style
- Use
cargo fmtfor formatting - Use
cargo clippyfor linting - Follow Rust naming conventions
- Add documentation for public APIs
- Include tests for new functionality
FAQ
Q: Why ultrasonic frequencies? A: Ultrasonic frequencies (18-22 kHz) are above human hearing range, so communication doesn't create audible noise. Most computer speakers and microphones support these frequencies.
Q: What's the maximum range? A: Typically 2-10 meters depending on environment, speaker/microphone quality, and background noise. Outdoor range may be longer.
Q: Can I use this through walls? A: Sound waves don't penetrate walls well. ush is designed for same-room or adjacent room communication.
Q: Is this secure? A: Currently no encryption is implemented. Messages are transmitted as plaintext audio. Anyone with a microphone in range can receive messages.
Q: Why is it slow compared to WiFi/Bluetooth? A: Audio-based communication is inherently slower due to symbol duration and error correction needs. It's designed for short messages, not bulk data transfer.
Q: Does this work on mobile devices? A: The current implementation is desktop-focused. Mobile support would require platform-specific audio handling.
Contributing
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
Areas where help is needed:
- Mobile platform support
- GUI interface
- Improved noise filtering
- Encryption/security features
- Performance optimizations
- Additional modulation schemes
License
MIT License - see LICENSE file for details.
Credits
Built with:
- Rust programming language
- cpal for cross-platform audio
- rustfft for signal processing
- clap for CLI parsing
Inspired by projects like:
- Acoustic data transmission protocols
- Ham radio digital modes
- Ultrasonic communication research
Note: This is experimental software. Use responsibly and be mindful of local regulations regarding ultrasonic emissions.