0

コードがあります:

import wave
import numpy as np
import math

wav = wave.open("music.wav", mode="r")
(nchannels, sampwidth, framerate, nframes, comptype, compname) = wav.getparams()

content = wav.readframes(nframes)
samples = np.fromstring(content, dtype=types[sampwidth])

for n in range(nchannels):
    channel = samples[n::nchannels]
    print channel

結果として:

[0 0 0 ..., 0 0 8]
[0 0 0 ..., 0 0 0]

タイプ:

<type 'numpy.ndarray'>
<type 'numpy.ndarray'>

次に何をすべきかわかりません...別の解決策があれば幸いです:)

4

2 に答える 2

0

ソリューション:

# first channel
samples_o = samples[0::2]
# second channel
samples_c = samples[1::2]

# for 3 second 24000 = 8000*3
gr_size = len(samples_o) // gr_count 

lst = [lst[i:i+gr_size] for i in range(0, len(samples_o), gr_size)]

agr = []

for array in lst:
  max_el = np.argmax(array, axis=0)
  agr.append(max_el)

print np.mean(agr, axis=0) # avg max volume for first channel
于 2013-11-07T09:19:46.873 に答える