Skip to content

Commit

Permalink
add transcription loop
Browse files Browse the repository at this point in the history
  • Loading branch information
dimastatz committed May 4, 2024
1 parent 64e4d70 commit 61095a3
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions python/deepsignal/transcription/transcriber.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
""" Implements Transcriber Worker for RT cases"""
import time
from queue import Queue
from typing import Callable
Expand All @@ -6,9 +7,12 @@


class Transcriber:
"""Implements Transcriber Worker for RT cases"""

def __init__(
self, model: Whisper, callback: Callable[[str, bool], None], max_size=1000
) -> None:
"""ctor"""
self.model = model
self.queue = Queue[bytes](max_size)
self.worker = Thread(target=self._transcribe_loop)
Expand All @@ -21,12 +25,15 @@ def __init__(
self.started = True

def add_chunk(self, chunk: bytes) -> None:
"""add new audio chunk"""
self.queue.put(chunk)

def stop(self) -> None:
"""stop transcription loop"""
self.started = False

def _transcribe_loop(self):
"""background transcription job"""
while self.started:
while self.queue.not_empty:
self.window.append(self.queue.get_nowait())
Expand Down

0 comments on commit 61095a3

Please sign in to comment.