ここに初めて投稿すると、これがどのようになるかを見てみましょう。pythonを使用してwavファイルにサイレントフレームを追加
私は、wavファイルの先頭に2番目の無音を追加するスクリプトをPythonで作成しようとしましたが、これまでにうまくいかなかったのです。私がやろうとした何
は、wavファイルのヘッダを読み込み、その後、波モジュールを使用して先頭に\ 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' milliseconds"""
#calculate the number of bytes which corresponds to the offset in milliseconds
offset= params[0]*offset_ms*int(params[2]/1000)
#create some silence
beginning= b'\0'
#remove space from the end
end= audio_bytes
return add(audio_bytes, beginning+end, params[0])
audio_params, aduio_bytes = input_wave(<audio_file>)
output_wave(delay(aduio_bytes,audio_params,10000), audio_params, <audio_file>, <audio_file_suffics>)
ここから基づいていたコードです。
私はオーディオ処理にも非常に新しいので、今は何かを試していて何がスティックであるかを見極めています。
どのアドバイスやアイデアにアプローチするかはすばらしいでしょう:)。
また、私はpythonを使用しています。2.7.5
多くのありがとうございます。
クール感謝。それを与えて、魅力のように働く。 – Madmax