Skip to content

Fuddlebob/MelodyBot3456

Repository files navigation

MelodyBot3456

Melodybot3456 is a bot that generates random melodies and posts them to facebook and/or twitter.

Facebook: https://www.facebook.com/MelodyBot3456-293565591327666/

Twitter: https://twitter.com/MelodyBot3456

A few external files are required for the script to run correctly; A config file (example provided), and a number of Soundfont2 .sf2 Instrument files. The requirements and usage of these files are noted below.

Once the files are present, the script can be run as follows:

python3 melodybot <config file>

This will create the randomised music track, and, if enabled in the config file, post the video to Facebook and/or Twitter.

Config File

The config file for this bot takes the form of a single JSON object, with several smaller children objects covering various functions of the bot, for ease of use. This section will go through the sections of the config file and explain their use. Please refer to the example config file (exampleConfig.json) if you're having trouble.

outfiles

The outfile section lists the locations of various files generated by the script. Naturally, it is recommended that the provided files do not conflict with existing files on your computer.

  • home
    • This is the directory that all other files (except outlog) will be created inside. This property is prepended to every other filename to create the final file name for that output file.
  • outmp4
    • The final MP4 video output that is posted to Facebook/Twitter
  • outwav
    • WAV audio file of the generated music track. The file is later converted to an MP3 audio file.
  • outmp3
    • MP3 audio file of the generated music track. This is combined with the sheet music frames to create the final video.
  • outmp3_temp
    • A temporary MP3 audio file created while normalizing the volume of the audio track. This file is removed during the execution of the script.
  • outmid
    • Generated MIDI file containing the track data. This is used by FluidSynth to create the WAV audio file.
  • outpng
    • PNG image file of the cropped sheet music. This is used to generate the individual frames that are used in the final video.
  • outsvg
    • SVG image file of the full sheet music. This is used to generate the individual frames that are used in the final video.
  • outlog
    • Text file listing date/time, seed, and generated message for each run of the bot. This is the only file that is not rooted in the home directory.
  • frame_folder
    • Directory containing the individual frames of the final video. This folder and the frames will be generated as necessary during the execution of the script.
  • frame_data_file
    • Text file containing the timing of each frame in the final video. This is used by ffmpeg to create the final video.

remove_files

This section lists each property from the outfile section along with a true or false, noting whether the corresponding outfile will be removed after the script has finished all other execution. Properties marked with true will be deleted, while those marked with false will remain.

Please note that ALL files listed, regardless of property value, will be removed at the start of script execution, to ensure the smooth running of the bot. If for whatever reason you do not wish for this to happen, properties can be omitted from this section, however this may cause issues while running the script.

infiles

This section contains properties detailing other input files for the bot. Currently there is only one property: soundfont_folder, which lists the directory containing the Soundfont instruments the script uses to generate the track.

song_params

This section contains properties that affect the track being generated.

  • instrument
    • The name of the instrument to generate the track with. If set to null, the instrument will be picked randomly.
  • tempo
    • The tempo of the generated track. If set to null, the tempo will be picked randomly.
  • key
    • The key in which the generated track is played. If set to null, the key will be picked randomly.
  • seed
    • The starting seed used by the random number generator. If set to null, the seed will be picked randomly.
  • sample_rate
    • The sample rate of the generated audio track. This was used previously, but in the current iteration it is not used at all.
  • target_volume
    • The desired volume of the generated audio track, in decibels. A specific value is required for this property.

upload

This section contains properties relating to uploading the tracks to social media platforms Facebook and Twitter. I may look into adding more platforms in future.

Each subsection relates to a single platform, and contains an upload property that should be set to true if uploading to that platform is desired, and false otherwise. The remaining properties are for various tokens and keys that are required for a successful upload. If you are planning to use this feature, please check in with the desired platform for details on how to obtain these keys.

archive

This section contains properties relating to the archiving of generated files. If the archive property is set to true, then, prior to the file removal step, a ZIP of the file home folder (listed in the outfile section) will be created, and placed into the directory listed in the location property. The file name will be generated based off the current time and date at which the file is created.

fun_stuff

This section details random effects that can be applied during the generation of the video. Set each property to true if you want the effect to be applied, and false otherwise. Currently there is only one property, but I may add more in future.

  • audio_replace
    • Replaces the audio of the generated video with a different audio file. Requires the addition of an additional property, replace_with, containing the location of the specific file you wish to replace the audio with.

Soundfonts

This script requires the use of SoundFont2 (.sf2) files to run correctly. These files are like virtual instruments that are used in conjunction with a generated MIDI file to create an audio track. There are a number of free soundfonts that are easily available online - simply Google "Free soundfonts" and you should be able to find a fair few. The files will have to be placed into a single directory, which you can specify the location of in the config file. Check the above section for details.

Notes on Mingus

This project requires use of the Mingus library to work. Unfortunately, there is no official version of Mingus that works in Python 3. Instead, I found a repo of an attempt at translating the library for Python 3, edited it slightly to fit my purposes, and included it wholesale in the scope of this project. As such, I claim no authorship over anything inside the "mingus" folder.

Requirements

MelodyBot relies on several programs outside of Python. The bot will not work without them so it is highly recommended to have these installed if you ever plan on trying to run this bot. In no particular order, they are:

  • ffmpeg
  • LilyPond
  • FluidSynth

All of these are available for free. I may have forgotten something here, if you're having trouble please reach out to me at Fuddlebob@gmail.com

About

Bot that generates short melodies and posts them to Facebook and Twitter.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages