Help

Difference between revisions of "SoX"

(Create page about terminal audio tool SoX ! :D)
 
(13 intermediate revisions by one other user not shown)
Line 7: Line 7:
 
== Denoise ==
 
== Denoise ==
 
=== Extract noise file from silence + room’s noise ===
 
=== Extract noise file from silence + room’s noise ===
Given a file with silence in it’s first 0.3sec. :
+
Given a file with silence in its first 0.3sec. :
  
<pre># sox in.ext out.ext trim {start: s.ms} {duration: s.ms}
+
<source 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</pre>
+
ffmpeg -i audio.wav -vn -ss 00:00:00 -t 00:00:00.300 noise-audio.wav</source>
 +
 
 
=== Generate a noise profile in sox: ===
 
=== Generate a noise profile in sox: ===
<pre>sox noise-audio.wav -n noiseprof noise.prof</pre>
+
<source lang="bash">sox noise-audio.wav -n noiseprof noise.prof</source>
  
 
=== Clean the noise from the audio ===
 
=== Clean the noise from the audio ===
 
Single file :
 
Single file :
  
<pre>sox audio.wav audio-clean.wav noisered noise.prof 0.21</pre>
+
<source lang="bash">sox audio.wav audio-clean.wav noisered noise.prof 0.21</source>
 
Batch of files:
 
Batch of files:
  
<pre>mkdir -p ./clean;
+
<source lang="bash">mkdir -p ./clean;
for file in ./*.wav;do key=$(basename &quot;$file&quot; .wav); sox &quot;$file&quot; ./clean/&quot;$key&quot;.wav noisered ./noise.prof 0.21; done;</pre>
+
for file in ./*.wav;do key=$(basename "$file" .wav); sox "$file" ./clean/"$key".wav noisered ./noise.prof 0.21; done;</source>
 
According to source :
 
According to source :
  
Line 34: Line 35:
  
 
== Fades ==
 
== Fades ==
To fade-in on 0.3s and out in 0.4s, you can use a simple bash script, as this:
+
To fade-in on 0.3s and out in 0.4s, you can use a simple ./fadeWav.sh bash script, such as:
 +
 
 +
<source lang="bash">
 +
sox input.wav output.wav fade "0:0.3" `soxi -d input.wav` "0:0.3"
 +
</source>
  
<pre>#! /bin/bash
+
Or as a script:
 +
<source lang="bash">#! /bin/bash
 
WAV_IN=$1
 
WAV_IN=$1
 
WAV_OUT=$2
 
WAV_OUT=$2
FADE_IN_L=&quot;0:0.3&quot;
+
FADE_IN_L="0:0.3"
FADE_OUT_L=&quot;0:0.4&quot;
+
FADE_OUT_L="0:0.4"
  
 
LENGTH=`soxi -d $WAV_IN`
 
LENGTH=`soxi -d $WAV_IN`
  
sox $WAV_IN $WAV_OUT fade $FADE_IN_L $LENGTH $FADE_OUT_L</pre>
+
sox $WAV_IN $WAV_OUT fade $FADE_IN_L $LENGTH $FADE_OUT_L</source>
 
<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:
  
<pre>./fadeWav test.wav faded.wav</pre>
+
<source lang="bash">./fadeWav.sh input.wav faded.wav</source>
 
=== 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]
Line 56: Line 62:
 
* [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]
 +
 +
{{Lingua_Libre_scripts}}
 +
 +
[[Category:Lingua Libre:Help]]

Revision as of 17:46, 19 January 2021

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.

Denoise

Extract noise file from silence + room’s noise

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

Generate a noise profile in sox:

sox noise-audio.wav -n noiseprof noise.prof

Clean the noise from the audio

Single file :

sox audio.wav audio-clean.wav noisered noise.prof 0.21

Batch of files:

mkdir -p ./clean;
for file in ./*.wav;do key=$(basename "$file" .wav); sox "$file" ./clean/"$key".wav noisered ./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

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

See also

Lingua Libre technical helps
Template {{Speakers category}} • {{Recommended lists}} • {{To iso 639-2}} • {{To iso 639-3}} • {{Userbox-records}} • {{Bot steps}}
Audio files How to create a frequency list?Convert files formatsDenoise files with SoXRename and mass rename
Bots Help:BotsLinguaLibre:BotHelp:Log in to Lingua Libre with PywikibotLingua Libre Bot (gh) • OlafbotPamputtBotDragons Bot (gh)
MediaWiki MediaWiki: Help:Documentation opérationelle MediawikiHelp:Database structureHelp:CSSHelp:RenameHelp:OAuthLinguaLibre:User rights (rate limit) • Module:Lingua Libre record & {{Lingua Libre record}}JS scripts: MediaWiki:Common.jsLastAudios.jsSoundLibrary.jsItemsSugar.jsLexemeQueriesGenerator.js (pad) • Sparql2data.js (pad) • LanguagesGallery.js (pad) • Gadgets: Gadget-LinguaImporter.jsGadget-Demo.jsGadget-RecentNonAudio.js
Queries Help:APIsHelp:SPARQLSPARQL (intermediate) (stub) • SPARQL for lexemes (stub) • SPARQL for maintenanceLingualibre:Wikidata (stub) • Help:SPARQL (HAL)
Reuses Help:Download datasetsHelp:Embed audio in HTML
Unstable & tests Help:SPARQL/test
Categories Category:Technical reports