fix: No more falsely detect a sentence end on "U.S.A", "3:00 a.m." and more

This commit is contained in:
TomTom101
2024-07-06 11:01:32 +02:00
parent 6071920c45
commit d1a36004ab
2 changed files with 28 additions and 5 deletions

View File

@@ -28,6 +28,15 @@ from pipecat.processors.async_frame_processor import AsyncFrameProcessor
from pipecat.processors.frame_processor import FrameDirection, FrameProcessor
from pipecat.utils.audio import calculate_audio_volume
from pipecat.utils.utils import exp_smoothing
import re
endofsentence_pattern = r"(?<![A-Z])(?<!\d)(?<!\d\s[ap])(?<!Mr|Ms|Dr)(?<!Mrs)(?<!Prof)[\.\?\!:]$"
endofsentence_re = re.compile(endofsentence_pattern)
def match_endofsentence(text: str) -> bool:
return endofsentence_re.search(text.rstrip()) is not None
class AIService(FrameProcessor):
@@ -137,9 +146,7 @@ class TTSService(AIService):
text = frame.text
else:
self._current_sentence += frame.text
if self._current_sentence.strip().endswith(
(".", "?", "!")) and not self._current_sentence.strip().endswith(
("Mr,", "Mrs.", "Ms.", "Dr.")):
if match_endofsentence(self._current_sentence):
text = self._current_sentence
self._current_sentence = ""