Message Boards Message Boards

Building a Karaoke machine with Mathematica 9

Posted 11 years ago
Here is a fun function which uses the 'new in 9' MIDI import functionality:

 KaraokeMachine[songFile_] := Module[{lyrics, song, textEvents},
    lyrics = Import[songFile, "Metadata"];
    song = Import[songFile];
    textEvents = Cases[lyrics, {time_, "TextEvent" -> text_}, 2];
    textEvents = Select[textEvents, Not[StringMatchQ[#[[2, 2]], "\\@*"]] &];
    textEvents = Map[{#[[1]], "TextEvent" -> StringReplace[#[[2, 2]], {"\\" -> "\n\n", "/" -> "\n"}]} &, textEvents];
    Map[(displayEvent[#] = Black) &, textEvents];
    Print@With[{t = textEvents}, Dynamic[Row[With[{x = #}, Style[x[[2, 2]], displayEvent[x]]] & /@ t]]];
   With[{x = #},
      RunScheduledTask[ Unevaluated[displayEvent[x] = {Red, FontSize -> 16}], {x[[1]]}];
      RunScheduledTask[ Unevaluated[displayEvent[x] = Black], {x[[1]] + 1.0}]] & /@

That's it. And then you're ready to start having fun with Karaoke!


 (midi file can be downloaded from

Also many more karaoke files here:
POSTED BY: Arnoud Buzing
5 Replies
POSTED BY: Frank Scherbaum
Most awesome!
POSTED BY: Michael Sollami
This is super cool! Mad props.
POSTED BY: Kyle Keane
Well, my evening passed triumphantly under ABBA’s "Winner Takes All". This is such a neat idea, Arnoud. It worked well on my Windows 7 laptop. I was amused that Import works with .kar file format. I wonder if it would be difficult to come up with an interface allowing to pause songs.
POSTED BY: Vitaliy Kaurov
If you hear bad sound glitches on a Mac, then this is due to Apple's current MIDI implementation in Java.

A simple standalone case reproduces this problem outside of Mathematica, is described here:

Update: The issue of sound glitches on Mac appears to be addressed in Java 7 (which is not yet the default on Mac OS X).
POSTED BY: Arnoud Buzing
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract