Serious audio processing on the command line

I’ve written previously about extracting and processing mp3 files from web pages. The use case that I described, obtaining Russian word pronunciations for Anki cards is basically the same although I’m now obtaining many of my words from Forvo. However, Forvo doesn’t seem to apply any audio dynamic range processing or normalization to the audio files. While many of the pronunciation mp3’s are excellent as-is, some need post-processing chiefly because the amplitude is too low. However, being lazy by nature, I set out to find a way of improving the audio quality automatically before I insert the mp3 file into my new vocabulary cards.

As before, the workflow depends heavily on Hazel to identify and process files coming out of Forvo. The download button on their website, sends the mp3 files to the Downloads directory. The first rule in the workflow just grabs downloaded mp3 files and moves them to ~/Documents/mp3 so that I can work on them directly there.

Another Hazel rule renames the verbosely-titled files to just the single Russian word being pronounced. It’s just neater that way.

rename 's/(pronunciation_ru_)(.*)/$2/' *.mp3

This uses the convenient rename command that you can obtain via Homebrew.

The final rule, grabs the newly-renamed mp3 file and performs a series of audio processing steps:

ffmpeg -i "$1" tmp.wav;
sox tmp.wav temp_out.wav norm gain compand 0.02,0.20 5:-60,-40,-10 -5 -90 0.1;
ffmpeg -i temp_out.wav -codec:a libmp3lame -qscale:a 2 tmp.mp3;
lame --mp3input -b 64 --resample 22.50 tmp.mp3 tmp;
mv tmp "$1";
rm tmp.mp3;
rm tmp.wav;
rm temp_out.wav

The first line ffmpeg -i "$1" tmp.wav; simply writes a temporary .wav file that we can process using sox. The second line invokes sox with a number of options that normalize and improve the dynamic range of the audio. Finally we use ffmpeg to convert the .wav file back to .mp3, compress the .mp3 file and then clean up.

Now I have excellent normalized audio for my cards, with no work for me!

See also:

Foreign language education in the U.S.: a neglected cure for xenophobia

Xenophobia has deep roots in the U.S. For all of its “global melting pot” rhetoric, the reality has been much more complex. It begins with the maltreatment of the native peoples of America with its attendant extinction of their language and culture. But even as recently as 1923, the U.S. Supreme Court ruled that persons from India were not eligible for U.S. citizenship because only “free white persons” were permitted. This case was one of the most egregious in the history of the United States and is a poignant example of how the Supreme Court reflects, rather than transcends, prevailing cultural values. In the United States v. Bhagat Singh Thind, 261 U.S. 204, the Supreme Court unanimously decided that an Indian Sikh man could not be granted citizenship because he was not white. Even today, the suspicion with which many English-speaking Americans view Spanish speakers undoubtedly contributes to their xenophobic calls to build a wall along the border with Mexico.

Language and culture are inextricably linked. We use spoken and written language to pass cultural values among one another and from one generation to another. Small wonder that imperialists throughout time have first sought to rid colonies of their native language. But perhaps it’s also true that by purposefully teaching languages, the U.S. will begin to see itself as a global participant rather than a global boss. The Latin origins of the word “educate” imply a process of leading out, drawing out, or leading away. Seen in this way, education isn’t a preparation solely to become part of an economic engine. It is to lead away from entrenched provincial ideas to a broader world view. Language education is a key component of this process.

Language education in the U.S.

Foreign language education in the U.S. is, to be blunt, deplorable. Owing to its fragmentary leadership structure, there are no national standards for education in the U.S. Local school districts, large and small are left to their own devices in writing curriculum standards. In many cases, individual states have specific standards to which local districts must adhere. But even those standards often derided by local politicians.

The effectiveness of a process can be judged by its outcomes. The desired outcome of foreign language education is fluency in the target language. In the U.S., less than 1% of Americans are fluent in a language that they studied in school.^[America’s Lacking Language Skills, The Atlantic, May 10, 2015. Friedman, A. Link] According to Stephen Dubner of “Freakonomics” fame, the average U.S. student studies a foreign language for 2-3 years.^[Is Learning a Foreign Language Really Worth It?, Freakonomics blog, March 5, 2014. Link] It’s hard to imagine anything more wasteful for children’s developing brains to spend hundreds of hours studying something they will never actually be able to apply in a meaningful way. Education budget cuts, lack of qualified teachers, and disjointed policy all contribute to poor foreign language acquisition by U.S. students. And that, in turn, heightens the perception that knowing English is sufficient to participate in the affairs of the world.

Language education worldwide

In contrast to the U.S. public education, the competent acquisition of a foreign language is required. Most European countries require the study of two foreign languages from an early age.^[Learning a foreign language a ‘must’ in Europe, not so in America, Devlin, K.,Pew Research Center, July 13, 2015, Link]

In this study from the Pew Research Center, nearly three-quarters of European countries require the study of not just one foreign language, but two languages. Instead, the U.S. is a crazy-quilt of state and local foreign language requirements. Some states are even allowing students to substitute computer languages for foreign languages to meet this requirement. I’m sure this will help them enormously during their vacations in Computerland!

Another striking observation about language education in Europe is that it begins early, far earlier than the U.S. where most foreign language education takes place in high school. The delayed exposure to foreign languages for most U.S. students has two devastating effects. Drawing on what is known about the acquisition of musical ability, another aural skill, students who first encounter a foreign language late in their education are less likely to become fluent because certain features of brain plasticity decline. A more insidious effect of delayed foreign language study is that students become more and more rooted in their own cultures. Their world view becomes more and more fossilized. This, of course, is the start of a vicious cycle. Their poor foreign language experience means that they won’t support improvements for the next generation.

Solutions

Foreign language acquisition is a must. Political rallies, calls to Make America Great Againâ„¢, walls, immigration bans and disparaging foreign nations won’t solve looming worldwide crises like climate change. But being able to understand and communicate with one another might.

  1. First, the U.S. needs to “prime the pump” by recruiting and developing qualified teachers who speak foreign languages competently. The U.S. already has an agency, the National Security Education Program (NSEP) a Federal initiative whose aim is to build the pool of U.S. citizens who fluently speak languages that are vital to its security interests.
  2. The U.S. Federal government should develop and promote a plan for compulsory foreign language education beginning in the early elementary years.
  3. The U.S. foreign language educational plan should develop a language prioritization based on the languages spoken by its own citizens and residents and on the languages spoken by both its adversaries and allies. The NSEP has developed just such a list of languages of strategic security importance.
  4. The U.S. should develop a plan for evaluating the effectiveness of foreign language education, holding school systems accountable for ensuring that each student is developing language fluency.

On a personal note, I was educated in the U.S. My first exposure to a language other than English was Latin which I studied for two years beginning in Grade 9. I went on to study French and Russian in high school with an amazing teacher Mme Collette Males to whom I’ve indescribably indebted. Had I not had this experience, I’m not quite sure where I would be.