57e869d89ef91b66315bbc55d0d6d9b56e82f8c5
11 self
.duration
= duration
12 self
.sample_rate
= sample_rate
14 def get_amplitudes_at_frequency_ranges(self
, ranges
):
15 recording
= self
._record
()
16 magnitude
= numpy
.abs(numpy
.fft
.rfft(recording
[:, 0], n
=self
.sample_rate
))
20 result
.append(numpy
.mean(magnitude
[start
:end
]))
23 def get_amplitude_at_frequency_range(self
, start
, end
):
24 n
= self
.sample_rate
// 2
25 if start
> n
or end
> n
:
26 raise ValueError("Maxmimum frequency is {}".format(n
))
28 recording
= self
._record
()
29 magnitude
= numpy
.abs(numpy
.fft
.rfft(recording
[:, 0], n
=self
.sample_rate
))
30 return numpy
.mean(magnitude
[start
:end
])
32 def get_noise_profile(
40 high
= 1.0 - low
- mid
42 recording
= self
._record
()
43 magnitude
= numpy
.abs(numpy
.fft
.rfft(recording
[:, 0], n
=self
.sample_rate
))
45 sample_count
= (self
.sample_rate
// 2) - noise_floor
47 mid_start
= noise_floor
+ int(sample_count
* low
)
48 high_start
= mid_start
+ int(sample_count
* mid
)
49 noise_ceiling
= high_start
+ int(sample_count
* high
)
51 amp_low
= numpy
.mean(magnitude
[self
.noise_floor
:mid_start
])
52 amp_mid
= numpy
.mean(magnitude
[mid_start
:high_start
])
53 amp_high
= numpy
.mean(magnitude
[high_start
:noise_ceiling
])
54 amp_total
= (low
+ mid
+ high
) / 3.0
56 return amp_low
, amp_mid
, amp_high
, amp_total
59 return sounddevice
.rec(
60 int(self
.duration
* self
.sample_rate
),
61 samplerate
=self
.sample_rate
,