Skip to content

Instantly share code, notes, and snippets.

@joseph
Created October 11, 2013 14:04
Show Gist options
  • Save joseph/6935178 to your computer and use it in GitHub Desktop.
Save joseph/6935178 to your computer and use it in GitHub Desktop.
A guileless script for converting Audacity labels to SMIL, with very little configurability.
#!/usr/bin/env ruby
file_path = ARGV.shift
base_name = File.basename(file_path, '.txt')
html_file = base_name+'.html'
sound_file = 'audio/'+base_name+'.mp3'
out = %Q`<?xml version="1.0" encoding="UTF-8"?>
<smil xmlns="http://www.w3.org/ns/SMIL"
xmlns:epub="http://www.idpf.org/2007/ops"
version="3.0"
>
<body>
<seq id="id1"
epub:textref="#{html_file}"
epub:type="bodymatter chapter"
>`
File.open(file_path, 'r').each { |line|
row = line.split(/\s+/)
out << %Q`
<par id="#{row[2]}">
<text src="#{html_file}##{row[2]}" />
<audio src="#{sound_file}" clipBegin="#{row[0]}" clipEnd="#{row[1]}" />
</par>
`
}
out << %Q`
</seq>
</body>
</smil>`
puts out
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment