Posts Tagged MacInTalk

I subjected Haiku Detector to some serious stress-testing with a 29MB text file (that’s 671481 sentences, containing 16810 haiku, of which some are intentional) a few days ago, and kept finding more things that needed fixing or could do with improvement. A few days in a nerdsniped daze later, I have a new version, and some interesting tidbits about the way Mac speech synthesis pronounces things. Here’s some of what I did:

Tweaked the user interface a bit, partly to improve responsiveness after 10000 or so haiku have been found.

Made the list of haiku stay scrolled to the bottom so you can see the new ones as they’re found.

Added a progress bar instead of the spinner that was there before.

Fixed a memory issue.

Changed a setting so it should work in Mac OS X 10.6, as I said here it would, but I didn’t have a 10.6 system to test it on, and it turns out it does not run on one. I think 10.7 (Lion) is the lowest version it will run on.

Added some example text on startup so that it’s easier to know what to do.

Made it a Developer ID signed application, because now that I have a bit more time to do Mac development (since I don’t have a day job; would you like to hire me?), it was worth signing up to the paid Mac Developer Program again. Once I get an icon for Haiku Detector, I’ll put it on the app store.

Fixed a few bugs and made a few other changes relating to how syllables are counted, which lines certain punctuation goes on, and which things are counted as haiku.

That last item is more difficult than you’d think, because the Mac speech synthesis engine (which I use to count syllables for Haiku Detector) is very clever, and pronounces words differently depending on context and punctuation. Going through words until the right number of syllables for a given line of the haiku are reached can produce different results depending on which punctuation you keep, and a sentence or group of sentences which is pronounced with 17 syllables as a whole might not have words in it which add up to 17 syllables, or it might, but only if you keep a given punctuation mark at the start of one line or the end of the previous. There are therefore many cases where the speech synthesis says the syllable count of each line is wrong but the sum of the words is correct, or vice versa, and I had to make some decisions on which of those to keep. I’ve made better decisions in this version than the last one, but I may well change things in the next version if it gives better results.

Here are some interesting examples of words which are pronounced differently depending on punctuation or context:

ooohh

Pronounced with one syllable, as you would expect

ooohh.

Pronounced with one syllable, as you would expect

ooohh..

Spelled out (Oh oh oh aitch aitch)

ooohh…

Pronounced with one syllable, as you would expect

H H

Pronounced aitch aitch

H H H

Pronounced aitch aitch aitch

H H H H H H H H

Pronounced aitch aitch aitch

Da-da-de-de-da

Pronounced with five syllables, roughly as you would expect

Da-da-de-de-da-

Pronounced dee-ay-dash-di-dash-di-dash-di-dash-di-dash. The dashes are pronounced for anything with hyphens in it that also ends in a hyphen, despite the fact that when splitting Da-da-de-de-da-de-da-de-da-de-da-de-da-da-de-da-da into a haiku, it’s correct punctuation to leave the hyphen at the end of the line:

Da-da-de-de-da-
de-da-de-da-de-da-de-
da-da-de-da-da

Though in a different context, where – is a minus sign, and meant to be pronounced, it might need to go at the start of the next line. Greater-than and less-than signs have the same ambiguity, as they are not pronounced when they surround a single word as in an html tag, but are if they are unmatched or surround multiple words separated by spaces. Incidentally, surrounding da-da in angle brackets causes the dash to be pronounced where it otherwise wouldn’t be.

Pronounced you es, unless in a capitalised sentence such as ‘TAKE US AWAY’, where it’s pronounced ‘us’

I also discovered what I’m pretty sure is a bug, and I’ve reported it to Apple. If two carriage returns (not newlines) are followed by any integer, then a dot, then a space, the number is pronounced ‘zero’ no matter what it is. You can try it with this file; download the file, open it in TextEdit, select the entire text of the file, then go to the Edit menu, Speech submenu, and choose ‘Start Speaking’. Quite a few haiku were missed or spuriously found due to that bug, but I happened to find it when trimming out harmless whitespace.

Apart from that bug, it’s all very clever. Note how even without the correct punctuation, it pronounces the ‘dr’s and ‘st’s in this sentence correctly:

