Friday 13 July 2018

How do you separate each channel of a two channel wav fiel into two different files using wavio? or another library?

The following script plays the original file ok. I try to separate each channel in the obvious way, but it does not work.

import os
import wavio
import numpy
import pyglet

file_name = "guitarup_full.wav"

# I get the file !
File = wavio.read(file_name)
rate = File.rate
# it looks good
print File.data.shape
print rate
# and then the channels:
channel_1 = File.data[:,0]
channel_2 = File.data[:,1]
wavio.write("guitar_channel_1.wav", channel_1, rate )
wavio.write("guitar_channel_2.wav", channel_2, rate )

# now we try to play:
source =  pyglet.resource.media(file_name, streaming=False)
source_ch1 =  pyglet.resource.media("guitar_channel_1.wav", streaming=False)
source_ch2 =  pyglet.resource.media("guitar_channel_2.wav", streaming=False)

#uncomment the one you want to listen.
source.play()
#source_ch1.play()
#source_ch2.play()

pyglet.app.run()

The first sounds like a guitar, the second and third like Gaussian noise. Can someone tell me what is wrong with it?

The audio file I used is: https://www.freesounds.info/global/wav.php?fileid=11

The shape of the data is: (88471, 2) rate is: 44100

Also, if I play the file in another player, I get the same: Gaussian Noise.

Note: The use of pyglet is superfluous for the problem. If you use it to investigate this issue, make sure the files are in a folder registered in the resources folder.



from How do you separate each channel of a two channel wav fiel into two different files using wavio? or another library?

No comments:

Post a Comment