Here's version 1 of some Twine macros to play sound files with HTML5 audio.
http://www.glorioustrainwrecks.com/files/TwineMacros-SoundMacros-1.0.0.txt
These macros accept either strings or string variables as their first argument. I recommend you set the filenames to specific variables and then use those as arguments to the macros.
<<playsound "carolofthebells.mp3" >>
plays the file "carolofthebells.mp3" from the start.
<<loopsound $heartbeat >>
starts playing $heartbeat from the start, over and over. Note: currently browsers are not that good at looping audio seamlessly - brief silences between loops may occur.
<<unloopsound $heartbeat >>
makes $heartbeat no longer repeat when it finishes.
<<stopsound "birds.ogg" >>
stops playing "birds.ogg"
<<pausesound "trees.ogg" >>
pauses "trees.ogg" at its current location.
<<stopallsound>>
stops all the sounds.
Important instructions:
There's a lot that can be done to expand on this. Something I intend to add is a way to bind looping sounds to a specific passage tag. So, you could perhaps write <<tagsoundloop "trees" "Howling_Monkeys.mp3">> and then give a passage a tag of "trees", and it will keep looping "Howling_Monkeys.mp3" if you're at such a passage, and stop it when you leave. That will come later. Also on the list of possibilities: fading sounds in and out when they're stopped, and support for base64-encoded sounds (which no one except me will ever use).
Version history:
Attachment | Size |
---|---|
TwineMacros-SoundMacros-1.0.0.txt | 1.85 KB |