mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-05 12:14:59 +00:00
clip low volumes to 0
This commit is contained in:
parent
fe73df9a42
commit
c38a877d81
1 changed files with 7 additions and 2 deletions
|
@ -22,12 +22,13 @@ class Voice:
|
||||||
min_rms = 1e5
|
min_rms = 1e5
|
||||||
pct = 0
|
pct = 0
|
||||||
|
|
||||||
|
threshold = 0.15
|
||||||
|
|
||||||
def is_audio_available(self):
|
def is_audio_available(self):
|
||||||
return sd is not None
|
return sd is not None
|
||||||
|
|
||||||
def callback(self, indata, frames, time, status):
|
def callback(self, indata, frames, time, status):
|
||||||
"""This is called (from a separate thread) for each audio block."""
|
"""This is called (from a separate thread) for each audio block."""
|
||||||
self.q.put(indata.copy())
|
|
||||||
rms = np.sqrt(np.mean(indata**2))
|
rms = np.sqrt(np.mean(indata**2))
|
||||||
self.max_rms = max(self.max_rms, rms)
|
self.max_rms = max(self.max_rms, rms)
|
||||||
self.min_rms = min(self.min_rms, rms)
|
self.min_rms = min(self.min_rms, rms)
|
||||||
|
@ -35,10 +36,14 @@ class Voice:
|
||||||
rng = self.max_rms - self.min_rms
|
rng = self.max_rms - self.min_rms
|
||||||
if rng > 0.001:
|
if rng > 0.001:
|
||||||
self.pct = (rms - self.min_rms) / rng
|
self.pct = (rms - self.min_rms) / rng
|
||||||
|
else:
|
||||||
|
self.pct = 0.5
|
||||||
|
|
||||||
|
self.q.put(indata.copy())
|
||||||
|
|
||||||
def get_prompt(self):
|
def get_prompt(self):
|
||||||
num = 10
|
num = 10
|
||||||
if np.isnan(self.pct):
|
if np.isnan(self.pct) or self.pct < self.threshold:
|
||||||
cnt = 0
|
cnt = 0
|
||||||
else:
|
else:
|
||||||
cnt = int(self.pct * 10)
|
cnt = int(self.pct * 10)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue