Help
Difference between revisions of "Renaming"
Line 2: | Line 2: | ||
Given files names such as <code>./{codeLang}-{word}-{speaker}-{id}.wav</code> such as <code>./cmn-quan3-Can_Yue-LL12087.wav</code> : | Given files names such as <code>./{codeLang}-{word}-{speaker}-{id}.wav</code> such as <code>./cmn-quan3-Can_Yue-LL12087.wav</code> : | ||
− | <pre>mkdir -p ./new # create dir | + | <pre class="console>mkdir -p ./new # create dir |
for file in ./cmn-*.wav; | for file in ./cmn-*.wav; | ||
do | do | ||
Line 13: | Line 13: | ||
;Dependencies | ;Dependencies | ||
<pre class="console">sudo apt-get install lame avconv | <pre class="console">sudo apt-get install lame avconv | ||
− | avconv -i ./cmn- | + | avconv -i ./cmn-jiāoliú.flac 2>&1 # print out metadata of $file, for some formats only |
</pre> | </pre> | ||
Line 21: | Line 21: | ||
built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.9) 20160609 | built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.9) 20160609 | ||
[...] | [...] | ||
− | Input #0, flac, from './cmn- | + | Input #0, flac, from './cmn-jiāoliú.flac': |
Metadata: | Metadata: | ||
TITLE : 交流 | TITLE : 交流 | ||
Line 50: | Line 50: | ||
;Renaming | ;Renaming | ||
− | <pre>mkdir -p ./new # create dir | + | <pre class="console>mkdir -p ./new # create dir |
− | for file in ./cmn-*. | + | for file in ./cmn-*.flac; |
do | do | ||
key=$(avconv -i "$file" 2>&1 | sed -ne 's/.*SWAC_TEXT *: //p') # print metadata, assign SWAC_TEXT's value to variable. | key=$(avconv -i "$file" 2>&1 | sed -ne 's/.*SWAC_TEXT *: //p') # print metadata, assign SWAC_TEXT's value to variable. | ||
− | # | + | cp "$file" ./cmn-$key.flac # ./cmn-交流.flac |
done</pre> | done</pre> |
Revision as of 14:36, 21 May 2018
Renaming using the file name's fields
Given files names such as ./{codeLang}-{word}-{speaker}-{id}.wav
such as ./cmn-quan3-Can_Yue-LL12087.wav
:
mkdir -p ./new # create dir for file in ./cmn-*.wav; do key=$(basename "$file" | cut -d- -f2); # using "-" as split, select field 2 : "quan3" cp "$file" ./new/cmn-"$key".wav; # ./new/cmn-quan3.wav done
Renaming using metadata
- Dependencies
sudo apt-get install lame avconv avconv -i ./cmn-jiāoliú.flac 2>&1 # print out metadata of $file, for some formats only
Result
ffmpeg version 2.8.14-0ubuntu0.16.04.1 Copyright (c) 2000-2018 the FFmpeg developers built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.9) 20160609 [...] Input #0, flac, from './cmn-jiāoliú.flac': Metadata: TITLE : 交流 LICENSE : Creative Commons BY-SA 3.0 U.S COPYRIGHT : (c) 2009 Yue Tan ARTIST : Tan DATE : 2009-07-08 GENRE : Speech SWAC_LANG : cmn SWAC_TEXT : 交流 SWAC_ALPHAIDX : jiāoliú SWAC_SPEAK_NAME : Tan SWAC_SPEAK_GENDER: F SWAC_SPEAK_BIRTH_YEAR: 1978 SWAC_SPEAK_LANG : zho SWAC_SPEAK_LANG_REGION: Liaoning SWAC_SPEAK_LIV_COUNTRY: FR SWAC_SPEAK_LIV_TOWN: Caen SWAC_PRON_PHON : jiāoliú SWAC_COLL_SECTION: HSK niveau II SWAC_COLL_LICENSE: Creative Commons BY-SA 3.0 U.S SWAC_COLL_COPYRIGHT: (c) 2009 Yue Tan SWAC_TECH_DATE : 2009-07-08 SWAC_TECH_SOFT : Shtooka Recorder/1.3 Duration: 00:00:01.40, start: 0.000000, bitrate: 447 kb/s Stream #0:0: Audio: flac, 44100 Hz, mono, s16
- Renaming
mkdir -p ./new # create dir for file in ./cmn-*.flac; do key=$(avconv -i "$file" 2>&1 | sed -ne 's/.*SWAC_TEXT *: //p') # print metadata, assign SWAC_TEXT's value to variable. cp "$file" ./cmn-$key.flac # ./cmn-交流.flac done