0
ls -lrt *wav|wc -l --> 2160

Got around 2k audio files with sample rate 8k. Need to make an script to convert all the files to 16k Sample rate.For now Usig SOX for converting 1 file at a time. For eg. :-

sox 9560850166.wav -r 16000 -b 16 -c 1 file1.wav

Need an script so that next audio files will be selected from the directory and SOX will be done to change sample rate and it will be saved with a new file name like file1.wav, file2.wav etc...

Cyrus
  • 84,225
  • 14
  • 89
  • 153
Mrityunjoy
  • 17
  • 4
  • Does this answer your question? [How to loop over files in directory and change path and add suffix to filename](https://stackoverflow.com/questions/20796200/how-to-loop-over-files-in-directory-and-change-path-and-add-suffix-to-filename) – omajid Jul 24 '20 at 16:25
  • yes Sir thank you, reference helped. – Mrityunjoy Jul 24 '20 at 18:37

3 Answers3

3

Run the below for loop from the directory containing wave files

a=0;
for i in `ls *.wav`;
do

let a++;
echo "Processing file $i"
sox $i -r 16000 -b 16 -c 1 file$a.wav 

done
LogicIO
  • 627
  • 7
  • 15
2

You do not need a script for this combination of find and exec will do the job Use following command

find ./ -name "*wav" -exec sox {} -r 16000 -b 16 -c 1 {}.16000.wav \;

With this new audio file should get created with .16000.wav appended in original file name.

Vishal
  • 145
  • 7
0
#!/bin/bash
i=0;
for filename in /home/mrityunjoy/myWork/audio_files/*.wav; do
    i=$((i+1));
    sox "$filename" -r 16000 -b 16 -c 1 "file$i.wav"
done

This will give the output in the directory we run the script.

Mrityunjoy
  • 17
  • 4