wav音频转pcm

百度搜索了很多博客,总结大家经验写下wav音频转pcm笔记,欢迎指导留言。

ffmpeg -i 原始.wav -f s16le new.pcm

eg:

 使用python编写成批量处理的脚本

# -*-coding:utf-8-*-
__author__ = "[email protected] hi:石磊"
import os
import time
import re
from adb_android import adb_android
import sys
import subprocess

def Write_file(wav_path):
    # wav_path = r"C:\Users\v_shilei03\Desktop\1"

    m4a_file = os.listdir(wav_path)

    for i, m4a in enumerate(m4a_file):
        print(i, m4a)
        old_name = os.path.join(wav_path, m4a)
        new_name = os.path.join(wav_path, m4a[:-4])
        # os.system("ffmpeg -i " + m4a_path + m4a+ " " + m4a_path + str(i) + ".wav")
        adb_d = "ffmpeg -i " + old_name + " -f s16le " + new_name + ".pcm"
        # print(adb_d)
        with open("test.txt", 'a+') as f:
            f.write(adb_d + '\n')
def Read_command(file):
    with open(file) as f:
        cmd = f.readlines()
    return cmd
def Executive_command (file):
    # print Read_command(file)
    for  i in Read_command(file):
        command = i.decode('utf8').encode('gb2312')
        print command
        # output = os.popen(command)
        output = os.system(command)
        time.sleep(3)

def main():
    # wav_path = r"C:\Users\v_shilei03\Desktop\1"
    wav_path = sys.argv[1]
    Write_file(wav_path)
    file = './test.txt'
    if file :
        Executive_command(file)
    else:
        print ("请传入相关参数")
if __name__ == '__main__':
    main()
    # os.remove("./test.txt")

ffmpeg下载链接:https://ffmpeg.zeranoe.com/builds/

如果有用点个关注呀

发布了72 篇原创文章 · 获赞 34 · 访问量 7万+

猜你喜欢

转载自blog.csdn.net/shilei123456789666/article/details/94581512