27 votes
Accepted

Remove silence from audio files while leaving gaps

The best way that I've seen is by adding the -l flag to silence as follows: sox in.wav out6.wav silence -l 1 0.1 1% -1 2.0 1% I've copied this command from Example 6 of this very useful blog post ...
Ben T's user avatar
  • 386
26 votes
Accepted

Sox: Convert a .wav file with required properties in a single command

sox disturbence.wav -r 16000 -c 1 -b 16 disturbence_16000_mono_16bit.wav gives within one command Sample rate of 16 kHz (-r 16000), one channel (mono) (-c 1), 16 bits bit depth (-b 16).
Golar Ramblar's user avatar
13 votes
Accepted

sox: Split audio on silence but keep silence

You can preserve all the silences in the split parts with some small changes. Starting with your original command: silence 1 0.5 0.1% 1 0.5 0.1% The first triplet of values means removes silence, ...
meuh's user avatar
  • 51.5k
12 votes

Split large amount of wav files to small parts

This is mentioned as an example in man sox: split the input file into multiple files of 30 seconds in length. Each output filename will have unique number in its name as documented in the Output ...
meuh's user avatar
  • 51.5k
12 votes
Accepted

batch convert mp3 files to wav using sox

It sounds like you're running into a problem with spaces in the filename. If you have a file named "My Greatest Hits.mp3", your command will try to convert the three different files named "My", "...
HiddenWindshield's user avatar
8 votes
Accepted

sox in between two pipes to resample a voice audio

You need to declare the type of the sox output by adding -t wav before the second -. When it's a file name, sox peeps at the name and deduces the type from there, but when it's stdout, the type needs ...
Ralph Rönnquist's user avatar
7 votes

Play a sound file slower or faster

I use the ffplay command (the sister of ffmpeg). There are two ways to change the speed of play: tempo and pitch. The former inserts or skips frames (it sounds like "glitches" in the music) but keeps ...
Constantine Kurbatov's user avatar
7 votes
Accepted

How to clear background noises with sox

If the background noise has some repetitive structure to it, you can remove it with the noiseprof and noisered effects of sox, see e.g. this script. Relevant bits repeated for convenience: # Create ...
Thor's user avatar
  • 17.2k
6 votes

sox convert raw audio to wav gives error although all option are defined

with -t raw, it's working: sox -t raw -r 44100 -b 16 -c 1 -L -e signed-integer /infiles/recording.dat /outfiles/recording.wav
gzx's user avatar
  • 81
5 votes

sox in between two pipes to resample a voice audio

When you give an explicit file name, such as toto.wav, SoX will deduce from the .wav extension that it is supposed to use WAV format. In case of - being the output “file name”, that deduction can’t be ...
chirlu's user avatar
  • 1,233
5 votes
Accepted

Split audio into several pieces based on timestamps from a text file with sox or ffmpeg

I've just had a quick go at it, very little in the way of testing so maybe it'll be of help. Below relies on ffmpeg-python, but it wouldn't be a challenge to write with subprocess anyway. At the ...
Guy's user avatar
  • 894
5 votes
Accepted

Sox format for stream with sample spec 's16le 1ch 16000Hz', channel map 'mono'

A raw stream does not contain any meta-information about its format, so you have to tell sox about it: parec ... | sox -t raw -r 16k -e signed -b 16 -c 1 ...
CL.'s user avatar
  • 2,709
4 votes
Accepted

Shuffle Using SoX?

You can use sort -R to reorder the file list into "random" order. The command could be the following: find ~/Music -type f | sort -R | xargs -I + play + Here find ~/Music -type f results in a list ...
Ralph Rönnquist's user avatar
4 votes

Programmatically change the playback speed (NOT pitch) in real-time

mplayer can playback wav and mp3 files, and you can interactively change the speed with keys [ and ], although wav files cannot be played slower than than their original speed. vlc can do the same and ...
meuh's user avatar
  • 51.5k
4 votes
Accepted

Play audio file from a certain time step in terminal?

Sox comes with the play command which takes the same arguments as sox. These include the trim effect which can specify a starting position. Effects come after the filename. So you can do, for example, ...
meuh's user avatar
  • 51.5k
4 votes
Accepted

How can I analyze a segment of an audio file with sox?

