美文网首页
音频格式转换:微信语音aud格式转成wav格式

音频格式转换:微信语音aud格式转成wav格式

作者: Colleen_oh | 来源:发表于2019-04-28 16:45 被阅读0次

近期遇到音频格式问题,下面就来记录一下,我暂时还没有找到直接从音频格式aud转换成wav的工具或者代码,所以我这里的转换是先把aud转换成mp3格式,然后再从mp3格式转换成aud格式。我是在linux上面跑的(centos7)。

一、aud转换成mp3

我用的是别人开发的silk v3编码音频格式转换工具,首先要从github下载https://github.com/kn007/silk-v3-decoder工具,下载这上面的压缩包,放到linux上解压,当然你也可以直接在linux上git。

sh converter.sh input_folder output_folder output_format

上面是官方代码,我来举个例子:

sh converter.sh input output mp3  
#input是待转换的音频文件目录,output是音频输出的目录,想将所有silk v3编码格式的音频转换为MP3

下面是我在linux上自己写的python脚本:

import sys,os
def to_mp3(int_path,out_path):
    for category in os.listdir(int_path):
        #os.system('mkdir' + out_path + category)#新建文件夹
        os.system( 'sh converter.sh '+int_path  +category+'/ ' + out_path  +category+'/ '+ 'mp3')
to_mp3(sys.argv[1],sys.argv[2])  

这是我有个大文件夹下还有很多文件夹的情况下写的,如果你的文件夹下面就直接是aud文件,就不用做循环啦。

二、MP3转wav

MP3就需要用到FFmpeg,我们需要在linux装FFmpeg才行,安装流程之前我有写过。https://www.jianshu.com/p/7ecaee04bdc6

如果只是一条音频MP3转成wav,可以用下面的代码

ffmpeg -i DING.mp3 -f wav test.wav

下面是我自己写的文件夹下的脚本(单双层文件夹):

import sys,os

def mp3_wav(path):
    for category in os.listdir(path):
        catdir = os.path.join(path,category)
        if  os.path.isdir(catdir):# 如果不是文件夹则跳过
            for mp3file in os.listdir(path + category +'/'):
                os.path.splitext(mp3file)[1] == '.mp3'
                filename = os.path.splitext(mp3file)[0]
                os.system('ffmpeg -i ' + path + category +'/' +filename +'.mp3 -f wav '+ path + category +'/'+filename + '.wav')
        else : 
            os.path.splitext(category)[1] == '.mp3'
            filename = os.path.splitext(category)[0]
            os.system('ffmpeg -i ' + path +filename +'.mp3 -f wav '+ path +filename + '.wav')
            
            
mp3_wav(sys.argv[1])

参考:
https://kn007.net/topics/advanced-batch-decoding-silk-v3-encoded-audio-to-other-formats/
https://kn007.net/topics/decoding-qq-wechat-silk-v3-encoded-audio-to-mp3-or-other-formats/

相关文章

网友评论

      本文标题:音频格式转换:微信语音aud格式转成wav格式

      本文链接:https://www.haomeiwen.com/subject/sihjnqtx.html