I frequently have to sync audio from a boom mic or external mic and camera audio, and without having a clapboard this is quite tedious (even with a clapboard this is tedious XD) hence this script.
See the attached zipped example files for use with this script.
See http://www.fon.hum.uva.nl/praat/download_win.html
To download the praat tool.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# -*- coding: utf-8 -*- ## Copyright 2019 Trevor van Hoof and Jan Pijpers. ## Licensed under the Apache License, Version 2.0 ## Downloaded from https://janpijpers.com or https://gumroad.com/janpijpers ## See the license file attached or on https://www.janpijpers.com/script-licenses/ ''' Name: find the offset of one wav file to the other. Description: This is a common problem with video and audio recording. Where the sound recording does not start at exactly the same time as the video. So I use this script to sync the two audio tracks. It uses a wonderful third party tool called Praat http://www.fon.hum.uva.nl/praat/ praat license gnu http://www.fon.hum.uva.nl/praat/GNU_General_Public_License.txt Note: I recommend converting the wav files to 16 bit 16khz. That seems to have the best result. else praat will have issues Note the script only uses the first 30 seconds to compare. If you reduce this time then the script becomes faster. If you want to modify the duration edit this line in the .praat script. Extract part: 0, 30, "no" If you want to compare the entire wav file change this to... Extract part: 0, 3000000000000000, "no" or something like that XD ''' import subprocess praatExe = r"Praat.exe" praatScript = r"findWavOffset.praat" wavFileA =r"bensound-summer.wav" wavFileB =r"bensound-summer_offset.wav" ## Construct the command praat_command = '{} --run {} {} {}'.format( praatExe, praatScript, wavFileA, wavFileB) print "Starting praat command please wait a few seconds..." sound_offset_time = subprocess.check_output( praat_command, shell=True).decode("utf-16") print "The offset from file B to A is:" print sound_offset_time ## should be like: 28.750839181733134 print "enter to exit" raw_input() |