rename to_flush to concatenate_tsw
This commit is contained in:
parent
77d43885a3
commit
8ee1488c08
2 changed files with 19 additions and 13 deletions
|
|
@ -170,15 +170,15 @@ class OnlineASRProcessor:
|
||||||
|
|
||||||
# transform to [(beg,end,"word1"), ...]
|
# transform to [(beg,end,"word1"), ...]
|
||||||
tsw = self.asr.ts_words(res)
|
tsw = self.asr.ts_words(res)
|
||||||
|
# insert into HypothesisBuffer
|
||||||
self.transcript_buffer.insert(tsw, self.buffer_time_offset)
|
self.transcript_buffer.insert(tsw, self.buffer_time_offset)
|
||||||
o = self.transcript_buffer.flush()
|
o = self.transcript_buffer.flush()
|
||||||
# Completed words
|
# Completed words
|
||||||
self.commited.extend(o)
|
self.commited.extend(o)
|
||||||
completed = self.to_flush(o)
|
completed = self.concatenate_tsw(o) # This will be returned at the end of the function
|
||||||
logger.debug(f">>>>COMPLETE NOW: {completed[2]}")
|
logger.debug(f">>>>COMPLETE NOW: {completed[2]}")
|
||||||
## The rest is incomplete
|
## The rest is incomplete
|
||||||
the_rest = self.to_flush(self.transcript_buffer.complete())
|
the_rest = self.concatenate_tsw(self.transcript_buffer.complete())
|
||||||
logger.debug(f"INCOMPLETE: {the_rest[2]}")
|
logger.debug(f"INCOMPLETE: {the_rest[2]}")
|
||||||
|
|
||||||
# there is a newly confirmed text
|
# there is a newly confirmed text
|
||||||
|
|
@ -245,7 +245,7 @@ class OnlineASRProcessor:
|
||||||
# we will continue with audio processing at this timestamp
|
# we will continue with audio processing at this timestamp
|
||||||
chunk_at = sents[-2][1]
|
chunk_at = sents[-2][1]
|
||||||
|
|
||||||
logger.debug(f"[Sentence-segmentation]: sentence will be chunked at {chunk_at:2.2f}")
|
|
||||||
self.chunk_at(chunk_at)
|
self.chunk_at(chunk_at)
|
||||||
|
|
||||||
def chunk_completed_segment(self, res):
|
def chunk_completed_segment(self, res):
|
||||||
|
|
@ -275,6 +275,11 @@ class OnlineASRProcessor:
|
||||||
"""trims the hypothesis and audio buffer at "time" """
|
"""trims the hypothesis and audio buffer at "time" """
|
||||||
logger.debug(f"chunking at {time:2.2f}s")
|
logger.debug(f"chunking at {time:2.2f}s")
|
||||||
|
|
||||||
|
logger.debug(
|
||||||
|
f"len of audio buffer before chunking is: {len(self.audio_buffer)/self.SAMPLING_RATE:2.2f}s"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
self.transcript_buffer.pop_commited(time)
|
self.transcript_buffer.pop_commited(time)
|
||||||
cut_seconds = time - self.buffer_time_offset
|
cut_seconds = time - self.buffer_time_offset
|
||||||
self.audio_buffer = self.audio_buffer[int(cut_seconds * self.SAMPLING_RATE) :]
|
self.audio_buffer = self.audio_buffer[int(cut_seconds * self.SAMPLING_RATE) :]
|
||||||
|
|
@ -316,14 +321,14 @@ class OnlineASRProcessor:
|
||||||
Returns: the same format as self.process_iter()
|
Returns: the same format as self.process_iter()
|
||||||
"""
|
"""
|
||||||
o = self.transcript_buffer.complete()
|
o = self.transcript_buffer.complete()
|
||||||
f = self.to_flush(o)
|
f = self.concatenate_tsw(o)
|
||||||
logger.debug(f"last, noncommited: {f[0]*1000:.0f}-{f[1]*1000:.0f}: {f[2]}")
|
logger.debug(f"last, noncommited: {f[0]*1000:.0f}-{f[1]*1000:.0f}: {f[2]}")
|
||||||
self.buffer_time_offset += len(self.audio_buffer) / 16000
|
self.buffer_time_offset += len(self.audio_buffer) / 16000
|
||||||
return f
|
return f
|
||||||
|
|
||||||
def to_flush(
|
def concatenate_tsw(
|
||||||
self,
|
self,
|
||||||
sents,
|
tsw,
|
||||||
sep=None,
|
sep=None,
|
||||||
offset=0,
|
offset=0,
|
||||||
):
|
):
|
||||||
|
|
@ -332,13 +337,14 @@ class OnlineASRProcessor:
|
||||||
# return: (beg1,end-of-last-sentence,"concatenation of sentences") or (None, None, "") if empty
|
# return: (beg1,end-of-last-sentence,"concatenation of sentences") or (None, None, "") if empty
|
||||||
if sep is None:
|
if sep is None:
|
||||||
sep = self.asr.sep
|
sep = self.asr.sep
|
||||||
t = sep.join(s[2] for s in sents)
|
|
||||||
if len(sents) == 0:
|
t = sep.join(s[2] for s in tsw)
|
||||||
|
if len(tsw) == 0:
|
||||||
b = None
|
b = None
|
||||||
e = None
|
e = None
|
||||||
else:
|
else:
|
||||||
b = offset + sents[0][0]
|
b = offset + tsw[0][0]
|
||||||
e = offset + sents[-1][1]
|
e = offset + tsw[-1][1]
|
||||||
return (b, e, t)
|
return (b, e, t)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -125,13 +125,13 @@ async def websocket_endpoint(websocket: WebSocket):
|
||||||
transcription = online.process_iter()[2]
|
transcription = online.process_iter()[2]
|
||||||
full_transcription += transcription
|
full_transcription += transcription
|
||||||
if args.vac:
|
if args.vac:
|
||||||
buffer = online.online.to_flush(
|
buffer = online.online.concatenate_tsw(
|
||||||
online.online.transcript_buffer.buffer
|
online.online.transcript_buffer.buffer
|
||||||
)[
|
)[
|
||||||
2
|
2
|
||||||
] # We need to access the underlying online object to get the buffer
|
] # We need to access the underlying online object to get the buffer
|
||||||
else:
|
else:
|
||||||
buffer = online.to_flush(online.transcript_buffer.buffer)[2]
|
buffer = online.concatenate_tsw(online.transcript_buffer.buffer)[2]
|
||||||
if (
|
if (
|
||||||
buffer in full_transcription
|
buffer in full_transcription
|
||||||
): # With VAC, the buffer is not updated until the next chunk is processed
|
): # With VAC, the buffer is not updated until the next chunk is processed
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue