I am trying to add some code to the begging of a script so that it will remove all the .transcript files, when their is no coressponding .wav file. But it doesnt work.
This is the code I have added:
for transcriptfile in `$voicemaildir/*.transcript`; do
wavfile=`echo $transcriptfile | cut -d'.' -f1`.wav
# If the transcript file exists but the wav file does not, remove the transcript.
if [[ -f $transcriptfile && ! -f $wavfile ]]; then
rm -f $transcriptfile
fi
done
Here is the entire script:
!/bin/sh
voicemaildir=/var/spool/asterisk/voicemail/$1/$2/INBOX/
echo `date` ':' $voicemaildir >> /var/log/voicemail-notify.log
for transcriptfile in `$voicemaildir/*.transcript`; do
wavfile=`echo $transcriptfile | cut -d'.' -f1`.wav
# If the transcript file exists but the wav file does not, remove the transcript.
if [[ -f $transcriptfile && ! -f $wavfile ]]; then
rm -f $transcriptfile
fi
done
for audiofile in $voicemaildir/*.wav; do
transcriptfile=${audiofile/wav/transcript}
flacfile=${audiofile%.wav}.flac
# For each message.wav we check if message.transcript
# exists
if [ ! -f $transcriptfile ]; then
# If not, we create it
flac --best --sample-rate=8000 "$audiofile" -o "$flacfile"
speech-recog-cli.pl $flacfile | head -2 | tail -1 | cut -f 2 -d ":" > $transcriptfile
# Now we can do whatever we want with the new transcription
echo `cat $transcriptfile`
fi
done
Thanks