You are not logged in.

#1 2017-02-06 02:18:56

audioMan
Member
Registered: 2017-02-05
Posts: 16

[SOLVED] Getting sOx to output multiple files

Hi,

I am trying to use sOx to convert *.flac to .wav ready for CD writing. The only problem is that sOx only outputs a single file. How can I use sOx to create a seperate file for each conversion? The man for sOx is fairly confusing on this matter. This is for a script, so converting the files one by one isn't an option. Also, internet searches turned up nothing.

Any help is much appreciated!

Regards,

- audioMan

Last edited by audioMan (2017-02-06 14:25:43)

Offline

#2 2017-02-06 02:34:58

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,523
Website

Re: [SOLVED] Getting sOx to output multiple files

audioMan wrote:

This is for a script, so converting the files one by one isn't an option

Why not - converting each file with it's own invocation of sox is exactly what a script would be good for.

What is currently in the script?


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#3 2017-02-06 02:51:24

audioMan
Member
Registered: 2017-02-05
Posts: 16

Re: [SOLVED] Getting sOx to output multiple files

Trilby wrote:
audioMan wrote:

This is for a script, so converting the files one by one isn't an option

Why not - converting each file with it's own invocation of sox is exactly what a script would be good for.

What is currently in the script?

Here is the script so far:

#!/bin/bash

# Creates the directory for converted files
 mkdir converted


# Uses sOx to convert from 96/24 to 44/16 
sox *.flac -b 16 -r 44.1k output.wav dither -f shibata
mv *.wav converted
cd converted
echo "sOx conversion completed."

# Makes TOC file with mktoc
mktoc -w *.wav >> toc_file.toc

# Records the converted audio files to a CD using CDRDAO.
cdrdao write --speed 8 toc_file.toc
eject
echo "Writing complete!"

As of now, the script produces one output file and writes the single file to CD, which isn't what I want.

- audioMan

Offline

#4 2017-02-06 13:16:21

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,523
Website

Re: [SOLVED] Getting sOx to output multiple files

You're currently telling it to combine all the files into one called "output.wav".  If it didn't combine all of them, then each one would overwrite the last and you'd still only have one output file.  Replace the following to lines with the code after them:

sox *.flac -b 16 -r 44.1k output.wav dither -f shibata
mv *.wav converted
for f in *.flac; do
   sox "$f" -b 16 -r 44.1k "converted/${f%.flac}.wav" dither -f shibata
done

"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#5 2017-02-06 14:24:47

audioMan
Member
Registered: 2017-02-05
Posts: 16

Re: [SOLVED] Getting sOx to output multiple files

Trilby wrote:

You're currently telling it to combine all the files into one called "output.wav".  If it didn't combine all of them, then each one would overwrite the last and you'd still only have one output file.  Replace the following to lines with the code after them:

sox *.flac -b 16 -r 44.1k output.wav dither -f shibata
mv *.wav converted
for f in *.flac; do
   sox "$f" -b 16 -r 44.1k "converted/${f%.flac}.wav" dither -f shibata
done

Thanks a lot! I knew I needed some kind of loop, but am relatively new to bash scripting. Works like a charm. Here is the script in case anyone would like to use it:

#!/bin/bash

echo "Starting sOx Conversion."

# Creates the directories needed
 mkdir converted


# Uses sOx to convert from FLAC 96/24 to WAV 44/16. Thanks to Trilby for 
# helping with this part.
for f in *.flac; do
   sox "$f" -b 16 -r 44.1k "converted/${f%.flac}.wav" dither -f shibata
done
echo sOx conversion complete!
cd converted

# Makes TOC file with mktoc
echo "Making TOC file."
mktoc -w *.wav >> toc_file.toc
echo "TOC file made."

# Records the converted audio files to a CD using CDRDAO.
echo "Starting CDRDAO."
cdrdao read-cddb toc_file.toc
cdrdao write --speed 8 toc_file.toc
eject
echo "Writing complete!"

Obviously, it can be modified (notably the sOx conversion).

- audioMan

Offline

Board footer

Powered by FluxBB