2017-04-12 477 views
0

我有一個.wav音頻文件,我正在將音頻轉換爲文本。我需要減少/消除噪音以獲得更準確的結果。如何從python中的.wav音頻文件中刪除/減少噪聲

請讓我知道如何去了解它

import wave 
import sys 

import binascii 

ip = wave.open('C:\\Users\\anagha\\Documents\\Python Scripts\\a1.wav', 'r') 

op = wave.open('C:\\Users\\anagha\\Documents\\Python Scripts\\r_1.wav', 'w') 
op.setparams(ip.getparams()) 

for i in range(ip.getnframes()): 
iframes = ip.readframes(1) 
amp = int(binascii.hexlify(iframes)) 
if amp > 32767: 
    amp = 65535 - int(binascii.hexlify(iframes))#-ve 
    print(amp) 
else: 
    amp = int(binascii.hexlify(iframes))#+ve 
    print(amp) 
if amp < 2000: 
    #make it zero 
    final_frame = '\x00\x00' 
else: 
    #Keep the frame 
    final_frame = iframe 
op.writeframes(final_frame) 
op.close() 
ip.close() 

收到錯誤:

ValueError: invalid literal for int() with base 10: b'ffff' 

回答

0

你試圖非數字轉換成整型,

也許,你意思。

amp = int(len(binascii.hexlify(iframes))) 
0

轉換爲int時,不帶前導'0x'的十六進制字符串手動指定基礎。如下:

int(binascii.hexlify(iframes), 16)