SimpleTextAggregator: Strip whitespace in the returned aggregation
This commit is contained in:
1
changelog/3247.fixed.md
Normal file
1
changelog/3247.fixed.md
Normal file
@@ -0,0 +1 @@
|
|||||||
|
- Fixed an issue in `SimpleTextAggreagtor` where spaces were not being stripped before returning the aggregation. This resulted in an extra space for TTS services that don't support word-timestamp alignment data.
|
||||||
@@ -40,7 +40,7 @@ class SimpleTextAggregator(BaseTextAggregator):
|
|||||||
Returns:
|
Returns:
|
||||||
The text that has been accumulated in the buffer.
|
The text that has been accumulated in the buffer.
|
||||||
"""
|
"""
|
||||||
return Aggregation(text=self._text.strip(), type=AggregationType.SENTENCE)
|
return Aggregation(text=self._text.strip(" "), type=AggregationType.SENTENCE)
|
||||||
|
|
||||||
async def aggregate(self, text: str) -> AsyncIterator[Aggregation]:
|
async def aggregate(self, text: str) -> AsyncIterator[Aggregation]:
|
||||||
"""Aggregate text and yield completed sentences.
|
"""Aggregate text and yield completed sentences.
|
||||||
@@ -97,7 +97,7 @@ class SimpleTextAggregator(BaseTextAggregator):
|
|||||||
# NLTK confirmed a sentence - return it
|
# NLTK confirmed a sentence - return it
|
||||||
result = self._text[:eos_marker]
|
result = self._text[:eos_marker]
|
||||||
self._text = self._text[eos_marker:]
|
self._text = self._text[eos_marker:]
|
||||||
return Aggregation(text=result, type=AggregationType.SENTENCE)
|
return Aggregation(text=result.strip(" "), type=AggregationType.SENTENCE)
|
||||||
# No sentence found - keep accumulating
|
# No sentence found - keep accumulating
|
||||||
return None
|
return None
|
||||||
# Still whitespace, keep waiting
|
# Still whitespace, keep waiting
|
||||||
@@ -123,7 +123,7 @@ class SimpleTextAggregator(BaseTextAggregator):
|
|||||||
# Return whatever we have in the buffer
|
# Return whatever we have in the buffer
|
||||||
result = self._text
|
result = self._text
|
||||||
await self.reset()
|
await self.reset()
|
||||||
return Aggregation(text=result.strip(), type=AggregationType.SENTENCE)
|
return Aggregation(text=result.strip(" "), type=AggregationType.SENTENCE)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
async def handle_interruption(self):
|
async def handle_interruption(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user