Preventing emitting the UserStartedSpeaking event multiple times.
This commit is contained in:
@@ -57,6 +57,10 @@ class BaseSmartTurn(ABC):
|
|||||||
def set_sample_rate(self, sample_rate: int):
|
def set_sample_rate(self, sample_rate: int):
|
||||||
self._sample_rate = sample_rate
|
self._sample_rate = sample_rate
|
||||||
|
|
||||||
|
@property
|
||||||
|
def speech_triggered(self) -> bool:
|
||||||
|
return self._speech_triggered
|
||||||
|
|
||||||
def append_audio(self, buffer: bytes, is_speech: bool) -> EndOfTurnState:
|
def append_audio(self, buffer: bytes, is_speech: bool) -> EndOfTurnState:
|
||||||
# Convert raw audio to float32 format and append to the buffer
|
# Convert raw audio to float32 format and append to the buffer
|
||||||
audio_int16 = np.frombuffer(buffer, dtype=np.int16)
|
audio_int16 = np.frombuffer(buffer, dtype=np.int16)
|
||||||
|
|||||||
@@ -196,12 +196,18 @@ class BaseInputTransport(FrameProcessor):
|
|||||||
and new_vad_state != VADState.STOPPING
|
and new_vad_state != VADState.STOPPING
|
||||||
):
|
):
|
||||||
frame = None
|
frame = None
|
||||||
if new_vad_state == VADState.SPEAKING:
|
# If the turn analyser is enabled, this will prevent:
|
||||||
frame = UserStartedSpeakingFrame()
|
# - Creating the UserStoppedSpeakingFrame
|
||||||
# TODO: need to double check if this is the expected behavior
|
# - Creating the UserStartedSpeakingFrame multiple times
|
||||||
# Not triggering the UserStoppedSpeakingFrame if the turn analyser is enabled
|
can_create_user_frames = (
|
||||||
elif new_vad_state == VADState.QUIET and not self.end_of_turn_analyzer:
|
self._params.end_of_turn_analyzer is None
|
||||||
frame = UserStoppedSpeakingFrame()
|
or not self._params.end_of_turn_analyzer.speech_triggered
|
||||||
|
)
|
||||||
|
if can_create_user_frames:
|
||||||
|
if new_vad_state == VADState.SPEAKING:
|
||||||
|
frame = UserStartedSpeakingFrame()
|
||||||
|
elif new_vad_state == VADState.QUIET:
|
||||||
|
frame = UserStoppedSpeakingFrame()
|
||||||
|
|
||||||
if frame:
|
if frame:
|
||||||
await self._handle_user_interruption(frame)
|
await self._handle_user_interruption(frame)
|
||||||
|
|||||||
Reference in New Issue
Block a user