Help
Difference between revisions of "SoX"
(→Fades) |
|||
(17 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
== Dependencies == | == Dependencies == | ||
− | * [https://linux.die.net/man/1/sox SoX] | + | * [https://linux.die.net/man/1/sox SoX] – Sound eXchange, the Swiss Army knife of audio manipulation |
− | * [https://linux.die.net/man/1/ffmpeg FFmpeg] | + | * [https://linux.die.net/man/1/ffmpeg FFmpeg] – ffmpeg video converter |
** '''-ss:''' the time offset from beginning. (<code>h:m:s.ms</code>). | ** '''-ss:''' the time offset from beginning. (<code>h:m:s.ms</code>). | ||
** '''-t duration:''' record or transcode duration seconds of audio/video. | ** '''-t duration:''' record or transcode duration seconds of audio/video. | ||
+ | ** '''-vn no video:''' ignore video stream | ||
+ | * FFprobe – complement to FFmpeg, gives information on files. | ||
+ | * Audacity – UI software to inspect audio file, convenient to see their audio waves. | ||
== Denoise == | == Denoise == | ||
− | + | :''See also [[:phab:T251638]].'' | |
− | |||
− | < | + | === Extract noise samples === |
+ | Given a file with silence in its first 0.3sec. : | ||
+ | <syntaxhighlight lang="bash"># sox in.ext out.ext trim {start: s.ms} {duration: s.ms} | ||
sox audio.wav noise-audio.wav trim 0 0.300 | sox audio.wav noise-audio.wav trim 0 0.300 | ||
# or : | # or : | ||
− | ffmpeg -i audio.wav -vn -ss 00:00:00 -t 00:00:00.300 noise-audio.wav</ | + | ffmpeg -i audio.wav -vn -ss 00:00:00 -t 00:00:00.300 noise-audio.wav |
+ | </syntaxhighlight> | ||
− | === Generate a noise profile in sox | + | For a folder with .wav audios with noisy silence in first 150ms and last 200ms : |
− | < | + | <syntaxhighlight lang="bash"># Create noise samples |
+ | mkdir -p ./noise; | ||
+ | for file in ./wav/*.wav; | ||
+ | do key=$(basename "$file" .wav); | ||
+ | ffmpeg -i "$file" -vn -ss 00:00:00 -t 00:00:00.150 ./noise/noise-"$key"-head.wav ; | ||
+ | ffmpeg -vn -sseof -0.200 -t 0.200 -i "$file" ./noise/noise-"$key"-tail.wav | ||
+ | # sox "$file" ./noise/noise-"$key"-head.wav trim 0 0.200 | ||
+ | # sox "$file" ./noise/noise-"$key"-tail.wav reverse trim 0 0.200 reverse | ||
+ | done; | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | === Generate a noise profile in sox === | ||
+ | [[File:Noise-audio-shtooka.wav|Background audio noise sample from Shtooka project based on 282 samples from 191 audio files' header (0.17s) and tail (0.23s), totalling 51 sec. of noise. Such file are used as sample to remove background noise (denoise) in audio files recorded in similar conditions.|thumb]] | ||
+ | <syntaxhighlight lang="bash"># From one noise sample audio file | ||
+ | sox noise-audio.wav -n noiseprof noise.prof</syntaxhighlight> | ||
+ | |||
+ | <syntaxhighlight lang="bash"># Contact noise samples into single noise sample | ||
+ | ffmpeg -f concat -safe 0 -i <(for f in ./noise/*.wav; do echo "file '$PWD/$f'"; done) -c copy ./noise/noise-audio.wav | ||
+ | |||
+ | # From sample, creates noise profile | ||
+ | sox ./noise/noise-audio.wav -n noiseprof ./noise/noise.prof ; | ||
+ | </syntaxhighlight> | ||
=== Clean the noise from the audio === | === Clean the noise from the audio === | ||
Single file : | Single file : | ||
− | < | + | <syntaxhighlight lang="bash">sox audio.wav audio-clean.wav noisered noise.prof 0.21</syntaxhighlight> |
Batch of files: | Batch of files: | ||
− | < | + | <syntaxhighlight lang="bash"># Denoise |
− | for file in ./*.wav;do key=$(basename "$file" .wav); sox "$file" ./clean/"$key".wav noisered ./noise.prof 0.21; done;</ | + | mkdir -p ./clean; |
+ | for file in ./wav/*.wav;do key=$(basename "$file" .wav); | ||
+ | sox "$file" ./clean/"$key".wav noisered ./noise/noise.prof 0.21; | ||
+ | done;</syntaxhighlight> | ||
According to source : | According to source : | ||
Line 35: | Line 64: | ||
== Fades == | == Fades == | ||
+ | :''See also [[:phab:T251640]].'' | ||
To fade-in on 0.3s and out in 0.4s, you can use a simple ./fadeWav.sh bash script, such as: | To fade-in on 0.3s and out in 0.4s, you can use a simple ./fadeWav.sh bash script, such as: | ||
− | < | + | <syntaxhighlight lang="bash"> |
sox input.wav output.wav fade "0:0.3" `soxi -d input.wav` "0:0.3" | sox input.wav output.wav fade "0:0.3" `soxi -d input.wav` "0:0.3" | ||
− | </ | + | </syntaxhighlight> |
Or as a script: | Or as a script: | ||
− | < | + | <syntaxhighlight lang="bash">#! /bin/bash |
WAV_IN=$1 | WAV_IN=$1 | ||
WAV_OUT=$2 | WAV_OUT=$2 | ||
Line 50: | Line 80: | ||
LENGTH=`soxi -d $WAV_IN` | LENGTH=`soxi -d $WAV_IN` | ||
− | sox $WAV_IN $WAV_OUT fade $FADE_IN_L $LENGTH $FADE_OUT_L</ | + | sox $WAV_IN $WAV_OUT fade $FADE_IN_L $LENGTH $FADE_OUT_L</syntaxhighlight> |
<code>soxi -d</code> returns the length of the wav file. See sox documentation for more on [http://sox.sourceforge.net/soxi.html soxi]. | <code>soxi -d</code> returns the length of the wav file. See sox documentation for more on [http://sox.sourceforge.net/soxi.html soxi]. | ||
You can run this bash script as follows: | You can run this bash script as follows: | ||
− | < | + | <syntaxhighlight lang="bash">./fadeWav.sh input.wav faded.wav</syntaxhighlight> |
=== Sources === | === Sources === | ||
* [https://stackoverflow.com/a/24307805?stw=2 Answer:SOX and fade in and fade out] | * [https://stackoverflow.com/a/24307805?stw=2 Answer:SOX and fade in and fade out] | ||
+ | |||
+ | == Normalize == | ||
+ | :''Content to create. See also [[:phab:T213535]] and [[LinguaLibre:Chat_room/Archives/2019#Normalize_loudness|LinguaLibre:Chat_room#Normalize_loudness]].'' | ||
== See also == | == See also == | ||
+ | * [[Help:Rename]] | ||
+ | * [[Help:Converting audios]] | ||
* [https://stackoverflow.com/questions/20014064/ How to batch split audio files wherever there is silence?] | * [https://stackoverflow.com/questions/20014064/ How to batch split audio files wherever there is silence?] | ||
* [https://people.xiph.org/~jm/demo/rnnoise/ RNNoise] | * [https://people.xiph.org/~jm/demo/rnnoise/ RNNoise] | ||
+ | |||
+ | {{Technicals}} | ||
+ | |||
+ | [[Category:Lingua Libre:Help]] |
Latest revision as of 16:06, 24 January 2024
Dependencies
- SoX – Sound eXchange, the Swiss Army knife of audio manipulation
- FFmpeg – ffmpeg video converter
- -ss: the time offset from beginning. (
h:m:s.ms
). - -t duration: record or transcode duration seconds of audio/video.
- -vn no video: ignore video stream
- -ss: the time offset from beginning. (
- FFprobe – complement to FFmpeg, gives information on files.
- Audacity – UI software to inspect audio file, convenient to see their audio waves.
Denoise
- See also phab:T251638.
Extract noise samples
Given a file with silence in its first 0.3sec. :
# sox in.ext out.ext trim {start: s.ms} {duration: s.ms}
sox audio.wav noise-audio.wav trim 0 0.300
# or :
ffmpeg -i audio.wav -vn -ss 00:00:00 -t 00:00:00.300 noise-audio.wav
For a folder with .wav audios with noisy silence in first 150ms and last 200ms :
# Create noise samples
mkdir -p ./noise;
for file in ./wav/*.wav;
do key=$(basename "$file" .wav);
ffmpeg -i "$file" -vn -ss 00:00:00 -t 00:00:00.150 ./noise/noise-"$key"-head.wav ;
ffmpeg -vn -sseof -0.200 -t 0.200 -i "$file" ./noise/noise-"$key"-tail.wav
# sox "$file" ./noise/noise-"$key"-head.wav trim 0 0.200
# sox "$file" ./noise/noise-"$key"-tail.wav reverse trim 0 0.200 reverse
done;
Generate a noise profile in sox
# From one noise sample audio file
sox noise-audio.wav -n noiseprof noise.prof
# Contact noise samples into single noise sample
ffmpeg -f concat -safe 0 -i <(for f in ./noise/*.wav; do echo "file '$PWD/$f'"; done) -c copy ./noise/noise-audio.wav
# From sample, creates noise profile
sox ./noise/noise-audio.wav -n noiseprof ./noise/noise.prof ;
Clean the noise from the audio
Single file :
sox audio.wav audio-clean.wav noisered noise.prof 0.21
Batch of files:
# Denoise
mkdir -p ./clean;
for file in ./wav/*.wav;do key=$(basename "$file" .wav);
sox "$file" ./clean/"$key".wav noisered ./noise/noise.prof 0.21;
done;
According to source :
Change 0.21 to adjust the level of sensitivity in the sampling rates (I found 0.2-0.3 often provides best result).
Sources
Fades
- See also phab:T251640.
To fade-in on 0.3s and out in 0.4s, you can use a simple ./fadeWav.sh bash script, such as:
sox input.wav output.wav fade "0:0.3" `soxi -d input.wav` "0:0.3"
Or as a script:
#! /bin/bash
WAV_IN=$1
WAV_OUT=$2
FADE_IN_L="0:0.3"
FADE_OUT_L="0:0.4"
LENGTH=`soxi -d $WAV_IN`
sox $WAV_IN $WAV_OUT fade $FADE_IN_L $LENGTH $FADE_OUT_L
soxi -d
returns the length of the wav file. See sox documentation for more on soxi.
You can run this bash script as follows:
./fadeWav.sh input.wav faded.wav
Sources
Normalize
- Content to create. See also phab:T213535 and LinguaLibre:Chat_room#Normalize_loudness.
See also
- Help:Rename
- Help:Converting audios
- How to batch split audio files wherever there is silence?
- RNNoise