0

I am looking for a way that I can combine multiple wave files into one wave file using python and run it on linux. I don't want to use any add on other than the default shell command line and default python modules. For example, if I have a.wav and b.wav. I want to create a c.wav which start with the content from a.wav then b.wav. I've found wave module, that I can open a wave file and write into a new file. Since i'm really new in this audio world. I still can't figure out how to do it. Below is my code

import struct, wave

waveFileA = wave.open('./a.wav', 'r')
waveFileB = wave.open('./b.wav', 'r')
waveFileC = wave.open('./c.wav', 'w')

lengthA = waveFileA.getnframes()
for i in range(0,lengthA):
    waveFileC.writeframes(waveFileA.readframes(1))

lengthB = waveFileB.getnframes()
for i in range(0,lengthB):
    waveFileC.writeframes(waveFileB.readframes(1))

waveFileA.close()
waveFileB.close()
waveFileC.close()

When i run this code, I got this error:

wave.Error: # channels not specified

Please can any one help me?

4

3 に答える 3

3

チャネル数、サンプル幅、およびフレーム レートを設定する必要があります。

waveFileC.setnchannels(waveFileA.getnchannels())
waveFileC.setsampwidth(waveFileA.getsampwidth())
waveFileC.setframerate(waveFileA.getframerate())

異なる設定の a.wav と b.wav を処理したい場合は、pysox のようなものを使用て同じ設定に変換するか、nchannels と sampwidth については自分で苦労できるかもしれません。

于 2012-09-29T03:11:03.423 に答える
2

n=waveFileA.getnchannels()waveFileB の場合と同様に、最初の入力ファイルが使用するチャネルの数を調べるために呼び出す必要があるように見えます。次にwaveFileC.setnchannels(n)、出力ファイルに入れるチャネルの数を伝えるために使用する必要があります。チャンネル数が異なる入力ファイルをどのように処理するのかわかりません...

于 2012-09-29T02:41:47.317 に答える
0

これが私が探している答えです

Pythonを使用して2つのwavファイルを結合するには? (Tom 10 のスレッドを探してください)

それは別のスレッドにあります。誰かがすでにこの問題を解決しています。

于 2012-10-06T19:10:07.333 に答える