如何在python中删除/减少来自.wav音频文件的噪音

时间:2017-04-12 11:37:54

标签: python-3.x audio hex speech-recognition noise-reduction

我有一个.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'

2 个答案:

答案 0 :(得分:0)

您正在尝试将非数字转换为int,

也许,你的意思。

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

答案 1 :(得分:0)

转换为int时,不带前导'0x'的十六进制字符串手动指定基数。如下:

int(binascii.hexlify(iframes), 16)