Skip to content

Extracts the dominant frequency sequence from an OGG audio file and exports it as a text file.

License

Notifications You must be signed in to change notification settings

R0mb0/Audio2pwm_frequency

🎼 Dominant Frequency Extractor for Arduino PWM

Codacy Badge Maintenance Open Source Love svg3 MIT Donate

This Python script extracts the dominant frequency sequence from audio files and exports them as text files, ready for Arduino PWM sound reproduction. You can choose the extraction algorithm via the settings.json file.

⚡ Supported Algorithms

  • fft: Fast Fourier Transform. Good for simple, relatively stationary signals.
  • autocorrelation: Finds periodicity by correlating the signal with itself. Robust for detecting pitch in periodic signals.
  • zcr: Zero Crossing Rate. Very simple, works best for pure tones.
  • cepstrum: Uses the cepstral domain to find pitch, robust for complex signals.

🛠️ Configuration

Create a settings.json file in the same directory as the script. Example:

{
  "samples_per_group": 300,
  "algorithm": "fft"
}
  • samples_per_group: Number of samples per analysis window (min 2).
  • algorithm: Choose "fft", "autocorrelation", "zcr", or "cepstrum".

🚀 Usage

  1. Place your audio files (.wav, .flac, .ogg, .aiff) in the script directory.
  2. Run the script:
    python extract_dominant_frequencies.py
  3. If multiple audio files are present, select one or all.
  4. Output .txt files will be created in the output folder, named after the audio file.

Each output file starts with a comment line indicating the algorithm used.

📦 Requirements

  • Python 3.x
  • numpy, soundfile (install via pip install numpy soundfile)

💡 Notes

  • For best results, experiment with different algorithms and samples_per_group values.
  • The output frequencies are suitable for PWM generation in Arduino.

Releases

No releases published

Sponsor this project

Languages