Allow partial transcription when streaming
This commit is contained in:
parent
db2b6d956b
commit
72347d5d47
@ -62,14 +62,18 @@ class Inference:
|
||||
for block in stream:
|
||||
if len(block.shape) > 1:
|
||||
block = speech[:, 0] + speech[:, 1]
|
||||
block_inference = self.buffer_to_text(block)
|
||||
transcript += block_inference.transcript + " "
|
||||
processing_time += block_inference.processing_time_sec
|
||||
if block_inference.confidence_score is not None:
|
||||
if confidence is None:
|
||||
confidence = block_inference.confidence_score
|
||||
else:
|
||||
confidence *= block_inference.confidence_score
|
||||
try:
|
||||
block_inference = self.buffer_to_text(block)
|
||||
transcript += block_inference.transcript + " "
|
||||
processing_time += block_inference.processing_time_sec
|
||||
if block_inference.confidence_score is not None:
|
||||
if confidence is None:
|
||||
confidence = block_inference.confidence_score
|
||||
else:
|
||||
confidence *= block_inference.confidence_score
|
||||
except torch.OutOfMemoryError as e:
|
||||
print(e)
|
||||
break
|
||||
return InferredTranscript(transcript.strip(), confidence, processing_time)
|
||||
|
||||
def file_to_text(self, audio_file: typing.BinaryIO) -> InferredTranscript:
|
||||
|
Loading…
x
Reference in New Issue
Block a user