![](https://private-user-images.githubusercontent.com/52180475/331840316-40fcaf33-45c9-4dbd-93c7-f8f8057d3125.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjM3MzM3NDcsIm5iZiI6MTcyMzczMzQ0NywicGF0aCI6Ii81MjE4MDQ3NS8zMzE4NDAzMTYtNDBmY2FmMzMtNDVjOS00ZGJkLTkzYzctZjhmODA1N2QzMTI1LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MTUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODE1VDE0NTA0N1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTc1N2ViMzY5ODNhODIzZjhhZGQ0YzdlNzg3YTA4OTVmN2JlNmMwNjI2MzcyYzRkM2U5NzRiMGNjYjBmMDBlYTUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.VFNL_10Q6otocU37z_jGCfVFPpZL2xiZbyUA0r1wQYk)
A Python script that converts audio files (WAV, MP3, OGG etc.) to AHAP (Apple Haptic Audio Pattern) format, which can be used to synchronize audio and haptic effects in games, virtual reality experiences, and interactive multimedia. With a simple GUI, AHAPpyUI.py, to streamline the conversion process. A sample iOS app is available with an example implementation.
This project was inspired by Lofelt's NiceVibrations, which offers advanced haptic feedback solutions for various applications. I felt a need for an even simpler implementation of haptic-audio synchronization that focused specifically on iOS development, leading to the creation of this AHAP converter.
You can install the dependencies using pip:
pip install numpy librosa pydub tkinter
or install using the requirements:
pip install -r requirements.txt
Run the script with the following command:
python generate_ahap.py input_wav [--output_dir OUTPUT_DIR] [--mode MODE] [--split SPLIT]
--input_wav: Path to the input WAV file. --output_dir: Directory where the output AHAP files will be saved. Defaults to the same directory as the input WAV file. --mode: Mode for processing the WAV file. Can be 'sfx' (sound effects) or 'music'. Defaults to 'music'. --split: Split mode for processing. Options are 'none', 'all', 'vocal', 'drums', 'bass', 'other'. Only applicable when mode is 'music'. Defaults to 'none'.
Example:
python generate_ahap.py example.wav --mode music --split vocal
New AHAP files will be saved in the specified directory, or the same directory as the WAV file if no output directory is specified.
Alternatively, you can use the AHAPpyUI.py file, which provides a minimal GUI for the conversion process.
python AHAPpyUI.py
![Screenshot 2024-05-18 at 9 23 49 PM](https://private-user-images.githubusercontent.com/52180475/331840825-99dc5b2a-9547-40c0-adb7-55ce5c1641d5.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjM3MzM3NDcsIm5iZiI6MTcyMzczMzQ0NywicGF0aCI6Ii81MjE4MDQ3NS8zMzE4NDA4MjUtOTlkYzViMmEtOTU0Ny00MGMwLWFkYjctNTVjZTVjMTY0MWQ1LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MTUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODE1VDE0NTA0N1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWRlYTk2YWQ2ZjU5YjgxNGYxMDRlOWYxZGM0MDM0NmUyY2YyOWRlN2Y1OTAxZTk3MWYwODZjNzY3OTk5MDEyMTYmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.qXjhMoKteGXGtC5sigODplNYduHIXRpXUuAqMeRmwAc)
- Transient and Continuous Events: The AHAP file contains both transient and continuous haptic events, synchronized with the audio content.
- Dynamic Parameter Calculation: Haptic parameters such as intensity and sharpness are calculated dynamically based on audio features.
- Customizable Parameters: You can adjust thresholds and window sizes to customize the conversion process according to your requirements.
- Music Mode and Splits: In music mode, you can specify different splits such as 'vocal', 'drums', 'bass', and 'other' to process specific components of the audio.
The conversion process involves the following steps:
- Load Audio: The input WAV file is loaded using PyDub and converted to a NumPy array.
- Feature Extraction: Audio features such as onsets and spectral centroid are extracted using Librosa.
- Event Generation: Transient and continuous haptic events are generated based on the audio features.
- Parameter Calculation: Haptic parameters such as intensity and sharpness are calculated dynamically.
- Output AHAP: The AHAP content is written in JSON format and saved to same directory as the input file.
If AHAPpy has helped you in your own projects I would love to hear about it! If you have any questions, feedback, or suggestions for improvement, feel free to reach out.