C
Carlos Leite
Is there any other option to analyze audio frequencies?
Or
Any here try to use pymedia to a simple audio FingerPrint.
A cant understand what the information the asBands() really giveme.
The Docs, say that asBands() return a List of tupples grouped by
frquenciy, and the first two values are frquency limits. But I dont
thonk so ! Its not seems to be correct!
THis is part of my output to an audio file of 2 seconds and a 1000Hz frequency
And the code is below
But I read a lot, search .. and I still cant understand what this
tuples really means.
Thanks oin advance
190.283203125;0.244085595012
211.42578125;1.08019864559
253.7109375;3.9267279307
317.138671875;9.92583847046
359.423828125;30.9667332967
422.8515625;2023.64868164
507.421875;1721.98303223
591.9921875;45.5271911621
697.705078125;6.53225898743
824.560546875;2.08980056218
972.55859375;0.794676959515
1141.69921875;0.362428373761
1331.98242188;0.29334748875
1564.55078125;0.218693238038
1839.40429688;0.278315830231
2156.54296875;0.146333972613
2537.109375;0.26632910683
2981.10351563;0.496793937683
3509.66796875;0.742335747028
4122.80273438;0.619799894445
4841.65039063;0.941718482971
5687.35351563;0.703689981014
6681.0546875;1.38942857222
7843.89648438;1.78449742244
9218.1640625;3.77672335976
190.283203125;0.194098889828
211.42578125;1.05994915962
253.7109375;3.90520095825
317.138671875;10.0715675354
359.423828125;31.0263417562
422.8515625;2023.83581543
507.421875;1721.99328613
591.9921875;45.4988830566
697.705078125;6.51365725199
824.560546875;2.10594912938
972.55859375;0.806965708733
1141.69921875;0.369390010834
1331.98242188;0.381403446198
1564.55078125;0.279652008644
1839.40429688;0.307544994354
2156.54296875;0.252535131243
2537.109375;0.34709642047
2981.10351563;0.604796524048
3509.66796875;0.553077500442
4122.80273438;1.07670492284
4841.65039063;1.21294984818
5687.35351563;1.33566446507
6681.0546875;1.47083462802
7843.89648438;2.5437119704
9218.1640625;4.14210630718
import pymedia.audio.sound as sound
import pymedia.audio.acodec as acodec
import sys
freqs=''
def playFile(file_name):
#Leitura do arquivo
file_extension = file_name.split('.' )[ -1 ].lower()
parms = {'id': acodec.getCodecID(file_extension), 'ext': file_extension}
decoder = acodec.Decoder(parms)
f = open(file_name, 'rb')
s = f.read(8192)
r = decoder.decode(s)
sampleFreqs= []
#snd = sound.Output(r.sample_rate, r.channels, sound.AFMT_S16_LE)
SAMPLES= 500
NUM_FREQS= 12
BANDS= 25
resampler= sound.Resampler( (r.sample_rate,r.channels), (r.sample_rate,1) )
analyzer= sound.SpectrAnalyzer( 1, SAMPLES, 512 )
arqb = open('saida_bands.txt' , 'w')
arqf = open('saida_freqs.txt', 'w')
arqb.write('%s \n' %(f.name))
contador = 0
while len(s)> 0:
contador = contador + 1
if r:
#snd.play(r.data)
s = f.read(512)
r = decoder.decode(s)
snd= sound.Output( r.sample_rate, r.channels, sound.AFMT_S16_LE )
s1= resampler.resample( r.data )
bTmp= analyzer.asBands( BANDS, s1 )
sampleFreqs.append( ( snd.getPosition()+ snd.getLeft(), bTmp ) )
fTmp= analyzer.asFrequencies(r.data)
#print (bTmp )
for k in bTmp:
for l in k:
#print l
arqb.write('%s;%s \n' % (l[0].__str__(),l[1].__str__(),))
arqb.write('Frame: %s \n' % (contador.__str__()))
arqf.write ('Leitura: %s \n ' % (contador.__str__()))
arqf.write ('Freq: %s \n ' % (fTmp.__str__()))
arqb.write('LOOPS: %s \n' % (contador.__str__()))
arqb.close()
arqf.close()
if __name__ == "__main__":
file_name = sys.argv[1]
playFile(file_name)
Or
Any here try to use pymedia to a simple audio FingerPrint.
A cant understand what the information the asBands() really giveme.
The Docs, say that asBands() return a List of tupples grouped by
frquenciy, and the first two values are frquency limits. But I dont
thonk so ! Its not seems to be correct!
THis is part of my output to an audio file of 2 seconds and a 1000Hz frequency
And the code is below
But I read a lot, search .. and I still cant understand what this
tuples really means.
Thanks oin advance
190.283203125;0.244085595012
211.42578125;1.08019864559
253.7109375;3.9267279307
317.138671875;9.92583847046
359.423828125;30.9667332967
422.8515625;2023.64868164
507.421875;1721.98303223
591.9921875;45.5271911621
697.705078125;6.53225898743
824.560546875;2.08980056218
972.55859375;0.794676959515
1141.69921875;0.362428373761
1331.98242188;0.29334748875
1564.55078125;0.218693238038
1839.40429688;0.278315830231
2156.54296875;0.146333972613
2537.109375;0.26632910683
2981.10351563;0.496793937683
3509.66796875;0.742335747028
4122.80273438;0.619799894445
4841.65039063;0.941718482971
5687.35351563;0.703689981014
6681.0546875;1.38942857222
7843.89648438;1.78449742244
9218.1640625;3.77672335976
190.283203125;0.194098889828
211.42578125;1.05994915962
253.7109375;3.90520095825
317.138671875;10.0715675354
359.423828125;31.0263417562
422.8515625;2023.83581543
507.421875;1721.99328613
591.9921875;45.4988830566
697.705078125;6.51365725199
824.560546875;2.10594912938
972.55859375;0.806965708733
1141.69921875;0.369390010834
1331.98242188;0.381403446198
1564.55078125;0.279652008644
1839.40429688;0.307544994354
2156.54296875;0.252535131243
2537.109375;0.34709642047
2981.10351563;0.604796524048
3509.66796875;0.553077500442
4122.80273438;1.07670492284
4841.65039063;1.21294984818
5687.35351563;1.33566446507
6681.0546875;1.47083462802
7843.89648438;2.5437119704
9218.1640625;4.14210630718
import pymedia.audio.sound as sound
import pymedia.audio.acodec as acodec
import sys
freqs=''
def playFile(file_name):
#Leitura do arquivo
file_extension = file_name.split('.' )[ -1 ].lower()
parms = {'id': acodec.getCodecID(file_extension), 'ext': file_extension}
decoder = acodec.Decoder(parms)
f = open(file_name, 'rb')
s = f.read(8192)
r = decoder.decode(s)
sampleFreqs= []
#snd = sound.Output(r.sample_rate, r.channels, sound.AFMT_S16_LE)
SAMPLES= 500
NUM_FREQS= 12
BANDS= 25
resampler= sound.Resampler( (r.sample_rate,r.channels), (r.sample_rate,1) )
analyzer= sound.SpectrAnalyzer( 1, SAMPLES, 512 )
arqb = open('saida_bands.txt' , 'w')
arqf = open('saida_freqs.txt', 'w')
arqb.write('%s \n' %(f.name))
contador = 0
while len(s)> 0:
contador = contador + 1
if r:
#snd.play(r.data)
s = f.read(512)
r = decoder.decode(s)
snd= sound.Output( r.sample_rate, r.channels, sound.AFMT_S16_LE )
s1= resampler.resample( r.data )
bTmp= analyzer.asBands( BANDS, s1 )
sampleFreqs.append( ( snd.getPosition()+ snd.getLeft(), bTmp ) )
fTmp= analyzer.asFrequencies(r.data)
#print (bTmp )
for k in bTmp:
for l in k:
#print l
arqb.write('%s;%s \n' % (l[0].__str__(),l[1].__str__(),))
arqb.write('Frame: %s \n' % (contador.__str__()))
arqf.write ('Leitura: %s \n ' % (contador.__str__()))
arqf.write ('Freq: %s \n ' % (fTmp.__str__()))
arqb.write('LOOPS: %s \n' % (contador.__str__()))
arqb.close()
arqf.close()
if __name__ == "__main__":
file_name = sys.argv[1]
playFile(file_name)