I am using pocketsphinx to convert audio file to text. These two commands must do the work:
First i run
ffmpeg -i file.mp3 -ar 16000 -ac 1 file.wavthen i run
pocketsphinx_continuous -infile file.wav 2> pocketsphinx.log > result.txtI do that for each file (mp4 or mp3), I want to execute these two commands only once in a script, by browsing the directory content (files with the extension mp3 or mp4), and give the file the same name with the extension .txt (for exemple with the first command "file.mp3" become "file.wav" then using the second command "file.wav" become "file.txt").
How to do that using a single script file?
1 Answer
#!/usr/bin/env bash
dir=$1
for path in "$dir"/*.mp3; do name=$(basename "$path") ffmpeg -i "$path" -ar 16000 -ac 1 "$dir/$name.wav" pocketsphinx_continuous -infile "$dir/$name.wav" 2> "$dir/pocketsphinx.log" > "$dir/$name.txt"
doneSave the script somewhere like convert_all.sh and chmod +x it as well. Then use it like this:
./convert_all.sh path/to/some/dirIt will get all the .mp3s in that directory, convert them to .wav then run sphinx on them.