Well there are many techniques, and of course plain old developing the talent by constant practice and doing... However specific techniques can help us to get started and to stay focused sometimes.
A simple idea is to start with a phrase (the first lyric line, or possibly the hook/chorus), and figure out the rhythm of that phrase. For instance “StevensCat, is so cool” could be interpreted rhythmically as 1+2, 3+4 (“one and two, three and four,” or two beamed 8th notes, a quarter note, then another set of beamed 8ths and a quarter). Then play with the rhythm for a while in your mind or on a keyboard, and see if some rhythmic pattern suggests melody notes to go with it.
Here is another great songwriting trick that I learned from bassist and singer Rodney Appleby, who in turn presented it to me as the brainchild of guitarist Tony Scozzaro. I therefore call it the “Scozzaro Method.” It’s a little more involved than the first.
Look at the grid below. The top line represents the “musical alphabet” (Notes A-G); the rest of the English alphabet is filled in underneath.
A B C D E F G
H I J K L M N
O P Q R S T U
V W X Y Z
The phrase “StevensCat is so cool” (using the coding from the grid above) comes out to the string of musical letters “E F E A E G E—C A F—B E—E A—C A A E.” Those can become melody notes. They can be chord changes. A has to be some kind of A (major, minor, flat, sharp, augmented, diminished, etc.). The string can be shortened by combining repetitive notes=E-F-A-G-C-B. Then create a melody and/or chord changes out of them. In your case, try to fit your lyric line to the notes in-question. Ultimately it’s a song starter, and at some point your creativity takes over. But you could encode an entire phrase, hook, or a girlfriend/wife/favorite horse’s name into music using the template above.
GJ