Trong quá trình nghiên cứu, tôi cần phải convert hơn 500 file .wav sang .raw bằng tiện ích SOX nên đã xây dựng script như sau:
Chú ý:
- Tại câu hỏi Where is the parent-directory of wav-dir? bạn nên viết đường dẫn tuyệt đối đến thư mục chứa thư mục wav
- Bạn nên chắc chắn rằng thư mục raw nếu đã tồn tại thì không chứa dữ liệu quan trọng trước khi chọn xoá nó
- #!/bin/bash
- echo “Where is the parent-directory of wav-dir?”
- read parent_wavDir
- cd $parent_wavDir
- if [ -d “raw” ]; then
- echo “/raw exits”
- echo “Delete all file in /raw (y/n?)”
- read decision
- if [[ $decision == “y” ]]; then
- rm -Rf raw
- fi
- else
- echo “$parent_wavDir/raw doesn’t exits!”
- echo “Make directory raw”
- fi
- echo “SOX will convert .wav file to .raw file. Do you want continue (y/n?)”
- read dec
- if [[ $dec == “y” ]]; then
- mkdir raw
- cd wav
- echo “Copy all file from wav-directory to raw-directory”
- for file in *.wav
- do
- cp $file ../raw/$file
- done
- wait
- cd ../raw
- for file in *.wav
- do
- echo “Convert $file to ${file%%.*}.raw”
- sox $file -b 16 -e signed-integer -c 1 -r 48k -t raw ${file%%.*}.raw
- done
- wait
- rm *.wav
- fi
Bạn có thể tải file: Script Wav2Raw