Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/bin/bash
#Recover from an Audacity crash by reassembling the saved data files
if [ $# != 2 ]; then
echo "ERROR: Not enough arguments"
echo "$0 [SOURCE PATH] [DESTINATION]"
exit 1
fi
DATA="$1/"
OUT=$2
if [ -e $OUT ]; then
# Hope the path exists
echo "ERROR: Output file exists ($OUT)"
exit 1
fi
COUNT=1
find $DATA -name "*.au" -print0 | while read -d $'\0' FILE ; do
#The offsets are probably all going to be the same, but best check it
OFFSET=$(echo $(od -i -j4 -N4 -An < $FILE) ) # Use echo for easy trim
if [ $COUNT -eq 1 ]; then
# Write the header
dd ibs=$OFFSET count=1 if=$FILE of=$OUT
fi
echo "Adding $FILE (offset=$OFFSET)"
dd ibs=$OFFSET skip=1 conv=notrunc oflag=append if=$FILE of=$OUT
let COUNT+=1
done
echo "Done"
@BleuLlama

This comment has been minimized.

Copy link

@BleuLlama BleuLlama commented Jun 24, 2015

mac doesn't have oflag=append, so i did this instead:

rm -f OOO
dd ibs=$OFFSET skip=1 conv=notrunc if=$FILE of=OOO
cat OOO >> $OUT

Although it was a stereo file, well, dual mono, so I need to still skip every other file in the process. Thanks for this script!

@mofosyne

This comment has been minimized.

Copy link

@mofosyne mofosyne commented Dec 21, 2019

Thanks for the script. Modified to use BleuLlama since I use a mac. Also used if (( ($COUNT % 2) == 1 )); then because I needed to recover a stereo recording and pairs of audio clips represents left and right pair. I only needed to recover at least one half of the channel.

#!/bin/bash
# Recover from an Audacity crash by reassembling the saved data files
# Modified for MacOS and skipping every second file due to stereo recording

if [ $# != 2 ]; then
		echo "ERROR: Not enough arguments"
		echo "$0 [SOURCE PATH] [DESTINATION]"
		exit 1
fi

DATA="$1/"
OUT=$2

if [ -e $OUT ]; then
		# Hope the path exists
		echo "ERROR: Output file exists ($OUT)"
		exit 1
fi

COUNT=1

find $DATA -name "*.au" -print0 | while read -d $'\0' FILE ; do
	#The offsets are probably all going to be the same, but best check it
	OFFSET=$(echo $(od -i -j4 -N4 -An < $FILE) ) # Use echo for easy trim
	if [ $COUNT -eq 1 ]; then
		# Write the header
		dd ibs=$OFFSET count=1 if=$FILE of=$OUT
	fi
	if (( ($COUNT % 2) == 1 )); then
		echo "Adding $FILE (offset=$OFFSET) $COUNT"
		rm -f OOO
		dd ibs=$OFFSET skip=1 conv=notrunc if=$FILE of=OOO
		cat OOO >> $OUT
	fi
	let COUNT+=1
done

echo "Done"
@masongcm

This comment has been minimized.

Copy link

@masongcm masongcm commented Mar 8, 2021

Hi all! Thanks for your work here. Do you know if this would work on a project with multiple tracks?

@jonata

This comment has been minimized.

Copy link

@jonata jonata commented May 13, 2021

Suggestion: in cases where the files are not named in sequence according to time of creation, you can replace this line:

find $DATA -name "*.au" -print0 | while read -d $'\0' FILE ; do

with this:

find $DATA -name "*.au" -printf "%T@ %Tc %p\n" | sort -n | awk '{print $NF}' | while read -d $'\n' FILE ; do

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment