datbkpro commited on
Commit
acaa9cd
·
verified ·
1 Parent(s): a0a209b

Update services/streaming_voice_service.py

Browse files
Files changed (1) hide show
  1. services/streaming_voice_service.py +23 -0
services/streaming_voice_service.py CHANGED
@@ -366,8 +366,31 @@ class StreamingVoiceService:
366
  result = transcription.strip()
367
  else:
368
  result = str(transcription).strip()
 
 
 
 
 
 
 
369
  total_asr_latency = time.time() - asr_start
370
  print(f"✅ ASR Latency: {total_asr_latency:.2f}s (API: {api_latency:.2f}s)")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
371
  print(f"✅ Transcription: '{result}'")
372
  return result
373
 
 
366
  result = transcription.strip()
367
  else:
368
  result = str(transcription).strip()
369
+ short_responses = {
370
+ 'ừ', 'uh', 'um', 'à', 'ờ', 'ê', 'ô',
371
+ 'có', 'không', 'đúng', 'sai', 'ok', 'okay', 'ừm',
372
+ 'vâng', 'dạ', 'ạ', 'được', 'tốt', 'hay', 'ừ ừ',
373
+ 'yes', 'no', 'yeah', 'yep', 'nope'
374
+ }
375
+
376
  total_asr_latency = time.time() - asr_start
377
  print(f"✅ ASR Latency: {total_asr_latency:.2f}s (API: {api_latency:.2f}s)")
378
+ # Chuẩn hóa text để so sánh
379
+ normalized_text = result.lower().strip()
380
+
381
+ # Loại bỏ dấu câu và khoảng trắng thừa
382
+ import re
383
+ normalized_text = re.sub(r'[^\w\s]', '', normalized_text)
384
+
385
+ # Nếu là từ ngắn thông dụng, vẫn chấp nhận
386
+ if normalized_text in short_responses:
387
+ print(f"✅ Nhận diện phản hồi ngắn: '{result}'")
388
+ return result
389
+ # Kiểm tra độ dài tối thiểu cho các từ khác
390
+ min_length = 2 # Ít nhất 2 ký tự cho các từ không trong danh sách ngắn
391
+ if len(normalized_text) < min_length and normalized_text not in short_responses:
392
+ print(f"⚠️ Bỏ qua transcription quá ngắn: '{result}'")
393
+ return None
394
  print(f"✅ Transcription: '{result}'")
395
  return result
396