小编Mad*_*max的帖子

使用python向wav文件添加静音帧

第一次在这里发帖,让我们看看这是怎么回事。

我试图用 python 编写一个脚本,它会在 wav 文件的开头添加一秒钟的静音,但到目前为止没有成功。

我试图做的是在 wav 标头中读取,然后使用 wave 模块在开头添加一个 \0 ,但这并不能很好地工作。这是基于这里的代码http://andrewslotnick.com/posts/audio-delay-with-python.html

import wave
from audioop import add

def input_wave(filename,frames=10000000): #10000000 is an arbitrary large number of frames
    wave_file = wave.open(filename,'rb')
    params=wave_file.getparams()
    audio=wave_file.readframes(frames)
    wave_file.close()

    return params, audio

#output to file so we can use ipython notebook's Audio widget
def output_wave(audio, params, stem, suffix):
    #dynamically format the filename by passing in data
    filename=stem.replace('.wav','_{}.wav'.format(suffix))
    wave_file = wave.open(filename,'wb')
    wave_file.setparams(params)
    wave_file.writeframes(audio)

# delay the audio
def delay(audio_bytes,params,offset_ms):
    """version 1: delay after 'offset_ms' …
Run Code Online (Sandbox Code Playgroud)

python audio wave audio-processing

6
推荐指数
1
解决办法
7363
查看次数

标签 统计

audio ×1

audio-processing ×1

python ×1

wave ×1