音频处理一:(音频基本信息)
生活随笔
收集整理的這篇文章主要介紹了
音频处理一:(音频基本信息)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
程序設計一:音頻基本信息
完整工程文件:
鏈接:https://pan.baidu.com/s/1dcoTGhIeDxsRz-RUr2Paxw 提取碼:jy48一:需求分析
wavinfo.exe waeinfo.py
輸入:wavinfo -i xxx.wav -o output.txt
輸出:(格式規范)xxx=yyy
rate(Hz)=16000 length=32000 ch=2 depth(bit)=16二:python代碼
holiday01.py import argparse import wavedef main():parser = argparse.ArgumentParser(description="Demo of argparse")parser.add_argument('-i','--input', default=' lanTian.wav ')parser.add_argument('-o','--output', default='output.txt')args = parser.parse_args()print(args)input = args.inputoutput=args.output# year = args.year# print('Hello {} {}'.format(name,year))#f = wave.open(r"G:\python\holiday\input", "rb")f = wave.open(input, "rb")# 讀取格式信息# 一次性返回所有的WAV文件的格式信息,它返回的是一個組元(tuple):聲道數, 量化位數(byte單位), 采樣頻率, 采樣點數, 壓縮類型, 壓縮類型的描述。wave模塊只支持非壓縮的數據,因此可以忽略最后兩個信息params = f.getparams()nchannels, sampwidth, framerate, nframes = params[:4]#file = open('results_storage.txt', 'a')file = open(output, 'a')bins = ['聲道數', '量化位數(byte單位)', '采樣頻率', '采樣點數']# i=0# 保存到本地txt文件params = params[:4]for i in range(4):# s = str(bins[i]).replace('[',").replace('[',")+'\t'+str(data[i]).replace('[',").replace('[',")#去除[],這兩行按數據不同,可以選擇s = str(bins[i]).replace('[', ").replace('[',") + '=' + str(params[i]).replace('[', ").replace('[',")s = s.replace("'", ").replace(',',") + '\n' # 去除單引號,逗號,每行末尾追加換行符file.write(s)file.close()print(f'聲道數:{nchannels} 量化位數(byte單位):{sampwidth} 采樣頻率:{framerate} 采樣點數:{nframes}')f.close()if __name__ == '__main__':main()三:實現結果
1.請求幫助
python holiday01.py -h optional arguments:-h, --help show this help message and exit-i INPUT, --input INPUT-o OUTPUT, --output OUTPUT2.保存數據
python holiday01.py -i BAC009S0003W0121.wav -o output.txt總結
以上是生活随笔為你收集整理的音频处理一:(音频基本信息)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 数据结构二:排序(快速排序和堆排序)
- 下一篇: 音频处理四:(音频的分帧)