我正在尝试使用此脚本使用Sox批量标准化音频。我遇到了问题,因为它似乎没有因某种原因创建tmp文件,当然也没有规范化的音频文件。我收到每个文件的错误:
norm_fade.sh: line 57: /Applications/sox/WantNotSamples/Who Am I-temp.wav: No such file or directory
Normalized File "wav_file" exists at "/Applications/sox/WantNotSamplesNormalize"
rm: /Applications/sox/WantNotSamples/Who Am I-temp.wav: No such file or directory
这是我的剧本:
#!/bin/sh
# Script.sh
#
#
# Created by scacinto on 1/31/13.
#
# For now, only put audio files in the working directory - working on a fix
# This is the directory to the source soundfiles that need to be
# normalized and faded (the first argument on the command line.)
src=$1
# This is the directory to write the normalized and faded files to
# (The second path you must supply on the command line.)
dest=$2
# This is the sox binary directory. Please set this to your sox path.
# As it is now, this assumes that the sox binary is in the same directory
# as the script.
SOX= ./sox
#enable for loops over items with spaces in their name
IFS=$'\n'
# This is the 'for' loop - it will run for each file in your directory.
for original_file in `ls "$src/"`
do
# Get the base filename of the current wav file
base_filename=`basename "$original_file" .wav`
# We need a temp file name to save the intermediate file as
temp_file="${base_filename}-temp.wav"
echo "Creating temp file: \"$temp_file\" in \"$src\""
# And we need the output WAV file
wav_file="${base_filename}-nf.wav"
# Convert all spaces to hyphens in the output file name
wav_file=`echo $wav_file | tr -s " " "-"`
#Print a progress message
echo "Processing: \"$original_file\". Saving as \"$wav_file\" ..."
# We need the length of the audio file
original_file_length=`$SOX $src/"$original_file" 2>&1 -n stat | grep Length | cut -d : -f 2 | cut -f 1`
# Use sox to add perform the fade-in and fade-out
# saving the result as our temp_file. Adjust the 0.1s to your desired fade
# times.
#$SOX $src/"$original_file" $src/"$temp_file" fade t 0.1 $original_file_length 0.1
# If files have readable headers, you can skip the above operation to get the
# file length and just use 0 as below.
#$SOX $src/"$original_file" $src/"$temp_file" fade t 0.5 0 0.5
# normalize and write to the output wave file
$SOX $src/"$temp_file" $dest/"$wav_file" norm -0.5
echo "Normalized File \"wav_file\" exists at \"$dest\""
# Delete that temp file
rm $src/$temp_file
done