Guest User

Untitled

a guest
Oct 15th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.88 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. # analyseExtractFade.sh or aef.sh for short
  4. #
  5. #
  6. # Created by PARKER Martin on 11/10/2018.
  7. #
  8. # arguments are path of the audio file you want to segment, file format of the files you want to break things up into, fade parameters (fade in time fade out time and fade type and ultimately a text file from which to inject Metadata into the asstes you've generated.
  9.  
  10. # e.g. bash analyseExtractFade.sh ~/Dropbox/sounds/magicSound.wav aif 100s 560s q (this will analyse the audio file with agSegementSf.py and dump all of the slices it detects into a directory named magicSound. The slices will have fade ins of 100 samples fade outs of 560 samples using a quadratic fade function.
  11.  
  12. # It's useful to batch inject metadata into the files in this folder so you can do some further ace stuff if you have the command line version bwfmetaedit installed
  13.  
  14. agPath="/Applications/audioguide" #sets the path of audioguide software so you can use this script from anywhere, I'm keeping audioguide in my applications directory, you'll have to set this path up inside the script manually if your audioguide location is different.
  15.  
  16. sourceFile=$1 #we might need sourceFile later OK.
  17. VAR=$1 # this creates a variable from the input argument
  18. DIR=$(dirname "${VAR}") # this uses the terminal's ability to strip the directory name from the file supplied to the script
  19. FILE=$(basename "${VAR}") # this uses the terminal's ability to strip the filename name from the file supplied to the script
  20. SLICEPATH="${FILE%.*}_sliced" #Use this to make a folder name from the file name input, removing the file extension
  21.  
  22. python $agPath/agSegmentSf.py $sourceFile; #run agSegmentSf.py to generate a text file
  23.  
  24. cd "${DIR}" #navigate to the directory where the input file resides
  25. mkdir $SLICEPATH; #make a folder to keep the slices in based on the file name input
  26. index=0 #set a starting index of 0
  27.  
  28. while read line; do #read through the lines of the text file generated by audioguide, it's specified in the line below
  29. if [ $index -gt 0 ]; then
  30. sox $sourceFile ${DIR}/$SLICEPATH/${FILE%.*}_$index.$2 trim $start =$end #create the SoX call with file name based on slice number
  31. # print to the console while rendering
  32. # echo extracting $SLICEPATH/${1%.*}_$index.$2 $length ms long
  33.  
  34. fi
  35. ((index+=1))
  36. start="$(awk '{print $1}' <<<$line)" #use awk to get the first float from the current line
  37. end="$(awk '{print $2}' <<<$line)" #use awk to get the second float from the current line
  38. length=$(bc <<< "$end - $start") #get the length of the extract if you want to make some fades with SoX
  39.  
  40. done < $sourceFile.txt
  41.  
  42. cd "${DIR}"/$SLICEPATH
  43. mkdir faded # directory to place faded files in, prevents destructive conversion
  44. for file in *.$2; do # for all the files of type specified in argument 2 in the directory
  45. outfile="${file%.*}.$2" # create an output filename
  46. FADE_IN_L=$3 #define the FadeIn time from arg 3
  47. FADE_OUT_L=$4 #define the fadeOUt time from arg 4
  48. # LENGTH=`soxi -d $file` # find out the length of the file using soxi (-d returns the duration), don't think I needed this in the end.
  49. sox "$file" faded/"$outfile" fade $5 $FADE_IN_L -0 $FADE_OUT_L # run the sox command
  50. echo writing faded files to faded/"$outfile" #tell the terminal what you're doing
  51. done #finish up
  52.  
  53. # delete the slices files
  54. rm "${DIR}"/$SLICEPATH/*.wav
  55.  
  56. # move the faded files folder up a level
  57. ditto "${DIR}"/$SLICEPATH/faded/*.wav "${DIR}"/$SLICEPATH
  58.  
  59. #delete the directory called faded
  60. rm -R "${DIR}"/$SLICEPATH/faded/
  61.  
  62. # move the text file made by audioguide to the folder you've created
  63. mv $sourceFile.txt "${DIR}"/$SLICEPATH
  64.  
  65. # inject metatdata into extracted wav files using bwfmetaedit this is still todo, yawn.
  66.  
  67. # DATE=`date +%Y-%m-%d`
  68. # TIME=`date +%H:%M:%S`
  69. # YEAR=`date +%Y`
  70.  
  71. # echo bwfmetaedit --OriginationDate=$DATE --OriginationTime=$TIME --ICOP=$YEAR "${DIR}"/$SLICEPATH/*.wav # to do `awk '{print $0}' $6`
  72. # bwfmetaedit --out-core="${DIR}"/$SLICEPATH/$SLICEPATH.csv
  73. # open "${DIR}"/$SLICEPATH/$SLICEPATH.csv
Add Comment
Please, Sign In to add comment