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.