Update TranscriptProcessor to handle GeminiMultimodalLiveLLMService changes
This commit is contained in:
@@ -93,49 +93,55 @@ class AssistantTranscriptProcessor(BaseTranscriptProcessor):
|
|||||||
"""Aggregates and emits text fragments as a transcript message.
|
"""Aggregates and emits text fragments as a transcript message.
|
||||||
|
|
||||||
This method uses a heuristic to automatically detect whether text fragments
|
This method uses a heuristic to automatically detect whether text fragments
|
||||||
use pre-spacing (spaces at the beginning of fragments) or not, and applies
|
contain embedded spacing (spaces at the beginning or end of fragments) or not,
|
||||||
the appropriate joining strategy. It handles fragments from different TTS
|
and applies the appropriate joining strategy. It handles fragments from different
|
||||||
services with different formatting patterns.
|
TTS services with different formatting patterns.
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
Pre-spaced fragments (concatenated):
|
Fragments with embedded spacing (concatenated):
|
||||||
```
|
```
|
||||||
TTSTextFrame: ["Hello"]
|
TTSTextFrame: ["Hello"]
|
||||||
TTSTextFrame: [" there"]
|
TTSTextFrame: [" there"] # Leading space
|
||||||
TTSTextFrame: ["!"]
|
TTSTextFrame: ["!"]
|
||||||
TTSTextFrame: [" How"]
|
TTSTextFrame: [" How"] # Leading space
|
||||||
TTSTextFrame: ["'s"]
|
TTSTextFrame: ["'s"]
|
||||||
TTSTextFrame: [" it"]
|
TTSTextFrame: [" it"] # Leading space
|
||||||
TTSTextFrame: [" going"]
|
|
||||||
TTSTextFrame: ["?"]
|
|
||||||
```
|
```
|
||||||
Result: "Hello there! How's it going?"
|
Result: "Hello there! How's it"
|
||||||
|
|
||||||
Word-by-word fragments (joined with spaces):
|
Fragments with trailing spaces (concatenated):
|
||||||
|
```
|
||||||
|
TTSTextFrame: ["Hel"]
|
||||||
|
TTSTextFrame: ["lo "] # Trailing space
|
||||||
|
TTSTextFrame: ["to "] # Trailing space
|
||||||
|
TTSTextFrame: ["you"]
|
||||||
|
```
|
||||||
|
Result: "Hello to you"
|
||||||
|
|
||||||
|
Word-by-word fragments without spacing (joined with spaces):
|
||||||
```
|
```
|
||||||
TTSTextFrame: ["Hello"]
|
TTSTextFrame: ["Hello"]
|
||||||
TTSTextFrame: ["there!"]
|
TTSTextFrame: ["there"]
|
||||||
TTSTextFrame: ["How"]
|
TTSTextFrame: ["how"]
|
||||||
TTSTextFrame: ["is"]
|
TTSTextFrame: ["are"]
|
||||||
TTSTextFrame: ["it"]
|
TTSTextFrame: ["you"]
|
||||||
TTSTextFrame: ["going?"]
|
|
||||||
```
|
```
|
||||||
Result: "Hello there! How is it going?"
|
Result: "Hello there how are you"
|
||||||
"""
|
"""
|
||||||
if self._current_text_parts and self._aggregation_start_time:
|
if self._current_text_parts and self._aggregation_start_time:
|
||||||
# Heuristic to detect pre-spaced fragments
|
has_leading_spaces = any(
|
||||||
uses_prespacing = False
|
part and part[0].isspace() for part in self._current_text_parts[1:]
|
||||||
if len(self._current_text_parts) > 1:
|
)
|
||||||
# Check if any fragment after the first one starts with whitespace
|
has_trailing_spaces = any(
|
||||||
has_spaced_parts = any(
|
part and part[-1].isspace() for part in self._current_text_parts[:-1]
|
||||||
part and part[0].isspace() for part in self._current_text_parts[1:]
|
)
|
||||||
)
|
|
||||||
if has_spaced_parts:
|
|
||||||
uses_prespacing = True
|
|
||||||
|
|
||||||
# Apply appropriate joining method
|
# If there are embedded spaces in the fragments, use direct concatenation
|
||||||
if uses_prespacing:
|
contains_spacing_between_fragments = has_leading_spaces or has_trailing_spaces
|
||||||
# Pre-spaced fragments - just concatenate
|
|
||||||
|
# Apply corresponding joining method
|
||||||
|
if contains_spacing_between_fragments:
|
||||||
|
# Fragments already have spacing - just concatenate
|
||||||
content = "".join(self._current_text_parts)
|
content = "".join(self._current_text_parts)
|
||||||
else:
|
else:
|
||||||
# Word-by-word fragments - join with spaces
|
# Word-by-word fragments - join with spaces
|
||||||
|
|||||||
Reference in New Issue
Block a user