Isaacyn commited on
Commit
ddd0ed2
·
1 Parent(s): fb38179

async queue pipeline

Browse files
Files changed (1) hide show
  1. asr.py +22 -1
asr.py CHANGED
@@ -11,7 +11,7 @@ import wave
11
 
12
  SAMPLE_RATE = 16000
13
  GROQ_TIMEOUT = 5.0
14
- VAD_THRESHOLD = 0.5
15
 
16
  GROQ_KEYS = [
17
  "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",
@@ -26,6 +26,17 @@ BLACKLIST = [
26
  "indonesia.",
27
  "terima kasih",
28
  "thank you",
 
 
 
 
 
 
 
 
 
 
 
29
  ]
30
 
31
  def audio_to_wav_bytes(audio: np.ndarray, sample_rate: int = SAMPLE_RATE) -> bytes:
@@ -91,6 +102,10 @@ class ASRPipeline:
91
  confidences.append(conf)
92
  return max(confidences) if confidences else 0.0
93
 
 
 
 
 
94
  def is_valid_text(self, text: str) -> bool:
95
  text_lower = text.lower().strip()
96
  if len(text_lower) < 3:
@@ -98,6 +113,9 @@ class ASRPipeline:
98
  for bl in BLACKLIST:
99
  if text_lower.startswith(bl):
100
  return False
 
 
 
101
  return True
102
 
103
  def groq_transcribe(self, audio: np.ndarray) -> str:
@@ -145,6 +163,9 @@ class ASRPipeline:
145
  if vad_conf <= VAD_THRESHOLD:
146
  return None
147
 
 
 
 
148
  text = self.groq_transcribe(audio_chunk)
149
  if not text:
150
  return None
 
11
 
12
  SAMPLE_RATE = 16000
13
  GROQ_TIMEOUT = 5.0
14
+ VAD_THRESHOLD = 0.7
15
 
16
  GROQ_KEYS = [
17
  "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",
 
26
  "indonesia.",
27
  "terima kasih",
28
  "thank you",
29
+ "thanks",
30
+ "subscribe",
31
+ "like",
32
+ "comment",
33
+ ]
34
+
35
+ ENGLISH_STARTERS = [
36
+ "so ", "we ", "the ", "this ", "that ", "i ", "you ", "it ",
37
+ "and ", "but ", "for ", "are ", "is ", "was ", "in ", "of ",
38
+ "a ", "an ", "to ", "with ", "my ", "your ", "our ", "they ",
39
+ "he ", "she ", "what ", "how ", "when ", "where ", "why ",
40
  ]
41
 
42
  def audio_to_wav_bytes(audio: np.ndarray, sample_rate: int = SAMPLE_RATE) -> bytes:
 
102
  confidences.append(conf)
103
  return max(confidences) if confidences else 0.0
104
 
105
+ def has_enough_energy(self, audio: np.ndarray) -> bool:
106
+ rms = np.sqrt(np.mean(audio ** 2))
107
+ return rms > 0.01
108
+
109
  def is_valid_text(self, text: str) -> bool:
110
  text_lower = text.lower().strip()
111
  if len(text_lower) < 3:
 
113
  for bl in BLACKLIST:
114
  if text_lower.startswith(bl):
115
  return False
116
+ for starter in ENGLISH_STARTERS:
117
+ if text_lower.startswith(starter):
118
+ return False
119
  return True
120
 
121
  def groq_transcribe(self, audio: np.ndarray) -> str:
 
163
  if vad_conf <= VAD_THRESHOLD:
164
  return None
165
 
166
+ if not self.has_enough_energy(audio_chunk):
167
+ return None
168
+
169
  text = self.groq_transcribe(audio_chunk)
170
  if not text:
171
  return None