Generate music based on metadata using Soundraw's API and this Bash script. It processes a CSV file containing music metadata, sends API requests to Soundraw, and downloads the generated music files in .m4a format.
Special thanks to the soundraw.io team for creating such a fantastic and user-friendly API.
For more information, refer to the soundraw.io API documentation:
- Bash shell
- jq (JSON processor)
- curl (HTTP client)
- AWK (text processing tool)
- shuf (random number generator)
Ensure these tools are installed and configured on your system.
Installation of jq on Windows:
curl -L -o /usr/bin/jq.exe https://github.com/stedolan/jq/releases/latest/download/jq-win64.exe
Create a .secret file in your project directory with the following content. Ensure this file is secure and not accessible publicly.
export URL=https://soundraw.io/api/v2/musics/compose
export AUTH_TOKEN='your_soundraw_auth_token'
Replace 'your_soundraw_auth_token' with your actual soundraw.io API auth token.
Optionally, you can Configure the default values of the following parameters within the generate.sh file:
- param_file_name: Name of the CSV file containing input parameters (default: soundraw_params.csv)
- num_batches: Number of songs generated per line in the input file (default: 2)
- length: Duration of the generated music in seconds (default: 300)
mood,genres,themes,tempo,tempo_2,energy_levels
Peaceful,Rock,Wedding & Romance,low,,Medium
Elegant,Lofi Hip Hop,Wedding & Romance,normal,normal,Medium
bash
chmod +x generate.sh
./generate.sh ./soundraw_params_samina.csv 5 30
chmod +x generate.sh
./generate.sh
In cases where an invalid parameter is supplied, the Soundraw.io API will return the following error:
{
"error":"No music available. Try choosing different parameters."
}
To assist with troubleshooting, parameters that result in errors are stored in the output/$today/errors directory. The corresponding error file will be named according to the pattern "$today_ts-$param_file_name-errors.csv". See screenshot section for details.
This setup ensures that you can easily locate and review any parameters that did not yield the expected results, facilitating a smoother and more efficient error-handling process.
- Extract music metadata from CSV file.
- Generate a unique output file name.
- Prepare JSON payload for the API request.
- Send POST request to Soundraw's API.
- Download music file if m4a_url is present in the response.
- Save API response and request parameters to a JSON file.
- Exit script if m4a_url is not present, handling errors appropriately.
Check the output directories (output/$today/music, output/$today/response, output/$today/temp) for downloaded music files, API responses, and temporary files. Manage sensitive data securely.
- Ensure the input CSV file and .secret file are correctly formatted and located.
- The API is expected to return a JSON response containing the m4a_url field.
As of October 5th, 2023, the available values for moods, themes, genres, and energy levels are:
Angry, Busy & Frantic, Dark, Dreamy, Elegant, Happy, Hopeful, Humorous, Light, Love, Mysterious, Neutral, Peaceful, Playful, Powerful, Sad, Scary, Serious, Sexy, Sporty, Suspenseful, Unearthly, Upbeat, Warm
Acoustic, Ambient, Blues, Cinematic, Classical, Country, Dance, Electronic, Folk, Funk, Hip Hop, Jazz, Latin, Metal, Pop, R&B, Reggae, Rock, Soul, World
1960s, 1970s, 1980s, 1990s, 2000s, Action, Adventure, Animation & Games, Business & Corporate, Celebration & Party, Children, Christmas, Cinematic, Commercials & Advertising, Cooking, Documentary, Drama, Fashion, Halloween, Healing & Meditation, Horror, Love & Romance, Meditation, News, Religious & Gospel, Sci-Fi & Fantasy, Sports, Storytelling, Summer, Suspense & Thriller, Technology, Travel & Nature, Vlog, Wedding & Romance, Winter, Workout, Yoga & Fitness
Very Low, Low, Medium, High, Very High
This project is under the MIT License.
Suggestions and contributions are always welcome! Follow these steps:
- Fork the Project
- Create your Feature Branch (git checkout -b feature/AmazingFeature)
- Commit your Changes (git commit -m 'Add some AmazingFeature')
- Push to the Branch (git push origin feature/AmazingFeature)
- Open a Pull Request
๐ Support & Appreciation ๐
If you've found this repository valuable or it has made your work easier, consider expressing your gratitude and encouragement by making a donation. Your support fuels ongoing development and keeps the project thriving. ๐
๐ Support the Developer - Donate Now
Every contribution, no matter how big or small, makes a difference and is immensely appreciated. Thank you for being awesome! ๐
Thank you to all contributors and users of this project!
- Syed Ali Bilgrami (Developer)
- Samina Mukhtar (Tester/Music Enthusiast)
For inquiries, suggestions, or bug reports, contact us at:
-
bilgrami @ gmail . com. Please mention "soundraw.io repo ideas" in the subject line to get priority reply.
-
If this project has been helpful, consider supporting its development by using this link to donate
-
add support for tempo, energy levels, bpm
-
add support for creating tracks longer than 300s.
๐ถ Stay Tuned with saMas Music! ๐ถ
If you're intrigued by the music generated via soundraw.io and wish to explore more, make sure to check out our YouTube channel! ๐ฅ
๐ Subscribe Now and hit the like button to stay updated with our latest musical creations. Your support helps us keep the rhythm alive and continue creating amazing content for you! ๐๐บ
Don't forget to share with your friends and spread the love for music! ๐ค๐ต
Thank you for being a part of our musical journey! ๐