making wav file after beamforming

494 views
Skip to first unread message

gav...@gmail.com

unread,
Sep 14, 2017, 4:54:38 AM9/14/17
to Acoular-users
Hi,

i have a recorded wav file from 2 microphones (someone speaking to one mic and noise in the second mic), converted to h5, also wrote xml mic positions, and used beamforming as in the demo. I get a mapping of the sources.
My question is how to convert the data that have been "beamformed" (using delay-sum-algo) to a wav file, so that i can hear that the noise has been reduced and the speaker is now louder.


Thanks for your help.

ndimuba...@gmail.com

unread,
Sep 22, 2017, 3:23:28 AM9/22/17
to Acoular-users
Hello,
You can convert a data array into a wav file using Python *wave* library ( in your case the signal array resulting from beamforming summing and scaling).
Assuming you have the "wave" library installed, then the code at the following link would save you data array as a wav file: https://pastebin.com/embed_js/w1YBnfR8

Best regards,
Boris

gav...@gmail.com

unread,
Sep 24, 2017, 4:23:48 AM9/24/17
to Acoular-users
Hi,

thanks for your answer. I know how to make a wavfile, i use wavfile.write() from scipy.io package. my question was where is the output of the beamforming so i can use this function to make my new wav file. I need a numpy array with the new samples. (BeamformerBase return some pointer..)

In fact i have a bigger issue. I see that no matter what input file i give to work on, the graph will always look the same.
I made 2 files where i talk from different angles, but the output sources seems identical..

Here is my code:

import sys
import numpy as np
import h5py
from os import path
import acoular
from pylab import figure, plot, axis, imshow, colorbar, show
from scipy.io import wavfile
from acoular import __file__ as bpath, td_dir, MicGeom, WNoiseGenerator, PointSource, Mixer, WriteH5

if __name__ == "__main__":
    if len(sys.argv) <= 1:
        print ("You must supply a filename to generate")
        exit(-1)
    for fname in sys.argv[1:]:
        fo = open(fname, "r")
        
arr = np.fromfile(fo, dtype=float, count=-1, sep=',')
arr = np.resize(arr, (len(arr)/2,2) )
max_value = np.max(arr)
arr = (arr/max_value) - 0.5

hdf = h5py.File('data2.h5', 'w')
time_data = hdf.create_dataset('time_data', data=arr, dtype='float32')

time_data.attrs['CLASS'] = 'EARRAY'
time_data.attrs['EXTDIM'] = '0'
time_data.attrs['TITLE '] = ''
time_data.attrs['VERSION'] = '1.1'
time_data.attrs.create('sample_freq' , '20000.0',None,float)

hdf.attrs.__setitem__('CLASS', 'GROUP')
hdf.attrs.__setitem__('PYTABLES_FORMAT_VERSION', '2.1')
hdf.attrs.__setitem__('TITLE' , '')
hdf.attrs.__setitem__('VERSION', '1.0')

hdf.close()
hdf = h5py.File('data2.h5', 'r')

micgeofile = path.join(path.split(acoular.__file__)[0],'xml','array_2.xml')
mg = acoular.MicGeom( from_file=micgeofile )
ts = acoular.TimeSamples( name='data2.h5' )
ps = acoular.PowerSpectra( time_data=ts, block_size=128, window='Hanning' )
rg = acoular.RectGrid( x_min=-0.7, x_max=0.7, y_min=-0.7, y_max=0.7, z=0.7, increment=0.01 )
bb = acoular.BeamformerBase( freq_data=ps, grid=rg, mpos=mg )
pm = bb.synthetic( 250, 1 )
Lm = acoular.L_p( pm )
imshow( Lm.T, origin='lower', vmin=Lm.max()-20, extent=rg.extend(), \
interpolation='bicubic')
colorbar()
figure(2)
plot(mg.mpos[0],mg.mpos[1],'o')
axis('equal')
show()
hdf.close()

here are my sample file (test.txt - mic1[sample], mic2[sample]..etc) and my xml file (2 mics). https://files.fm/u/9rnqqsmm
In this test.txt i said "left" , "right" , "center"

i run python myfile.py test.txt

please help me !
thanks a lot

samantha...@gmail.com

unread,
Apr 4, 2018, 5:22:55 AM4/4/18
to Acoular-users
hi,
sorry,but how can i convert one file wav in a file .h5????

thanks for your help

sammy

carlos.p...@gmail.com

unread,
May 4, 2018, 10:18:38 AM5/4/18
to Acoular-users
Hi, I think I try the same, but have the problem, how get samples filtered after beamforming?

"where is the output of the beamforming so i can use this function to make my new wav file. I need a numpy array with the new samples. (BeamformerBase return some pointer..)"


Thanks!

stephe...@gmail.com

unread,
Jan 24, 2020, 2:31:17 PM1/24/20
to Acoular-users
Hello -- maybe you can help me on my problem? 

I have collected a field recording (birds, vehicles, etc.) using a 4-microphone array, and would like to map the sounds using acoular, which requires an h5 file.

I am very new to Python -- starting with wav files & array positions, how do I get the data into an h5 file?

Thank you!

Steve Caird
Reply all
Reply to author
Forward
0 new messages