A while back, Bryan posted a program that renders a spoken version of the classic "99 bottles of beer on the wall" using FreeTTS 1.1. Well, Bryan was using lower level (non-JSAPI) FreeTTS API and things have changed in this API a bit with the release of FreeTTS 1.2, so I thought I'd update the source so it will work with 1.2. This little code snippet, when coupled with FreeTTS will indeed sing the whole song, without ever getting tired.
import com.sun.speech.freetts.Voice;
import com.sun.speech.freetts.VoiceManager;
public class BottlesOfBeer {
public static void main(String[] args) {
VoiceManager voiceManager = VoiceManager.getInstance();
Voice voice = voiceManager.getVoice("kevin16");
if (voice == null) {
System.err.println( "Cannot find kevin16");
System.exit(1);
}
voice.allocate();
for (int i = 99; i > 0; i--) {
String verse = i + getBottle(i) + " of beer on the wall, " +
i + getBottle(i) + " of beer. " +
"Take one down, Pass it around, " +
(i - 1) + getBottle(i - 1) + "of beer on the wall.";
voice.speak(verse);
}
voice.speak("Thank you everyone. You've been a great audience. " +
"I'll be here all week!");
/* Clean up and leave.
*/
voice.deallocate();
System.exit(0);
}
public static String getBottle(int numberOfBottles) {
return numberOfBottles != 1 ? " bottles" : " bottle";
}
}
I figured with all those kids heading out to camp this summer with their laptops, they can just fire this up on those bus rides instead of having to sing it themselves.
Oh, and be sure to check out www.99-bottles-of-beer.net for 621 variations of this program in just about every programming language ever written. A most valuable resource.