the dr who lives on rodeo dr who is better than the dr I met on the st john’s st turnpike

However, it pronounces the second ‘st’ as ‘saint’ in the following:

the dr who lives on rodeo dr who is better than the dr I met in the st john’s st john

This is not just because it knows there is a saint called John; strangely enough, it also gets this one wrong:

the dr who lives on rodeo dr who is better than the dr I met in the st john’s st park

I could play with this all day, or all night, and indeed I have for the last couple of days, but now it’s your turn. Download the new Haiku Detector and paste your favourite novels, theses, holy texts or discussion threads into it.

If you don’t have a Mac, you’ll have to make do with a few more haiku from the New Scientist special issue on the brain which I mentioned in the last post:

Being a baby
is like paying attention
with most of our brain.

But that doesn’t mean
there isn’t a sex difference
in the brain,” he says.

They may even be
a different kind of cell that
just looks similar.

It is easy to
see how the mind and the brain
became equated.

We like to think of
ourselves as rational and
logical creatures.

It didn’t seem to
matter that the content of
these dreams was obtuse.

I’d like to thank the people of the xkcd Timediscussion thread for writing so much in so many strange ways, and especially Sciscitor for exporting the entire thread as text. It was the test data set that kept on giving.

I originally wrote Haiku Detector because my friend Gry saw Times Haiku and wondered whether there were any haiku in her Ph. D. thesis. The other day I heard back about the haiku she found. It turns out that even the title of the thesis is a haiku:

Developments for
studies of the extremes of
nuclear matter

Here’s another one, which could be about anything. The last line is a bit of an anticlimax.

As of today, the
origin of this strength is
not well understood.

When I read this one, I wondered if miniball was a mini-golf style version of another ball game:

At HIE-ISOLDE
the MINIBALL would be used
for the same purpose.

The impurities
of 48,50Ti
are easily seen.

After seeing these, I sent her the as-yet-unreleased new version of Haiku Detector, which can detect haiku made up of several sentences. Having mostly had my name on papers authored by the entire CMS collaboration, I expected her to find a lot of haiku in the author list. But ISOLDE is much smaller, and also this is her thesis that she wrote, not some paper whose author list she got tacked onto. So she got some from references:

Kitatani, S.
Goko, H. Toyokawa,
K. Yamada, T.

C 47,
537
(1993).

and some things with section numbers tacked on:

2.1.1
Open shell nuclei and
collective models

This matrix is the
starting point for the Oslo
method. 45

That last one has so many possibilities. I like to think of it as being about an electronic band called The Oslo Method which released a 45rpm record about The Matrix. Unfortunately, nobody can be told what the haiku is. You have to see it for yourself. And indeed, you can see the other haiku she found on the #MyHaikuThesis tag on Twitter.

I noticed something interesting while writing this post — some of the ‘haiku’ Gry found include gamma (γ) symbols:

Haiku Detector on her Mac has treated them as having zero syllables, as if they are not pronounced, and I think I recall characters like that not being pronounced in the Princeton Companion to Mathematics. But I just checked on my Mac running Mac OS X Yosemite, and the speech synthesis (which Haiku Detector relies on for syllable counting) pronounces γ as ‘Greek small letter gamma’, so Haiku Detector does not find those erroneous haiku. I think that this might be a new feature in Yosemite.

But here’s where it gets weird: you’d think that it’s just reading ‘Greek small letter gamma’ because that’s the unicode name of the character. I tried with a few emoji and other special characters, and that hypothesis is upheld. But the unicode character named ‘chicken’ (🐔) is pronounced ‘chicken head’. Spooky. Another strange thing is that there is no unicode ‘duck’ character.

If you’ve beenpayingattention, you probably know why I happened to come across those oddities. I’ll have to investigate them later, though; right now I’m in Edinburgh for NSScotland, and it’s about time I looked at some tourism information.

So, Haiku Detector; what now? Maybe look for supersymmetric haiku?

