A few more experiments in creative AI

AI music album cover

This is a sequel to a blog post I wrote last year, about the proliferation of free online tools that use AI to produce creative writing and imagery. Since then, I’ve made frequent use of the latter in particular, as it provides a quick and effortless way to obtain customized visuals for blog posts, videos etc. The results can often be strikingly imaginative, as in the above example from Bing Image Creator. The prompt in this case (for reasons that will become obvious in the course of this post) was “artwork for an album cover themed around ancient Egyptian mythology and space warfare“.

Until recently, a notable omission among creative AI tools (at the “free” level, at least) was anything that could produce convincingly realistic musical compositions. You could ask an AI chatbot to “write a song”, but that only gave you the lyrics – you had to compose the music yourself. But fortunately that’s changed now, and there’s at least one really excellent tool that produces impressive results even in the free demo mode – https://aimusic.so/ .

As with an AI image creator, all you have to do is type in a simple prompt and the AI does everything else for you – musical score, lyrics, electronic orchestration and synthesized voice. After a few initial experiments, the first prompt I tried that worked really well was “A symphonic metal song about the pyramids and mythology of ancient Egypt“. After working away for a few minutes, the AI then came back with not one but two different songs (both with the same lyrics). Here’s the first of them:

Pharaoh’s Wrath (1st version)

Musically, I think that’s a very impressive effort – just the balance I wanted between a hard rock sound in some places and a more sophisticated electronic sound in others. The AI-generated lyrics are pretty good too, but as they’re not very easy to make out, here they are in full:

[Verse 1]
Serpent’s hiss; Anubis’ gaze;
Jackals hunt; End of days;
Temple crumbles; Pharaoh’s might;
Horus’ wings in endless flight.

[Chorus]
Scepter falls; Blood-stained kings;
Cursed tombs and deathly rings;
Mortal souls; Gods’ design;
Power divine; Sands of time.

[Verse 2]
Ra’s inferno; Eyes ablaze;
In Isis’ arms; Final praise;
Nile runs red; Fate’s cruel jest;
Pyramid’s heart; No rest.

[Bridge]
Bones turn to dust; Heart weighs;
In Maat’s scale; No escape;
Eternal pain; Undead realm;
Crown and sword; Evil helm.

[Verse 3]
Scarabs crawl; Shadows close;
Ancient lore; Royal foes;
Warlords rise; Slaves of old;
In death’s grasp; Embers cold.

The second version of “Pharaoh’s Wrath” was generally less interesting than the first, but there were a couple of things near the end that I liked: a rather exotic instrumental that actually sounds quite “Egyptian”, and a nice dramatic ending. So here’s just the second half of v2:

Pharaoh’s Wrath (2nd version, ending only)

For a second experiment, I tried a more prescriptive prompt: “A military sci-fi song called Celestial Cyberstrike, male vocals, verses in heavy industrial metal style in D minor, but chorus in E minor in more melodic prog rock style“. I don’t think the result is quite as impressive as “Pharaoh’s Wrath”, but it’s still far better than anything I could do myself. The machine has made a reasonable effort to vary the style between the verse and chorus – and, judging by what my trusty ChordAI mobile app says, it pulled off the change of key too. Here’s the result:

Celestial Cyberstrike

And for completeness, here are the lyrics:

[Verse 1]
Battle cries echo through the void
Programmed rage soldiers deploy
Brutal code hearts are hollow joys
Man and machine nothing to destroy

[Chorus]
Hear the stars lament and cry
In the void our fate we tie
Reach out through the dark divide
Together we move collide

[Verse 2]
Gunfire dances digital reaper
Destruction codes sinking deeper
Lost souls ride this endless sleeper
In the void no dream’s a keeper

[Bridge]
Silent echoes tear the night
Distant fires burning bright
Underneath the cold starlight
Courage finds its moment’s flight

[Verse 3]
Chaos reigns in circuits twisted
Every step by fate enlisted
We are broken dreams resisted
In the void where hope persisted

New book out now – The Science of Music

The Science of Music

My 5th and latest contribution to the “Hot Science” series from Icon Books has just been published, The Science of Music: How Technology has Shaped the Evolution of an Artform. This is a book I’ve written about a couple of times previously (here and here) – but not to be confused with The Science of Sci-Fi Music, which is a completely different book that I wrote a few years ago!

Here is the publisher’s blurb for the new book:

