作者Levi Zhang 聯系方式
1. 需要用到的工具和軟件
Mac/Windows電腦均可,Mac上安裝brew, gcc, git, ffmpeg等。
windows 10 建議啟用bash,這樣使用命令行方便,上面的工具gcc, git, ffmpeg都可以安裝使用
屏幕截圖 2016-08-15 12.21.10-1.png
屏幕截圖 2016-08-15 12.26.05-1.png
iOS格式aud,用itools等工具導出
安卓格式amr,手機保存路經
Tencent\MicroMsg===================\voice2
用自己喜歡的工具將語音導出來,我個人用的是filezilla ftp,手機設置成ftp服務器,電腦連上慢慢下載。將voice2整個目錄下載到本地文件夾voice2
新建文件夾ori和dest,原語音在文件夾ori,轉換后語音在dest
2. 將子目錄下的所有錄音全部拷貝出來
原來的目錄層級很多,操作不方便,將所有語音拷貝到一個文件夾里
cd voice2
find . -name "*amr*" -exec cp {} ../ori \;
3. 轉碼
使用工具 silk-v3-decoder
轉換命令:
git clone https://github.com/kn007/silk-v3-decoder
cd silk-v3-decoder
bash converter.sh ori dest mp3
4. 重命名
研究了下語音文件的格式,發現msg_后面的12位數字分別是 秒秒時時分分日日月月年年,接著6位是用戶id。
為方便將語音文件按照用戶分類,需要將所有文件重命名下,按照用戶id-年月日時分秒的順序排列。
轉換前文件名
msg_00 13 39 05 05 16 3e53e0 0a9b4101.mp3
轉換后文件名
msg_3e53e0 16 05 05 13 39 00 0a9b4101.mp3
命令測試:
rename -v -n 's/msg_(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\S{6})/msg_$7_20$6$4$5$2$3$1_/' msg_0013390505163e53e00a9b4101.mp3
沒問題后,重命名所有文件
rename -v 's/msg_(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\S{6})/msg_$7_20$6$4$5$2$3$1_/' *.mp3
5. 使用ffmpeg工具按照目錄合并
5.1 本來打算一步到位,但出現錯誤
ffmpeg -f concat -i <(for f in *.mp3; do echo "file '$PWD/$f'"; done) -acodec copy `basename "$PWD"`.mp3
ffmpeg -f concat -i <(printf "file '$PWD/%s'\n" *.mp3) -acodec copy `basename "$PWD"`.mp3
屏幕截圖 2016-08-20 11.51.18.png
現在只能分步進行
5.2 取得列表
for f in *.mp3; do echo "file '$f'" >> mylist.txt; done
或者
printf "file '%s'\n" *.mp3 > mylist.txt
5.3 合并
ffmpeg -f concat -i mylist.txt -acodec copy `basename "$PWD"`.mp3
或者
ffmpeg -f concat -i mylist.txt -acodec copy `echo "${PWD##*/}"`.mp3
5.4 遍歷文件夾并執行命令
for dir in `ls .`
do
if [ -d $dir ]
then
echo $dir
cd $dir
printf "file '%s'\n" *.mp3 > mylist.txt
ffmpeg -f concat -i mylist.txt -acodec copy 2016`basename "$PWD"`.mp3
rm -f mylist.txt
mv 2016`basename "$PWD"`.mp3 ..
cd ..
fi
done
完工 EOF
6. 參考
進一步研究微信語音的格式/iOS上微信語音的導出/文中所用到的命令,參考:
- https://www.zhihu.com/question/31286525
- https://zhuanlan.zhihu.com/p/21783890
- http://iosre.com/t/topic/3199
- http://iosre.com/t/topic/3700
- https://github.com/mrojas/ios-pjsip/tree/master/silk-arm-ios
- https://www.zhihu.com/question/19909162
- https://github.com/kn007/silk-v3-decoder
- https://kn007.net/topics/decoding-qq-wechat-silk-v3-encoded-audio-to-mp3-or-other-formats/
- http://askubuntu.com/questions/283145/pattern-based-batch-file-rename-in-terminal
- http://tips.webdesign10.com/how-to-bulk-rename-files-in-linux-in-the-terminal
- https://www.cs.tut.fi/~jkorpela/perl/regexp.html
- https://trac.ffmpeg.org/wiki/Concatenate
- http://unix.stackexchange.com/questions/156084/why-does-process-substitution-result-in-a-file-called-dev-fd-63-which-is-a-pipe
- http://www.cnblogs.com/liuokay/archive/2011/08/15/2139493.html