Merging .au files without the project file

Questions, discussion and recipes for scripting and batch processing in Audacity.
See also the "Scripting" section of the Audacity manual.
Forum rules
If you require help using Audacity, please post on the forum board relevant to your operating system:
Windows
Mac OS X
GNU/Linux and Unix-like
Post Reply
yannik131
Posts: 8
Joined: Sun May 26, 2019 4:35 pm
Operating System: Windows 10

Merging .au files without the project file

Post by yannik131 » Mon Jul 22, 2019 7:28 pm

Hello,

I have a bunch of .au-files linked to an Audacity project, but I don't have the project file itself. Luckily, the files can be sorted by creation date (the left and right mono files are created at the same time as a pair, I guess). I wrote a python script to rename the files according to their creation date, let Audacity convert them to mp3, then used ffmpeg -filter_complex amix=inputs=2:duration=longest to merge the two monos into one and then ffmpeg -i "concat:..|..|.." to append them all to one file. You can hear distinct cut-noises after each file, though. Any tips on how to do this right?

kozikowski
Forum Staff
Posts: 69384
Joined: Thu Aug 02, 2007 5:57 pm
Operating System: macOS 10.13 High Sierra

Re: Merging .au files without the project file

Post by kozikowski » Mon Jul 22, 2019 8:04 pm

You can hear distinct cut-noises after each file, though.
You mean after each 6-second snippet? That could be your process getting the Left and Right wrong way around.
Audacity convert them to mp3,
Never use MP3 anywhere in a production process. It creates sound damage and has badly defined stop and start points. Try WAV 16-bit 44100.
I wrote a python script
What's the possibility of publishing that script?

Koz

yannik131
Posts: 8
Joined: Sun May 26, 2019 4:35 pm
Operating System: Windows 10

Re: Merging .au files without the project file

Post by yannik131 » Mon Jul 22, 2019 9:59 pm

Yeah, using a different format did solve the problem. ffmpeg doesn't support concatenating wav files though, so I converted au to mpeg (2x mono) to mpeg (1x mono) to mp3. That works okay. Here's the code:

Code: Select all

import os
from tkinter import filedialog
import subprocess

ffmpegPath = input("Where is ffmpeg.exe located? Press Enter if it's added to PATH, otherwise"\
                   " enter the full path to the executable.\n>> ")
if ffmpegPath == "\n":
    ffmpegPath = "ffmpeg"

#Search for the au files and 
auFolder = filedialog.askdirectory() +"/"
files = [auFolder+file for file in os.listdir(auFolder) if file.endswith(".au")]
#sort them by creation time
files = sorted(files, key=lambda file: os.stat(file).st_mtime)

#rename them according to creation time, so audacity conversion can't mess them up
i = 0
while i <= len(files)-2:
    try:
        os.rename(files[i], auFolder+str(i+1)+".au")
        os.rename(files[i+1], auFolder+str(i+2)+".au")
    except FileExistsError:
        break #This script apparently has already been run once
    i += 2
    
input("Now convert everything in " + auFolder + " to wav using audacity and press enter.\n"\
      "Use File-Apply Chain... for this (preferably wav format)")

#Convert the mono canals into one
files = [auFolder+"cleaned/"+file for file in os.listdir(auFolder+"cleaned/")]
files = sorted(files, key=lambda file: int(file.split("/")[-1][:-4]))
try:
    os.mkdir("converted")
except FileExistsError:
    for file in os.listdir("converted"):
        os.remove("converted/"+file)
i = 0
while i <= len(files)-2:
    subprocess.run(ffmpegPath+" -i \""+files[i]+"\" -i \""+files[i+1] +\
                   "\" -filter_complex amix=inputs=2:duration=longest -y converted/"+str(i)+".mpeg")
    i += 2
    
#concatenate with the created files
files = ["converted/"+file for file in os.listdir("converted/")]
files = sorted(files, key=lambda file: int(file.split("/")[-1][:-5]))
command = ffmpegPath+" -i concat:\""
for i in range(len(files)):
    if i == len(files)-1:
        command += files[i]+"\" "
    else:
        command += files[i]+"|"

command += " -y converted.mp3"
#The file is created where this script is run
subprocess.run(command)
Thanks!

steve
Site Admin
Posts: 81651
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Merging .au files without the project file

Post by steve » Mon Jul 22, 2019 10:19 pm

yannik131 wrote:
Mon Jul 22, 2019 9:59 pm
ffmpeg doesn't support concatenating wav files though
SoX does. http://sox.sourceforge.net/
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

yannik131
Posts: 8
Joined: Sun May 26, 2019 4:35 pm
Operating System: Windows 10

Re: Merging .au files without the project file

Post by yannik131 » Tue Jul 23, 2019 8:06 am

Obviuosly it has to be

Code: Select all

if ffmpegPath == "":
    ffmpegPath = "ffmpeg"
instead. But I can't edit my post or sent a pm to anybody. So that's neat.

Post Reply