Building an audio stack for CCHits

I used to process all my audio for CCHits.net on my home machine, but due to some instabilities, I moved to building the audio on an EC2 server. I’ve seen some comments about doing similar things recently, so I decided to document how I build the CCHits shows.
The showmaker script which makes the show is hosted on Gitorious, and is executed by running showmaker.php which in turn loads the library.php file. Showmaker handles interpreting the CLI commands, and the downloading and handling of the data from the server.

The creation of a daily show follows the following steps:

  1. Create the show entry in the MySQL databases using a combination of cURL and PHP.
  2. Use SOX to create silence to prefix the show intro and postfix the show outro.
  3. Build the show and track intro/outro files using Festival.
  4. Convert the intro/outro files into a consistent audio format.
  5. Join the silence files to the intro/outro files with SOX.
  6. Merge the show theme tune to the intro and outro files, again, using SOX
  7. Reformat the track to the consistent audio format.
    1. For WAV, MP3 files or OGG/OGA files, do this with SOX.
    2. For M4A files or AAC files, convert to a WAV file with FAAD, then reformat using SOX.
  8. Use SOXI to get the length of the intro. Put that value into a variable.
  9. Join the intro to the track using Festival.
  10. Use SOXI to get the length of the combined intro+track. Use this and the previously calculated length to build a JSON encoded “running order”.
  11. Join the outro to the combined intro+track using Festival.
  12. Get the length of the show using SOXI.
  13. Convert the show to it’s output formats, then tag it.
    1. Output to MP3 using SOX, then tag and add artwork using eyeD3.
    2. Output to OGA using SOX, then tag and add artwork using vorbiscomment.
    3. Output to M4A using FAAC then tag using mp4tags and add artwork using mp4art. Add chapters to this file using mp4chaps.
  14. Get an MD5 hash of each of the files, using md5sum. JSON encode the array of these hashes.
  15. Update the database with the MD5 hash, the total length of the file and the running order, using cURL.

So, here are the tools, where to get them from, and how to use them.

  • SOX/SOXI (Various sound conversion and manipulation)
    • Sources: http://sourceforge.net/projects/sox/files/sox/
    • Uses:
      • Create silence:
        sox -n -r 44100 -c 2 output.wav trim 0.0 $LENGTH
      • Join two tracks:
        sox --combine concatenate input1.wav input2.wav output.wav
      • Merge two tracks:
        sox -m input1.wav input2.wav output.wav
      • Reverse a track:
        sox input.wav output.wav reverse
      • Set formatting of the track to 44.1k, 2 channel WAV:
        sox input.mp3 -r 44100 -c 2 output.wav
      • Get the length of a track:
        soxi -d input.wav
      • Trim all the silence off both ends of a track and save it as a normalized, 44.1k, 2 channel flac file (note the special options here are “-t sox -” as this means, use the internal sox format and pipe it from one command to the next):
        sox infile.mp3 --norm -r 44100 -t sox - silence 1 0.1 1% reverse | sox -t sox - outfile.flac silence 1 0.1 1% reverse
  • Festival (For text to speech)
    • Sources: I’d like to have provided links to how to build this, but frankly, not being able to build this changed this from a “how to build and use these tools” into “how to use these tools”. Get it from your distribution of choice. Don’t build it from source.
    • I only use Sable files for generating text-to-speech wave files. For more details on Sable, see http://www.cstr.ed.ac.uk/projects/festival/manual/festival_10.html.
      Use:

      text2wave -o output.wav input.sable
  • FAAD(AAC decoder)
  • eyeD3 (ID3 tagger)
    • Source: http://eyed3.nicfit.net/releases/
    • Use:
      eyeD3 --artist="Artist Name" --title="Track Title" --album="Album Name" --add-image "coverart.png":FRONT_COVER output.mp3
  • vorbis-tools (for vorbiscomment)
    • Source: http://downloads.xiph.org/releases/vorbis/
    • Use:
      vorbiscomment -t "Artist=Artist Name" -t "Title=Track Title" -t "Album=Album Name" output.ogg

      To embed coverart in this file, you need to base64 encode the file first, and then add that, as follows:

      vorbiscomment -t "METADATA_BLOCK_PICTURE=`base64 --wrap=0 coverart.png`" -t "COVERARTMIME=image/png" output.ogg
  • FAAC (AAC encoder)
  • mp4v2 (for mp4chaps, mp4tags and mp4art)
    • Source: http://code.google.com/p/mp4v2/
    • Use:
      • mp4chaps:
        FILENAME="`basename output.mp4 .mp4`" && echo "00:00:00.000 intro" > ${FILENAME}.chapters.txt && echo "00:03:00.000 track" >> ${FILENAME}.chapters.txt && mp4chaps -r input.mp4 && mp4chaps -i output.mp4
      • mp4tags:
        mp4tags -a "Artist Name" -s "Track Title" -A "Album Name" output.mp4
      • mp4art:
        mp4art --add coverart.png output.mp4

JonTheNiceGuy

He/Him. Husband and father. Linux advocating geek. Co-Host on the AdminAdmin Podcast, occasional conference speaker.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.