Update: It seems that in Mac OS X 10.8, γ is not pronounced, and 🐔 is pronounced ‘chicken emoji’. Other emoji also have ’emoji’ in their pronunciations, while still others are not pronounced. I wonder if pronunciations were added (and later edited to remove the ’emoji’) for certain emoji, and now the default pronunciation has changed from nothing to the unicode name. So ‘🐔’ ended up with the explicit pronunciation ‘chicken head’ while others which were not previously pronounced use their unicode names. So this should be a haiku in Yosemite, though for some reason Haiku Detector does not detect it:

Back in late February, my friend Alice sent an email asking people to cover The Doubleclicks’ Nerdy Birthday Song for Sara Chicazul, who had a birthday on JoCo Cruise Crazy 2 but not on JoCo Cruise Crazy 3. The idea was to put up one per day, so that she could experience the thrill and horror (previously reserved for Mike Phirman) of having a birthday every day. A lot of people did. I don’t usually sing anything more melodic than Chicken Monkey Duck when people can hear me, so I figured I’d dust off my robot choir (a little program I wrote to take text and a tune played on my MIDI keyboard, and turn it into TUNE commands to make the built-in Mac speech synthesis sing) and record a cover that way. It took a fair bit of dusting off, what with a new version of XCode and of the MIDI framework I used, and I think the metaphorical dust mites gave me cold-like symptoms, which is why I haven’t posted anything for a while. Anyway, today I finally recorded a cover, and here it is. Given that the third thing I ever recorded using my robot choir was my Macs singing Happy Birthday to the London Science Museum, I think I may as well rename my robot choir to ‘The Phirmanator’.

This recording starts off with just the Victoria voice singing, then at the first ‘you’re getting older’, Vicki joins in. I have a cameo saying ‘everybody!’ and then Agnes joins in and all three voices get a gospel choir effect. I added Zarvox (an intentionally robotic voice) at the end, partly because I thought it would be funny, and partly because Vicki sounds awful holding that ‘all’ note and I wanted to make up for her being so much quieter in that part. I noticed part of the way through that I’d used the wrong notes in a few places, so I fixed those, but there are probably others. I don’t know how to make music; I just know how to turn MIDI notes into frequencies. Also, I can barely even play my rainstick, let alone a stringed instrument, so it’s a robocoppella. I timed everything to synch up with the original song, and it sounds kind of nice if you play both together. By itself, well… it sounds like autotune became sentient and killed all the human singers.

Feel free to make your own recording of it with human vocals and actual music if you wish. I make no claim of being musical, and I probably accidentally copied the tune from something. Sosumi.

If I can’t have this, then I’ll have that
If I can’t have a dog, I’ll have a cat
If I don’t like today there’s always tomorrow
If I can’t be Superman, I’m Bizarro
If I can’t have coffee I’ll have tea
If I can’t have a pool I’ll have the sea
If I can’t have chocolate, I’ll have cakes
If I can’t have cities, I’ll have lakes
But if I can’t have you there are no good fakes
So I’ll be very sad.

Well you can’t always get what you think that you want
But you can get something that’s just as nice
It is not very likely the thing that you crave
Will be the only thing that will suffice

If I can’t have Mars I’ll take the moon
If I can’t be first I’ll be there soon
If I can’t have shuttles, I’ll have Soyuz
If I can’t fly from you I’ll fly for youse
If I can’t have Skylab I’ll have Mir
If I can’t leave Earth then I’ll stay here
If there’s no zigazig I want all your base
If there’s no E.T. I’ll take the human race
But if I can’t have you there’s an empty space
And I’ll be very sad.

Well you can’t always get what you think that you want
But you can always want what you’ve got
It is not very likely the thing that you crave
Will be the only thing to hit the spot

If I can’t have ATLAS there’s CMS
If I can’t find the Higgs I’ll make another guess
If I can’t prove that, I’ll become a believer
If I can’t go to PAX I won’t be a reaver
If I can’t write songs then I’ll still write Things
and if my voice sounds bad my computer sings
If I can’t have Hexley, I’ll have Tux
If I can’t have a princess, I’ll have ducks
But if I can’t have you then that just sucks
And I’ll be very sad

Well you can’t always get what you think that you want
But you can always rehypothesise
It is not very likely the answer you seek
Is the only one that satisfies

