Compare commits
11 Commits
eos_multi_turn
...
v0.5.1
| Author | SHA1 | Date | |
|---|---|---|---|
| bc070d6688 | |||
| 8e7e329a39 | |||
| 380f07394b | |||
| 30f78a2cc6 | |||
| 01c6bc1ecd | |||
| bdaed45820 | |||
| 4870e9fb9e | |||
| ccb183b4d8 | |||
| fac62aaccc | |||
| aade67736a | |||
| abfe830eee |
@@ -1,5 +1,5 @@
|
|||||||
faster-whisper==1.0.1
|
faster-whisper==1.0.1
|
||||||
torch
|
torch==2.3.0
|
||||||
websockets
|
websockets
|
||||||
onnxruntime==1.16.0
|
onnxruntime==1.16.0
|
||||||
numba
|
numba
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
__version__ = "0.5.0"
|
__version__ = "0.5.1"
|
||||||
|
|||||||
+20
-4
@@ -2,6 +2,7 @@ import os
|
|||||||
import shutil
|
import shutil
|
||||||
import wave
|
import wave
|
||||||
|
|
||||||
|
import logging
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import pyaudio
|
import pyaudio
|
||||||
import threading
|
import threading
|
||||||
@@ -28,7 +29,8 @@ class Client:
|
|||||||
translate=False,
|
translate=False,
|
||||||
model="small",
|
model="small",
|
||||||
srt_file_path="output.srt",
|
srt_file_path="output.srt",
|
||||||
use_vad=True
|
use_vad=True,
|
||||||
|
log_transcription=True
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
Initializes a Client instance for audio recording and streaming to a server.
|
Initializes a Client instance for audio recording and streaming to a server.
|
||||||
@@ -56,11 +58,11 @@ class Client:
|
|||||||
self.use_vad = use_vad
|
self.use_vad = use_vad
|
||||||
self.last_segment = None
|
self.last_segment = None
|
||||||
self.last_received_segment = None
|
self.last_received_segment = None
|
||||||
|
self.log_transcription = log_transcription
|
||||||
|
|
||||||
if translate:
|
if translate:
|
||||||
self.task = "translate"
|
self.task = "translate"
|
||||||
|
|
||||||
self.timestamp_offset = 0.0
|
|
||||||
self.audio_bytes = None
|
self.audio_bytes = None
|
||||||
|
|
||||||
if host is not None and port is not None:
|
if host is not None and port is not None:
|
||||||
@@ -117,6 +119,7 @@ class Client:
|
|||||||
self.last_response_received = time.time()
|
self.last_response_received = time.time()
|
||||||
self.last_received_segment = segments[-1]["text"]
|
self.last_received_segment = segments[-1]["text"]
|
||||||
|
|
||||||
|
if self.log_transcription:
|
||||||
# Truncate to last 3 entries for brevity.
|
# Truncate to last 3 entries for brevity.
|
||||||
text = text[-3:]
|
text = text[-3:]
|
||||||
utils.clear_screen()
|
utils.clear_screen()
|
||||||
@@ -431,6 +434,8 @@ class TranscriptionTeeClient:
|
|||||||
|
|
||||||
def handle_ffmpeg_process(self, process, stream_type):
|
def handle_ffmpeg_process(self, process, stream_type):
|
||||||
print(f"[INFO]: Connecting to {stream_type} stream...")
|
print(f"[INFO]: Connecting to {stream_type} stream...")
|
||||||
|
stderr_thread = threading.Thread(target=self.consume_stderr, args=(process,))
|
||||||
|
stderr_thread.start()
|
||||||
try:
|
try:
|
||||||
# Process the stream
|
# Process the stream
|
||||||
while True:
|
while True:
|
||||||
@@ -477,6 +482,16 @@ class TranscriptionTeeClient:
|
|||||||
|
|
||||||
return process
|
return process
|
||||||
|
|
||||||
|
def consume_stderr(self, process):
|
||||||
|
"""
|
||||||
|
Consume and log the stderr output of a process in a separate thread.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
process (subprocess.Popen): The process whose stderr output will be logged.
|
||||||
|
"""
|
||||||
|
for line in iter(process.stderr.readline, b""):
|
||||||
|
logging.debug(f'[STDERR]: {line.decode()}')
|
||||||
|
|
||||||
def save_chunk(self, n_audio_file):
|
def save_chunk(self, n_audio_file):
|
||||||
"""
|
"""
|
||||||
Saves the current audio frames to a WAV file in a separate thread.
|
Saves the current audio frames to a WAV file in a separate thread.
|
||||||
@@ -664,9 +679,10 @@ class TranscriptionClient(TranscriptionTeeClient):
|
|||||||
use_vad=True,
|
use_vad=True,
|
||||||
save_output_recording=False,
|
save_output_recording=False,
|
||||||
output_recording_filename="./output_recording.wav",
|
output_recording_filename="./output_recording.wav",
|
||||||
output_transcription_path="./output.srt"
|
output_transcription_path="./output.srt",
|
||||||
|
log_transcription=True,
|
||||||
):
|
):
|
||||||
self.client = Client(host, port, lang, translate, model, srt_file_path=output_transcription_path, use_vad=use_vad)
|
self.client = Client(host, port, lang, translate, model, srt_file_path=output_transcription_path, use_vad=use_vad, log_transcription=log_transcription)
|
||||||
if save_output_recording and not output_recording_filename.endswith(".wav"):
|
if save_output_recording and not output_recording_filename.endswith(".wav"):
|
||||||
raise ValueError(f"Please provide a valid `output_recording_filename`: {output_recording_filename}")
|
raise ValueError(f"Please provide a valid `output_recording_filename`: {output_recording_filename}")
|
||||||
if not output_transcription_path.endswith(".srt"):
|
if not output_transcription_path.endswith(".srt"):
|
||||||
|
|||||||
+12
-1
@@ -787,9 +787,15 @@ class ServeClientFasterWhisper(ServeClientBase):
|
|||||||
self.no_speech_thresh = 0.45
|
self.no_speech_thresh = 0.45
|
||||||
|
|
||||||
device = "cuda" if torch.cuda.is_available() else "cpu"
|
device = "cuda" if torch.cuda.is_available() else "cpu"
|
||||||
|
if device == "cuda":
|
||||||
|
major, _ = torch.cuda.get_device_capability(device)
|
||||||
|
self.compute_type = "float16" if major >= 7 else "float32"
|
||||||
|
else:
|
||||||
|
self.compute_type = "int8"
|
||||||
|
|
||||||
if self.model_size_or_path is None:
|
if self.model_size_or_path is None:
|
||||||
return
|
return
|
||||||
|
logging.info(f"Using Device={device} with precision {self.compute_type}")
|
||||||
|
|
||||||
if single_model:
|
if single_model:
|
||||||
if ServeClientFasterWhisper.SINGLE_MODEL is None:
|
if ServeClientFasterWhisper.SINGLE_MODEL is None:
|
||||||
@@ -822,7 +828,7 @@ class ServeClientFasterWhisper(ServeClientBase):
|
|||||||
self.transcriber = WhisperModel(
|
self.transcriber = WhisperModel(
|
||||||
self.model_size_or_path,
|
self.model_size_or_path,
|
||||||
device=device,
|
device=device,
|
||||||
compute_type="int8" if device == "cpu" else "float16",
|
compute_type=self.compute_type,
|
||||||
local_files_only=False,
|
local_files_only=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -973,6 +979,7 @@ class ServeClientFasterWhisper(ServeClientBase):
|
|||||||
|
|
||||||
input_bytes, duration = self.get_audio_chunk_for_processing()
|
input_bytes, duration = self.get_audio_chunk_for_processing()
|
||||||
if duration < 1.0:
|
if duration < 1.0:
|
||||||
|
time.sleep(0.1) # wait for audio chunks to arrive
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
input_sample = input_bytes.copy()
|
input_sample = input_bytes.copy()
|
||||||
@@ -1031,6 +1038,8 @@ class ServeClientFasterWhisper(ServeClientBase):
|
|||||||
"""
|
"""
|
||||||
offset = None
|
offset = None
|
||||||
self.current_out = ''
|
self.current_out = ''
|
||||||
|
last_segment = None
|
||||||
|
|
||||||
# process complete segments
|
# process complete segments
|
||||||
if len(segments) > 1:
|
if len(segments) > 1:
|
||||||
for i, s in enumerate(segments[:-1]):
|
for i, s in enumerate(segments[:-1]):
|
||||||
@@ -1046,6 +1055,8 @@ class ServeClientFasterWhisper(ServeClientBase):
|
|||||||
self.transcript.append(self.format_segment(start, end, text_))
|
self.transcript.append(self.format_segment(start, end, text_))
|
||||||
offset = min(duration, s.end)
|
offset = min(duration, s.end)
|
||||||
|
|
||||||
|
# only process the segments if it satisfies the no_speech_thresh
|
||||||
|
if segments[-1].no_speech_prob <= self.no_speech_thresh:
|
||||||
self.current_out += segments[-1].text
|
self.current_out += segments[-1].text
|
||||||
last_segment = self.format_segment(
|
last_segment = self.format_segment(
|
||||||
self.timestamp_offset + segments[-1].start,
|
self.timestamp_offset + segments[-1].start,
|
||||||
|
|||||||
Reference in New Issue
Block a user