Automate iTunes for chorus repetitions of L2 pronunciation practice

N.B. This script has been updated to work with the new Music app on macOS 10.15 Catalina. 2020-07-04.

That title is a mouthful!

TL;DR: One approach to developing good second language pronunciation and rhythm is to repeat a sentence many times while simultaneously listening to a native speaker. If you do this while gradually reducing the source amplitude, you will be speaking on your own without help. This is an AppleScript that automates this process on the Mac platform.

Background

For adult learners of a second language (L2), pronunciation and prosody (the rhythm and cadence of language) can be difficult. A method devised by Swedish linguist and medical doctor Olle Kjellin seeks to remedy this problem by applying a method of chorus repetitions of sentence in the L2. While listening to the sentence over and over, the learner repeats the same sentence aloud, attempting to match the native speaker’s pronunciation and cadence. By gradually reducing the volume of the native speaker, the learner gradually hears more of his own voice. This shaping process has sound neurocognitive underpinnings and Kjellin’s explanation of the method is definitely worth reading.

Automating the process

One of the ideas that Kjellin discusses is gradual reduction in the native speaker’s volume. That rationale is that as the learner begins to hear less of the native speaker’s voice, he begins to hear more of his own. In this way, he learns to shape his pronunciation and developing prosody while the auditory stimulus is gradually withdrawn.

It is possible to do this automatically on the Mac plattorm.^[Sorry Windows and Linux users, this approach relies on AppleScript which of course doesn’t run on these other platforms. Almost certainly there are platform-specific approaches there but that’s for someone else to figure out!] For this approach, I use AppleScript to ask the user for the intended track duration in minutes and then it begins playing the current track, gradually reducing the volume over the course of the desired duration. To simplify the choices the user must make, the script only asks for the duration. The minimum volume is hard-coded as is the linear shape of the decay. With a little ingenuity, these choices could be modified. For example, the volume decay could be faster, leaving some of the remaining time at the minimum volume.^[Currently when the minimum volume is finally reached, playback stops.]

Installing

You’ll need to grab the source code from Github and paste it into a new empty script in AppleScript Editor.app.^[You have it, it’s just hard to find. Look in /Applications/Utilities.] From AppleScript Editor, you need to save it to the iTunes script directory which is located at ~/Library/Library/Scripts/Applications/iTunes.^[You can access the iTunes scripts folder from the scripts menu when iTunes is the frontmost application by going to the scripts menu > Open Scripts Folder > Open iTunes Scripts Folder. That’s where you need to save the script.] Sorry this is a little cumbersome but I can help you. Just send me a note via contact page.

Source code

For the intrepid and the techies, here’s the source code for you:

--
--  Created by: Alan Duncan
--  Created on: 2018-01-11
--
--  Copyright (c) 2018 OjisanSeiuchi
--  All Rights Reserved
--

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

property minimumVolume : 10

--  initial volume, set by user
global volume0, trackRepeatMode0

on run
	set trackDuration to the text returned of (display dialog "Minutes to play track?" default answer "5")
	tell application "iTunes"
		set volume0 to sound volume
		set trackRepeatMode0 to song repeat

		-- probe to see that we have a track selected
		try
			set t to the current track
		on error errMsg number errNum
			if errNum is -1728 then
				display dialog "Please select a track first"
			else
				display dialog "Unable to begin playback"
			end if
			return
		end try

		-- set track repeat 1
		set song repeat to one
		-- begin playing track
		set player position to 0
		play

		-- calculate the delay between fades
		set fadeDelay to (trackDuration * 60) / (volume0 - minimumVolume)
		repeat with i from minimumVolume to volume0
			delay fadeDelay
			set sound volume to (sound volume) - 1
		end repeat

		-- stop playing
		pause
		set player position to 0

		-- restore iTunes settings
		set sound volume to volume0
		set song repeat to trackRepeatMode0

		quit me
	end tell
end run

I’ve found chorus repetitions to be an excellent way of honing one’s pronunciation and prosody in L2 practice and I hope this approach of automating the process is helpful.