Ich suche eine Wave-Datei von Mono zu Stereo in Python zu konvertieren. Am Ende soll es zwei identische Kanäle rechts und links den Monokanal Information. Mein Code funktioniert nicht. Ich bekomme nur den linken Kanal mit den Eingangsinformationen, der rechte Kanal ist leer. Irgendwelche Vorschläge?Python: Konvertieren Mono-Wave-Datei auf Stereo
import struct, wave
import numpy as np
def make_stereo(file1, output):
def everyOther (v, offset=0):
return [v[i] for i in range(offset, len(v), 2)]
ifile = wave.open(file1)
print ifile.getparams()
# (1, 2, 44100, 2013900, 'NONE', 'not compressed')
(nchannels, sampwidth, framerate, nframes, comptype, compname) = ifile.getparams()
frames = ifile.readframes(nframes * nchannels)
ifile.close()
out = struct.unpack_from("%dh" % nframes * nchannels, frames)
# Convert 2 channels to numpy arrays
if nchannels == 2:
left = np.array(list(everyOther(out, 0)))
right = np.array(list(everyOther(out, 1)))
else:
left = np.array(out)
right = left
ofile = wave.open(output, 'w')
ofile.setparams((2, sampwidth, framerate, nframes, comptype, compname))
ofile.writeframes(left.tostring())
# ofile.writeframes(right.tostring())
ofile.close()
make_stereo("Input.wav", "Output.wav")
Vielen Dank, dass der Trick! – bunkus