How can music – an artform – have anything to do with science? Yet there are myriad ways in which the two are intertwined, from the basics of music theory and the design of instruments to hi-fi systems and how the brain processes music. Science writer Andrew May traces the surprising connections between science and music, from the theory of sound waves to the way musicians use mathematical algorithms to create music. The most obvious impact of science on music can be seen in the way electronic technology has revolutionised how we create, record and listen to music. Technology has also provided new insights into the effects that different music has on the brain, to the extent that some algorithms can now predict our reactions with uncanny accuracy, which raises a worrying question: how long will it be before AI can create music on a par with humans?

Science of Music playlist

Science of Music videos

My new book The Science of Music will be published by Icon Books on 16 March 2023. I’ve already alluded to some of the musical works used as examples in the book (in this post from last year) and there’s a fuller “playlist” in the back of the book – running in chronological order from Mozart’s Dissonance Quartet and Beethoven’s Battle Symphony to Miss Anthropocene by Grimes and Djesse vol. 3 by Jacob Collier.

On a more self-indulgent note, I’ve created another short playlist on YouTube of compositions I wrote myself while trying to get my head round some of the techniques discussed in the book – particularly algorithmic (i.e. computer-assisted) composition and electronic music production using a DAW (Digital Audio Workstation). Here is a link to it:

Out Now: The Science of Sci-Fi Music

The Science of Sci-Fi Music

My latest book has just been published! It’s my fourth contribution to the “Science and Fiction” series from Springer, following on from Pseudoscience and Science Fiction (2017), Rockets and Ray Guns (2018) and Fake Physics (2019). This one is called The Science of Sci-Fi Music, and here’s the back-cover blurb:

The 20th century saw radical changes in the way serious music is composed and produced, including the advent of electronic instruments and novel compositional methods such as serialism and stochastic music. Unlike previous artistic revolutions, this one took its cues from the world of science.

Creating electronic sounds, in the early days, required a well-equipped laboratory and an understanding of acoustic theory. Composition became increasingly “algorithmic”, with many composers embracing the mathematics of set theory. The result was some of the most intellectually challenging music ever written – yet also some of the best known, thanks to its rapid assimilation into sci-fi movies and TV shows, from the electronic scores of Forbidden Planet and Dr Who to the other-worldly sounds of 2001: A Space Odyssey.

This book takes a close look at the science behind “science fiction” music, as well as exploring the way sci-fi imagery found its way into the work of musicians like Sun Ra and David Bowie, and how music influenced the science fiction writings of Philip K. Dick and others.

The Science of Sci-Fi Music is available from all the usual places, such as Amazon.com or Amazon UK, either as a paperback or an ebook.

To give a flavour of the contents, here’s a link to a short video preview of the book:

Algorithmic Beatles

Markov music matrix

When Eric Morecambe mangled Grieg’s Piano Concerto on a TV special in 1971, he insisted he was “playing all the right notes, but not necessarily in the right order”. That’s a valid point, because there aren’t that many different notes on a piano and the only thing that distinguishes one tune from another is the order in which you play them.

To a mathematician or computer programmer the situation is crying out for quantitative analysis. The diagram above shows the “transition matrix” for one specific Beatles tune (using the MIDI standard where middle C is C5). It’s clear there’s a lot of order here. One thing that jumps out is that there’s only one “black” note, G#5, and it’s always followed by A5. In fact A5 is a very popular note, cropping up after no fewer than 8 different pitches. On the other hand, G#5 itself is very rare, only ever coming after D6, and then only 6% of the time.

As well as analysing the original tune, this allows us to write a new tune of our own using the same transition matrix. The result (as the aforementioned mathematicians and computer programmers will recognize) is a first-order Markov chain. Producing an algorithm of this type from scratch would be rather tedious (as indeed the initial analysis would be), but fortunately there’s some free software called OpenMusic which includes built-in Markov functions that make the process much simpler.

Of course, there’s more to a tune than the pitch of the notes – there’s the duration of a note too. But that can be analysed and reproduced by exactly the same method. I experimented with an algorithmic composition of my own, based on the Beatles song analysed above. As a first step, I used the OpenMusic Markov functions to generate a series of tune-fragments for both the “right hand” and “left hand” of the piano. Then, to give the composition some structure, I arranged the fragments in a rough approximation to classical sonata form.

I won’t say what the original song was, because I want to see if anyone can guess it. As a hint, I’ve inserted a brief quotation from the original at the mid-point of the piece. Here it is on YouTube: