wave fadein, fadeout

Hi all,

I’m using “afplay” to play wave files, but I cannot find any function (or equivalent command) to fadein or fadeout the sound from scripting.
I cannot use an app to play/control the sound (such as iTunes, Quicktime, Vlc or so) but I’d prefer to stick to terminal/applescript commands.
You guys have any idea if this is possible at all?


I made such a script to fade out.

(1)Timer interrupt
You can set sound volume during playing sound with QuickTime Player or alternatives in Cocoa framework.

(2)And iTunes/Music has fade out / fade in function
iTunes/Music.app has fede in / out function (cross fade).

At first, try (2). My solution is (1).

Model: MacBook Pro 2012
AppleScript: 2.7
Browser: Safari 13.0.1
Operating System: macOS 10.14

You would prefer stick to terminal/applescript commands, but there is some limitations with shell commands. For example, you can’t use ignoring application responses block of AppleScript, which is needed in the given case. Why not control Quicktime on the background as here?:

set wavAudio to choose file of type "wav" with prompt "WELCOME TO MODIFIED AFPLAY!

tell application "QuickTime Player"
	open wavAudio
	ignoring application responses
		play document 1
	end ignoring
end tell

-- Gradually increase the volume
repeat with X from 0 to 100
	set volume output volume X
	delay 0.1
end repeat

-- Gradually decrease the volume
repeat with X from 100 to 0 by -1
	set volume output volume X
	delay 0.1
end repeat

Of course, you can save the do shell script “afplay …” as an application and use it instead of QuickTime, but this will be a meaningless replacement.