The effects function as a chain, so the stat effect feeds into trim, swap them around and it will work, e.g.: sox audio.wav -n trim 50 5 stat
Thor's user avatar
  • 17.2k
4 votes
Accepted

Why does `read` fail saying "read error: 0: Resource temporarily unavailable"?

What happens is that one of your SoX programs (sox, play, rec) has changed how stdin is behaving, making it non-blocking. Typically, something is calling fcntl(0, F_SETFL, O_NONBLOCK). When a call to ...
xhienne's user avatar
  • 17.8k
3 votes

Programmatically change the playback speed (NOT pitch) in real-time

You can use mplayer -af scaletempo -speed 0.5 filename.mp3 to change the playspeed without changing the audio pitch. If you would like to change the speed in real time (after calling mplayer from the ...
user's user avatar
  • 781
3 votes
Accepted

sound recording with motion?

I know this is a very old question but I may be able to help someone (like me, few years ago) who stumble across this in a search... I found the above answer from ridgy when I was looking to record ...
Augustus Nightcustard's user avatar
3 votes

Piping Sox and FFMPEG together

Decode with FFmpeg, pipe with the sox format to avoid format detection issues, output in 16 bits with level 8 FLAC compression. ffmpeg -hide_banner -i input.wav -f sox - | sox -t sox - -b 16 -C 8 ...
Patrik Lundquist's user avatar
3 votes

sox returns an error when I try to handle mp3 files

It can be solved esaily with yum install sox soxr sox-plugins-freeworld -y sox-plugins-freeworld include mp3 support.
hanx.phy's user avatar
3 votes

How to create the spectrogram of many audio files efficiently with Sox?

here is my "get spectrogram" solution to .... handle more codecs like aac, opus handle more and containers like mp4, mkv, avi, m4a normalize spectrogram height to 24kHz plot only one channel = mono ...
milahu's user avatar
  • 218
3 votes
Accepted

SoX - mixing two audio tracks but looping/repeating only one

got to use the pipe option -p, --sox-pipe otherwise the first command is not passing anything to stdout and the second command only gets one file for mixing: sox FAIL sox: Not enough input filenames ...
nath's user avatar
  • 5,704
3 votes
Accepted

What is the Hd output of SoX’s play?

Have a look at this thread on the SoX mailing list: [SoX-users] What does Hd:0.0 mean?: The first answer is: Rene Maurer <renemaur@...>: Can anyone tell me what "Hd:" means. ...
Freddy's user avatar
  • 25.6k
3 votes

Detecting sound / silence on a sox pipe?

If a dirty hack is good enough... I defer to Marcus' response, but if a dirty hack is good enough, you could try this one. Caveats: Requires PulseAudio or PipeWire (with pulseaudio utils installed) ...
Paul Rafferty's user avatar
2 votes

How to use sox or ffmpeg to detect silence intervals in a long audio file and replace them by zeros (aka suppress background noise)?

Use sox silence option: sox [input] [output] silence 1 1 2% -1 0.5 2% will trim silence at front to 1 second and reduce gaps to half a second in the file. 2% in my case ignores noise floor. 0% might ...
Robert's user avatar
  • 21
2 votes
Accepted

Splitting the ordered list into sublists

First, gather the list into a Bash array. If the files are in the current directory, you can use files=(prefix_????.mp3) Alternatively, you can use find and sort, IFS=$'\n' ; files=($(find . -name '...
Nominal Animal's user avatar
2 votes

Splitting the ordered list into sublists

(edited for clarity, and to make it safer) This should work if there are no gaps in the file sequence. Just replace LAST=0 with the last 4-digit number in your sequence. You’ll be left with ...
msp's user avatar
  • 51
2 votes
Accepted

How to monitor microphone volume level?

(Answer based on various comments, as this method seems to be acceptable, and comments are not guaranteed to stay.) Look at the first recording ("10 secs of silence") in an audio editor, e.g. ...
dirkt's user avatar
  • 32.4k
2 votes

Does altering the amplitude of an mp3 file, using sox, alter the signal?

Yes, sox uncompresses and re-compresses lossy formats while processing (see man sox), and iterated compression will cause slight detoriation of quality. To change the gain in an mp3 file, it's not ...
dirkt's user avatar
  • 32.4k

Only top scored, non community-wiki answers of a minimum length are eligible