Wednesday, September 28, 2005

Making the computer sing!

Creating a grammar to produce a random song is hard. I'm guessing AI research PhD hard. But I just want extremely simple ditties to liven up my game. And if I can make insulting ditties about the player - all the better!

A grammar can only produce extremely simple songs - as it's very hard to keep the song about the same thing. You might have a production.


[songs_about] -> love | angels | sausages | wilderbeast


Looks pretty promising right? - WRONG!

The song will change half way through - at one point the singers talking about love then sausages - entertaining - yes but not widely applicable.

Therefore the grammar output needs to have some post processing / don't use a grammar at all - or use a Context Sensitive Grammar (harder to right, not as fast) instead of a Context Free Grammar.

For now I'm going the post-process route. Anyway with these grammars bards could make up songs on the spot - enough songs to draw from and it might even sound okay. The bard could also draw from things he can see - which could be interesting.

I'm very interested in making songs about the players deeds if they're cool enough but the current way I'm making songs won't cut it. Anyway let's see a pre-post-processed song grammar output.

Oh I knew a man and he loved a [lovedthing],
Finer than the big wide sky thought he, it to be,
[lovedthing] oh [lovedthing] was all his eye did see,

[lovedthing] oh [lovedthing] was all his eye did see,
hey hey oh heyyyy,
[lovedthing] oh [lovedthing] was all his eye did see,

Oh I knew a man and he loved a [lovedthing],
Finer than life itself thought he, it to be,
[lovedthing] oh [lovedthing] was all his eye did see


Surely heartfelt and the new global number one. Let's assume I've written some post process code (which I haven't) and let's say it makes the following song:

Oh I knew a man and he loved a cat,
Finer than the big wide sky thought he, it to be,
cat oh cat was all his eye did see,

cat oh cat was all his eye did see,
hey hey oh heyyyy,
cat oh cat was all his eye did see,

Oh I knew a man and he loved a cat,
Finer than life itself thought he, it to be,
cat oh cat was all his eye did see


Currently I have a conversation mark-up code thing - I may produce that rather than plain text. That may make things a little more interesting - it can handle producing stuff like a woman, anorange.

Here's the pretty crude grammar. I actually wrote three of four song grammars but this was the first:


[start] -> [songs]

[more] -> "life itself" | "the big wide sky" | "the deep blue sea" | "gold and silver" |
"his sweet family"

[songs] -> [song1]

[song1] -> [stanza1] "\r\n" [chorus1] "\r\n" [stanza1] |
[stanza2] "\r\n" [chorus1] "\r\n" [stanza2]

[stanza1] -> [line1][line2][line3]
[stanza2] -> [line1][a1line2][line3]

[line1] -> "Oh I knew a man and he loved a [lovedthing],\r\n"
[line2] -> "He loved it more than " [more] ",\r\n"
[a1line2] -> "Finer than " [more] " thought he, it to be,\r\n"
[line3] -> "[lovedthing] oh [lovedthing] was all his eye did see,\r\n"

[chorus1] -> [line3] "hey hey oh heyyyy,\r\n" [line3]


Here I could also have [emotion] -> hate | love ... which would give the song more scope for being random. These are all post process procedures - which I haven't touched. I'd like them to be quite modular.

Of course I also want books, item description, personal histories ... etc

... maybe I should be looking in more fractal stuff. (the linguistics stuff in this article is dodgey in my opinion. You and I understand the sentenced - Bryan bryan-ed his was down to the shops. We can make up words and be very creative in sentences - it's not a strict grammar - have these people ever heard anyone speak?)

Also this link about games for education caught my attention. One of the things in the back of my head is a FF / DQ rpg to teach English. A little like Slime Forest (which is for learning Japanese) but with more puzzles.
Post a Comment