An open API service indexing awesome lists of open source software.

https://github.com/chrisrobison/spectrogram

A tool to view the spectrogram of an audio stream or file or to create an audio file containing the spectrogram of a provided image.
https://github.com/chrisrobison/spectrogram

Last synced: 16 days ago
JSON representation

A tool to view the spectrogram of an audio stream or file or to create an audio file containing the spectrogram of a provided image.

Awesome Lists containing this project

README

          

# ๐ŸŽต Image-to-Audio Spectrogram Visualizer ๐ŸŽจ

A real-time audio visualization tool that converts images to sound and displays spectrograms of audio from various sources (microphone, audio files, or images converted to audio).

![Spectrogram Screenshot](screenshot.png)

## โœจ Features

- **๐ŸŽค Multiple Input Sources**:
- Microphone input for real-time audio visualization
- Audio file upload (.mp3, .wav, etc.)
- Image-to-audio conversion with spectrogram display

- **๐Ÿ“Š Real-time Visualization**:
- Responsive spectrogram display
- Customizable color mapping
- Pause/resume functionality

- **๐Ÿ“ฑ Responsive Design**:
- Works on both desktop and mobile devices
- Adaptive interface with hamburger menu on small screens

- **๐Ÿ–ผ๏ธ Image Processing**:
- Server-side image-to-audio conversion
- Uses the 'enscribe' command-line tool
- Supports common image formats (JPEG, PNG, GIF)

## ๐Ÿš€ Installation

### Prerequisites

- ๐Ÿ–ฅ๏ธ Web server with PHP support
- ๐Ÿ› ๏ธ 'enscribe' command-line tool installed on the server
- ๐ŸŒ Modern web browser with Web Audio API support

### Setup

1. Clone this repository:
```bash
git clone https://github.com/yourusername/image-to-audio-spectrogram.git
cd image-to-audio-spectrogram
```

2. Create required directories:
```bash
mkdir uploads
mkdir audio
```

3. Set proper permissions:
```bash
chmod 755 uploads
chmod 755 audio
```

4. Make sure PHP has permission to execute the 'enscribe' command.

5. Deploy to your web server or run locally with PHP's built-in server:
```bash
php -S localhost:8000
```

## ๐ŸŽฎ Usage

1. Open the application in your web browser.

2. Choose an input source:
- **๐ŸŽค Microphone**: Click "Start Mic" to use your device's microphone
- **๐ŸŽง Audio File**: Upload an audio file using the "Audio File" button
- **๐Ÿ–ผ๏ธ Image File**: Upload an image to convert to audio using the "Image File" button

3. Adjust visualization parameters:
- **๐ŸŒˆ Hue**: Changes the color spectrum used in the visualization
- **โ˜€๏ธ Base**: Adjusts the base brightness level
- **๐Ÿ“Š Range**: Controls the dynamic range of brightness

4. Additional controls:
- **โฏ๏ธ Pause/Resume**: Freezes or continues the visualization
- **๐Ÿงน Clear**: Resets the visualization display

## โš™๏ธ How It Works

### Client-Side

The web application uses the Web Audio API to:
- Capture audio from the microphone
- Process audio files
- Analyze frequency data using an FFT analyzer
- Visualize the frequency spectrum as a scrolling spectrogram

### Server-Side

The PHP handler (`enscribe_handler.php`):
1. Receives uploaded images
2. Validates file types and sizes
3. Executes the 'enscribe' command to convert images to audio
4. Returns the path to the generated audio file

## ๐Ÿ”ฌ Technical Details

- The spectrogram visualizes frequency data from 0Hz to ~22kHz (depending on sample rate)
- Frequency data is mapped logarithmically for more natural audio visualization
- The Web Audio API's AnalyserNode performs real-time FFT analysis
- Color mapping uses HSL color space for intuitive parameter control

## ๐Ÿ”’ Security Considerations

- File validation prevents upload of unauthorized file types
- Command execution is protected against injection using `escapeshellcmd()` and `escapeshellarg()`
- File size limits prevent server resource abuse

## ๐Ÿ”ง Troubleshooting

- **๐Ÿ”‡ No audio visualization**: Ensure your browser supports the Web Audio API
- **๐ŸŽค Microphone access denied**: Check browser permissions for microphone access
- **๐Ÿ–ผ๏ธ Image processing fails**: Verify the 'enscribe' command is properly installed and accessible to PHP
- **๐Ÿ“ฑ Blank display on mobile**: Try rotating your device or refreshing the page

## ๐ŸŒ Browser Compatibility

- Chrome 70+
- Firefox 63+
- Safari 12.1+
- Edge 79+

## ๐Ÿ“„ License

[MIT License](LICENSE)

## ๐Ÿ‘ Acknowledgments

- The 'enscribe' tool for image-to-audio conversion
- Web Audio API for real-time audio processing capabilities