If I can’t have some things I’ll have others
If I can’t have sisters I’ll have brothers
If I can’t have rhythm I’ll have rhyme
If I can’t have space then I’ll have time
If I can’t have proof then I’ll have trust
If I can’t make love then I’ll take lust
If I can’t have lovers, I’ll have nudes
And if I can’t have ladies, I’ll have dudes
But I can’t have you so we’ll have feuds
’cause I am very sad

Well you can’t always get with the person you like
but you can always find someone new
It is not very likely the one that you want
Will be the only one that’s meant for you

Well, they say there are plenty more fish in the sea
Though I don’t think they mean that literally
And while I can’t seem to stop the overfishing
I always can be careful what I’m wishing

‘Cause if I can’t be linked then I’ll be free
If I can’t have you there’s another three
And if I can’t have them then I’ll have me
And you’ll be very sad.
But you can deal with that:
Just find another lad.

Somebody on Twitter mentioned he’d like the file I used to get my Mac to sing Still Alive, so here it is. If you have a Mac, you just need to open this in any application which can view text (TextEdit, for example) go to the Edit menu, Speech submenu, and select ‘Start Speaking’. You can try different voices by changing the system voice in the Speech pane in the System Preferences. For best results, use a high quality voice such as Vicki or Victoria. Alex is supposed to be the highest-quality, but it’s a male voice, and I don’t think I’ve tried it. Voices that already have their own built-in tunes (such as Good News and Bad News) won’t work. You could also create a sound file of it using the ‘Text to Audio File’ Automator action.

It won’t sound exactly like the recording in the video I made, because I edited the resulting sound file in GarageBand to get the timing to match up with the original song. If you want to shortcut all that, or if you don’t use a Mac, you can get your computer to sing (or lip-synch?) Still Alive by downloading this mp3.

This file is released under a PleaseDon’tSueMeValve-Attribution-Noncommercial-ShareAlike license, which is explained in detail in the file itself.

The weirdest thing happened yesterday. I was using Ayu, my as-yet-unnamed MacBook Pro, and suddenly Axis, my old PowerBook G4 booted and started singing Still Alive, the theme to the game Portal. I really should stop naming my Macs; I hear it makes them sentient.

Okay, that’s not really what happened. Actually, a couple of weekends ago, all three of the parties I had been invited to (yeah, I don’t understand how I got this social life either; just believe me) were cancelled or too difficult to get to, so I used my unexpected free time to do something I’d wanted to do for ages: get my Mac to sing Still Alive. You might remember that one weekend way back when I had an excuse to avoid being social, I wrote a parody of Still Alive, and a program to get my Mac to sing it using the TUNE input to the built-in speech synthesiser. Back then, I had to enter the notes and durations to sing one by one, and it was too tedious to do the whole song.

Somebody on YouTube asked where I got the file to make my Macs sing happy birthday to the London Science Museum. I realised I’d forgotten to upload it anywhere. Or perhaps I didn’t think people would be interested, since in general if they wanted their Macs to sing happy birthday, they’d want to customise the name. The software I wrote to do this (and other things) is really still a prototype unintuitively bolted onto an unrelated prototype, with the default CoreData interface, so I’d rather not release it yet. But just in case you do want your Mac to sing happy birthday to the London Science Museum, here’s the file. There are instructions in the file on how to get it to sing.

I also just made this file where you can put the name of your choice instead of the London Science Museum; just search for ‘your name here’ in the file, and change it. It will just speak the name rather than singing it, since to get it to sing it you’d have to figure out how to write the name in MacInTalk phonemes.

Alternatively, if you want to personalise the song while still having the name sung, you could record your Mac singing to a sound file using the ‘Text to Audio File’ Automator action, and then open that in GarageBand and splice in a recording of yourself singing the appropriate name.

Addendum: I just thought of another possibility: you could use the Repeat After Me application (which comes with the developer tools) to get your Mac to sing the name however you do. This is not what I used for the rest of the song, since it’s made with normal speech intonation in mind rather than singing, and it gets quite tedious for anything long, but it is a very cool program and would be great for just recording the name.