Editing WMA files with Audacity

724

Author: Colin Beckingham

Audacity is a fine open source audio editor, but it cannot currently edit Windows Media Audio (WMA) files. There’s nothing open about either the API or the codec for the Windows Media Audio format, so the Audacity Developer Team is taking its time before attempting to incorporate direct import, editing, and export of these files. But if you have WMA files you need to edit with more precision than Microsoft’s tools allow, Audacity can still help.

Ideally we would simply convert the WMA files to some more convenient codec and get on with the editing. But it is not quite that simple. Some WMA files are copyrighted, in which case there is no way to legally edit them. Additionally there are issues related to loss of quality when converting from one codec to another, and WMA offers a facility called scripting that triggers other events during playback which it might be convenient to retain.

Let’s imagine we have a couple of problems to solve. First, we have to cut one single WMA into separate audio bites, and secondly, we need to bleep out an expletive from one of these bites. Both tasks require that we be very precise about where we cut. The second issue demands more accuracy than the first, since when people speak rapidly the words tend to run together and are pronounced as one sound. In technical terms this running together of words is known as a “lack of phonetic boundaries.” If the phrase is (excuse my language) “those effing things,” what we are really dealing with is “thozeffing things,” and we need to place our millisecond markers accurately to get a really clean “those –bleep– things” as the final product.

Zooming in on the millisecond

Microsoft provides a free utility that has limited editing capability but can usefully crop WMA files and convert standard file types to WMA format. This utility works well for preparing a WMA file suitable for streaming, progressive download, or Pocket PC use, but is inadequate for precise editing from its limited screen.

The problem for accurate editing is that we cannot precisely position the slider bar except by manually entering values including milliseconds. By contrast, the advantage of Audacity is that you can magnify the waveform display and obtain a very accurate point for marking. The following graphic shows a magnification of an MP3 file in Audacity:

Note that the time track is showing in milliseconds, and the magnification icon at the top left is highlighted. This image is from Audacity 1.2.4, the latest stable version. Version 1.3.0, currently in beta, has a new selection bar that makes this editing easier. If you want to try the beta, be aware that it has a few bugs, including one related to clicking the “length” radio button which freezes the application.

We can use Audacity to precisely position the cursor. We first make a copy of the original WMA as a WAV using a utility such as the NCH Swift Audio File Converter or MPlayer and read this into Audacity. We will not actually be editing this file, just using it to determine millisecond time markers. Zooming the waveform (select the magnification icon from the panel at top left and click the waveform repeatedly to get the desired zoom level) allows us to position the cursor very finely, determine the millisecond mark we need, and enter this into the Windows Media Editor.

Solutions

Click to enlarge

Given that we can now find the marker points accurately, we can use Audacity to determine the millisecond values and enter these into the Windows Media Editor. We fix each of the points with the “Seek” button followed by the “Mark In” and “Mark Out” at the beginning and end of the clip. To cut one file into two pieces we use “Mark In” at the beginning of the file and “Mark Out” at our millisecond point determined from Audacity, and save that bite. Then back to the original, seek the “Mark In” where we left off on the previous file and “Mark Out” at the end of the file and save that chunk. Yes, it’s a pain. The advantage of this process is that it is lossless, in the sense that we have not converted the file to another format to achieve any of the goals. It started as a WMA and is still a WMA, and hopefully we have retained the original script points and the original quality, though because the WMA editor is proprietary we have no idea what manipulations were necessary.

The second problem is a bit more complex and requires the interposition of another codec.

The Windows Media Editor is not clever enough to allow us to replace parts of the file, but Audacity can. We can make a copy of the file and convert it from WMA to WAV or MP3 or another codec, bearing in mind that later we will be asking Windows Media Encoding to convert it back to WMA. With the WAV loaded into Audacity we can highlight very carefully, using magnification of the waveform as necessary, the part that offends. A particularly useful feature in Audacity is that if we click and drag in the waveform to highlight one part of the wave and then click the Play button, only the selected portion will be played back. This is useful to make sure we have selected the right part of the file for replacement. Then from the menu, choose Generate, then Tone. When the dialogue window appears, accept the default values and simply click Generate Tone.

That replaces the word with the neutral sound. We can tweak the options to modify the replacement tone, but the defaults are quite acceptable. To avoid a click at the end of the tone-generated section use the cross fade out function four or five times in succession on the very end of the section.

After testing, normalizing, and exporting the revised file from Audacity, use the Windows Media Encoder, or, from a DOS prompt (Command) window after navigating to the encoder folder, issue the command:


cscript.exe wmcmd.vbs -input
C:work...Myfile.wav -output
C:work...Myfile.wma

which gives us the final output in WMA format. There should not be any loss of quality, but we have made two conversions, so there may be some subtle changes.

Here is a copy of a sample WMA file, and a second file after insertion of a sine wave tone using the above procedure to mask the middle section. Readers can judge whether there has been any degradation in quality.

The future of WMA and Audacity

According to Dominic Mazzoni, lead developer of Audacity, it is technically possible to use the API in later versions of Windows to perform the import and export of WMA files in Audacity, and the development team sees it as a good idea for a feature. One potential roadblock is legal: the GPL license that Audacity uses disallows linking to closed source libraries such as the WMA codec that comes with Windows, but makes an exception for libraries that are distributed as part of the operating system. So it may be possible to include WMA support, for example, but only for versions of Windows that contained WMA built-in and not for versions of Windows that require you to obtain WMA support as a separate download.

Much as we would like our world to be limited to open source sound file formats, the fact is that WMA and other proprietary formats are out there and numerous, so the least we can do is find workarounds to deal with them. Audacity sets a high standard, and in this case is able to support and complement the basic WMA editor.