Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 076aebf3b6 | |||
| a7eedc5d84 | |||
| d91330d790 | |||
| 783d147316 | |||
| 058c93e55e | |||
| 2300eedc8b | |||
| cafcb04fbc | |||
| 72ead71eeb | |||
| 7b2f5cff72 | |||
| 32c6a565d7 | |||
| e30286c046 | |||
| e92ddd291a |
@@ -1 +1 @@
|
||||
__version__="0.0.10"
|
||||
__version__="0.0.11"
|
||||
|
||||
@@ -412,7 +412,7 @@ class Client:
|
||||
for _ in range(0, int(self.rate / self.chunk * self.record_seconds)):
|
||||
if not self.recording:
|
||||
break
|
||||
data = self.stream.read(self.chunk)
|
||||
data = self.stream.read(self.chunk, exception_on_overflow = False)
|
||||
self.frames += data
|
||||
|
||||
audio_array = Client.bytes_to_float_array(data)
|
||||
|
||||
+33
-30
@@ -102,7 +102,9 @@ class TranscriptionServer:
|
||||
language=options["language"],
|
||||
task=options["task"],
|
||||
client_uid=options["uid"],
|
||||
model_size=options["model_size"]
|
||||
model_size=options["model_size"],
|
||||
initial_prompt=options.get("initial_prompt"),
|
||||
vad_parameters=options.get("vad_parameters")
|
||||
)
|
||||
|
||||
self.clients[websocket] = client
|
||||
@@ -118,7 +120,7 @@ class TranscriptionServer:
|
||||
elapsed_time = time.time() - self.clients_start_time[websocket]
|
||||
if elapsed_time >= self.max_connection_time:
|
||||
self.clients[websocket].disconnect()
|
||||
logging.warning(f"{self.clients[websocket]} Client disconnected due to overtime.")
|
||||
logging.warning(f"Client with uid '{self.clients[websocket].client_uid}' disconnected due to overtime.")
|
||||
self.clients[websocket].cleanup()
|
||||
self.clients.pop(websocket)
|
||||
self.clients_start_time.pop(websocket)
|
||||
@@ -127,13 +129,11 @@ class TranscriptionServer:
|
||||
break
|
||||
|
||||
except Exception as e:
|
||||
logging.error(e)
|
||||
logging.info(f"[ERROR]: Client with uid '{self.clients[websocket].client_uid}' Disconnected.")
|
||||
if self.clients[websocket].model_size is not None:
|
||||
self.clients[websocket].cleanup()
|
||||
self.clients.pop(websocket)
|
||||
self.clients_start_time.pop(websocket)
|
||||
logging.info("Connection Closed.")
|
||||
logging.info(self.clients)
|
||||
del websocket
|
||||
break
|
||||
|
||||
@@ -190,7 +190,9 @@ class ServeClient:
|
||||
multilingual=False,
|
||||
language=None,
|
||||
client_uid=None,
|
||||
model_size="small"
|
||||
model_size="small",
|
||||
initial_prompt=None,
|
||||
vad_parameters=None
|
||||
):
|
||||
"""
|
||||
Initialize a ServeClient instance.
|
||||
@@ -218,6 +220,8 @@ class ServeClient:
|
||||
self.language = language if self.multilingual else "en"
|
||||
self.task = task
|
||||
self.websocket = websocket
|
||||
self.initial_prompt = initial_prompt
|
||||
self.vad_parameters = vad_parameters or {"threshold": 0.5}
|
||||
|
||||
device = "cuda" if torch.cuda.is_available() else "cpu"
|
||||
|
||||
@@ -352,11 +356,11 @@ class ServeClient:
|
||||
# whisper transcribe with prompt
|
||||
result, info = self.transcriber.transcribe(
|
||||
input_sample,
|
||||
initial_prompt=None,
|
||||
initial_prompt=self.initial_prompt,
|
||||
language=self.language,
|
||||
task=self.task,
|
||||
vad_filter=True,
|
||||
vad_parameters={"threshold": 0.5}
|
||||
vad_parameters=self.vad_parameters
|
||||
)
|
||||
|
||||
if self.language is None:
|
||||
@@ -401,12 +405,20 @@ class ServeClient:
|
||||
})
|
||||
)
|
||||
except Exception as e:
|
||||
logging.error(f"[ERROR]: {e}")
|
||||
logging.error(f"[ERROR]: Failed to send message to client: {e}")
|
||||
|
||||
except Exception as e:
|
||||
logging.error(f"[ERROR]: {e}")
|
||||
logging.error(f"[ERROR]: Failed to transcribe audio chunk: {e}")
|
||||
time.sleep(0.01)
|
||||
|
||||
def format_segment(self, start, end, text):
|
||||
"""Helper function to format a segment with string timestamps."""
|
||||
return {
|
||||
'start': "{:.3f}".format(start),
|
||||
'end': "{:.3f}".format(end),
|
||||
'text': text
|
||||
}
|
||||
|
||||
def update_segments(self, segments, duration):
|
||||
"""
|
||||
Processes the segments from whisper. Appends all the segments to the list
|
||||
@@ -437,22 +449,16 @@ class ServeClient:
|
||||
text_ = s.text
|
||||
self.text.append(text_)
|
||||
start, end = self.timestamp_offset + s.start, self.timestamp_offset + min(duration, s.end)
|
||||
self.transcript.append(
|
||||
{
|
||||
'start': start,
|
||||
'end': end,
|
||||
'text': text_
|
||||
}
|
||||
)
|
||||
self.transcript.append(self.format_segment(start, end, text_))
|
||||
|
||||
offset = min(duration, s.end)
|
||||
|
||||
self.current_out += segments[-1].text
|
||||
last_segment = {
|
||||
'start': self.timestamp_offset + segments[-1].start,
|
||||
'end': self.timestamp_offset + min(duration, segments[-1].end),
|
||||
'text': self.current_out
|
||||
}
|
||||
last_segment = self.format_segment(
|
||||
self.timestamp_offset + segments[-1].start,
|
||||
self.timestamp_offset + min(duration, segments[-1].end),
|
||||
self.current_out
|
||||
)
|
||||
|
||||
# if same incomplete segment is seen multiple times then update the offset
|
||||
# and append the segment to the list
|
||||
@@ -464,13 +470,11 @@ class ServeClient:
|
||||
if self.same_output_threshold > 5:
|
||||
if not len(self.text) or self.text[-1].strip().lower()!=self.current_out.strip().lower():
|
||||
self.text.append(self.current_out)
|
||||
self.transcript.append(
|
||||
{
|
||||
'start': self.timestamp_offset,
|
||||
'end': self.timestamp_offset + duration,
|
||||
'text': self.current_out
|
||||
}
|
||||
)
|
||||
self.transcript.append(self.format_segment(
|
||||
self.timestamp_offset,
|
||||
self.timestamp_offset + duration,
|
||||
self.current_out
|
||||
))
|
||||
self.current_out = ''
|
||||
offset = duration
|
||||
self.same_output_threshold = 0
|
||||
@@ -512,4 +516,3 @@ class ServeClient:
|
||||
"""
|
||||
logging.info("Cleaning up.")
|
||||
self.exit = True
|
||||
self.transcriber.destroy()
|
||||
|
||||
@@ -934,9 +934,6 @@ class WhisperModel:
|
||||
)
|
||||
]
|
||||
|
||||
def destroy(self):
|
||||
del self.model
|
||||
|
||||
|
||||
def restore_speech_timestamps(
|
||||
segments: Iterable[Segment],
|
||||
|
||||
Reference in New Issue
Block a user