This project is a Go application that allows users to generate an audio spectrogram from a YouTube video URL. The application downloads the audio from the specified YouTube video URL and creates a spectrogram image in PNG format.
This project relies on ffmepg to convert downloaded audio files to WAV format.
NOTE: With recent updates to Youtube you may get a 403 error when trying to save the audio to a file. This is a recent change to prevent bots. I found if you are playing the video when running the application, this appears to bypass the download request.
youtube-spectrogram
├── src
│ ├── downloader.go # Functions for downloading audio from YouTube
│ ├── main.go # Entry point of the application
│ ├── spectrogram.go # Functions for generating the audio spectrogram
│ ├── utils.go # Utility functions for checking if a file exists
│ └── wavConverter.go # Uses ffmpeg to convert an audio file to wav format
└── README.md # Project documentation
-
Clone the repository:
git clone https://github.com/edgehew/spectrogram-generator.git cd spectrogram-generator -
Install Go: Make sure you have Go installed on your machine. You can download it from golang.org.
-
Install ffmpeg Make sure you have ffmpeg installed
# Example: sudo apt install ffmpeg -
Install dependencies: Navigate to the
srcdirectory and run:go mod tidy -
Build the application: Run the following command
go build src/*.go
To run the application, use the following command:
go run src/*.go --help
// or after building the application
./downloader --help
Usage:
-hop int
Hop size for the spectrogram (default 512)
-output string
Output path for the spectrogram image (default "spectrogram.png")
-url string
YouTube video URL
-window int
FFT window size (default 1024)
Replace <YouTube-Video-URL> with the actual URL of the YouTube video you want to process.
go run src/*.go -url "https://www.youtube.com/watch?v=dQw4w9WgXcQ" -output rickroll.png
// After building
./downloader -url "https://www.youtube.com/watch?v=dQw4w9WgXcQ" -output rickroll.png
This command will download the audio from the specified YouTube video and generate a spectrogram image named rickroll.png in the current directory.
This project is licensed under the MIT License - see the LICENSE file for details.