Help

Difference between revisions of "Converting audios"

Line 12: Line 12:
  
 
== Helpers ==
 
== Helpers ==
<pre>mkdir -p ./new/                    # create folder, if not existing (-p)
+
<source lang="bash">
 +
mkdir -p ./new/                    # create folder, if not existing (-p)
 
file=&quot;./dir/audio-0a6f36g.flac&quot;    # path to .flac file into varible &quot;$file&quot;
 
file=&quot;./dir/audio-0a6f36g.flac&quot;    # path to .flac file into varible &quot;$file&quot;
avconv -i &quot;$file&quot; 2&gt;&amp;1              # print out metadata of $file, for some formats only</pre>
+
avconv -i &quot;$file&quot; 2&gt;&amp;1              # print out metadata of $file, for some formats only</source>
  
 
== Simple batch format conversion ==
 
== Simple batch format conversion ==
<pre>for file in ./flac/*.flac
+
<source lang="bash">
 +
for file in ./flac/*.flac
 
do
 
do
 
   key=$(basename &quot;$file&quot; .flac).mp3              # name of the file minus .flac, plus .mp3  
 
   key=$(basename &quot;$file&quot; .flac).mp3              # name of the file minus .flac, plus .mp3  
 
   lame --abr 24    -m m -h --resample 22.05 &quot;$file&quot; &quot;./new/$key&quot;
 
   lame --abr 24    -m m -h --resample 22.05 &quot;$file&quot; &quot;./new/$key&quot;
done</pre>
+
done</source>
  
 
== Metadata-based format conversion ==
 
== Metadata-based format conversion ==
 
This example works on SWAC recorder audio files having the <code>SWAC_TEXT</code> metadata field. In this exemple, we assume a folder with file <code>audio-0a6f36g.flac</code> and metadata <code>SWAC_TEXT    : 很</code>.
 
This example works on SWAC recorder audio files having the <code>SWAC_TEXT</code> metadata field. In this exemple, we assume a folder with file <code>audio-0a6f36g.flac</code> and metadata <code>SWAC_TEXT    : 很</code>.
  
<pre>for file in ./flac/*.flac
+
<source lang="bash">
 +
for file in ./flac/*.flac
 
   do
 
   do
 
   key=$(avconv -i &quot;$file&quot; 2&gt;&amp;1 | sed -ne 's/.*SWAC_TEXT *: //p')                # print metadata, assign SWAC_TEXT's value to variable.
 
   key=$(avconv -i &quot;$file&quot; 2&gt;&amp;1 | sed -ne 's/.*SWAC_TEXT *: //p')                # print metadata, assign SWAC_TEXT's value to variable.
 
   lame --abr 24    -m m -h --resample 22.05 &quot;$file&quot; &quot;./new-24k/cmn-$key.mp3&quot;    # ex: cmn-很.mp3 (24k abr)
 
   lame --abr 24    -m m -h --resample 22.05 &quot;$file&quot; &quot;./new-24k/cmn-$key.mp3&quot;    # ex: cmn-很.mp3 (24k abr)
 
   lame --cbr -b 96 -m m -h --resample 22.05 &quot;$file&quot; &quot;./new-96k/cmn-$key.mp3&quot;    # ex: cmn-很.mp3 (96k cbr)
 
   lame --cbr -b 96 -m m -h --resample 22.05 &quot;$file&quot; &quot;./new-96k/cmn-$key.mp3&quot;    # ex: cmn-很.mp3 (96k cbr)
done</pre>
+
done</source>

Revision as of 14:43, 21 May 2018

How to convert large batch of audios ?

Dependencies

sudo apt-get install lame avconv
man lame                           # then search for parameters via &quot;/{param}&quot;. ex: /-m

Technolecte

  • cbr: constant bit rate.
  • abr: average bit rate.
  • vbr: variable bit rate. For more, see man lame.

Helpers

mkdir -p ./new/                     # create folder, if not existing (-p)
file=&quot;./dir/audio-0a6f36g.flac&quot;     # path to .flac file into varible &quot;$file&quot;
avconv -i &quot;$file&quot; 2&gt;&amp;1              # print out metadata of $file, for some formats only

Simple batch format conversion

for file in ./flac/*.flac
do
  key=$(basename &quot;$file&quot; .flac).mp3              # name of the file minus .flac, plus .mp3 
  lame --abr 24    -m m -h --resample 22.05 &quot;$file&quot; &quot;./new/$key&quot;
done

Metadata-based format conversion

This example works on SWAC recorder audio files having the SWAC_TEXT metadata field. In this exemple, we assume a folder with file audio-0a6f36g.flac and metadata SWAC_TEXT : 很.

for file in ./flac/*.flac
  do
  key=$(avconv -i &quot;$file&quot; 2&gt;&amp;1 | sed -ne 's/.*SWAC_TEXT *: //p')                # print metadata, assign SWAC_TEXT's value to variable.
  lame --abr 24    -m m -h --resample 22.05 &quot;$file&quot; &quot;./new-24k/cmn-$key.mp3&quot;    # ex: cmn-很.mp3 (24k abr)
  lame --cbr -b 96 -m m -h --resample 22.05 &quot;$file&quot; &quot;./new-96k/cmn-$key.mp3&quot;    # ex: cmn-很.mp3 (96k cbr)
done