From 67c7ad3d0fe3a3e481fc90aee29648d7c1978cd9 Mon Sep 17 00:00:00 2001 From: Shuming Liu Date: Fri, 11 Sep 2026 12:21:02 +0800 Subject: [PATCH] fixed a bug --- sentence_api/transcription.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/sentence_api/transcription.py b/sentence_api/transcription.py index 95583b2..ee6875a 100644 --- a/sentence_api/transcription.py +++ b/sentence_api/transcription.py @@ -99,7 +99,8 @@ class MossTranscriber: segments = _parse_json_segments(payload.get("segments")) if not segments: segments = _parse_compact_segments(raw_text) - plain_text = " ".join(segment.text for segment in segments).strip() or raw_text + plain_text = " ".join(segment.text for segment in segments).strip() + plain_text = _strip_speaker_tags(plain_text) or _strip_speaker_tags(raw_text) return Transcript(text=plain_text, segments=segments) def _transcribe_chunked( @@ -142,7 +143,9 @@ class MossTranscriber: ) ) segments.sort(key=lambda item: (item.start_seconds, item.end_seconds)) - plain_text = " ".join(segment.text for segment in segments).strip() + plain_text = _strip_speaker_tags( + " ".join(segment.text for segment in segments).strip() + ) return Transcript(text=plain_text, segments=segments) def _post_audio( @@ -249,6 +252,11 @@ _ABBREVIATION_RE = re.compile( _SPEAKER_TAG_RE = re.compile(r"\[(S\d+)\]") +def _strip_speaker_tags(text: str) -> str: + """Remove inline ``[S01]`` speaker tags from a text string.""" + return _SPEAKER_TAG_RE.sub("", text).strip() + + def _expand_speaker_segments( segment: TranscriptionSegment, ) -> List[TranscriptionSegment]: