Add custom vocabulary / hotwords support

This commit is contained in:
Aaron Boxer
2026-04-17 09:36:05 -04:00
committed by Aaron Boxer
parent 9a71a95ca8
commit 4210697ca6
4 changed files with 16 additions and 4 deletions
+1
View File
@@ -55,6 +55,7 @@ class TestClientCallbacks(BaseTestCase):
"same_output_threshold": 10, "same_output_threshold": 10,
"enable_translation": False, "enable_translation": False,
"target_language": "fr", "target_language": "fr",
"hotwords": None,
}) })
self.client.on_open(self.mock_ws_app) self.client.on_open(self.mock_ws_app)
self.mock_ws_app.send.assert_called_with(expected_message) self.mock_ws_app.send.assert_called_with(expected_message)
@@ -34,6 +34,7 @@ class ServeClientFasterWhisper(ServeClientBase):
same_output_threshold=7, same_output_threshold=7,
cache_path="~/.cache/whisper-live/", cache_path="~/.cache/whisper-live/",
translation_queue=None, translation_queue=None,
hotwords=None,
): ):
""" """
Initialize a ServeClient instance. Initialize a ServeClient instance.
@@ -78,6 +79,7 @@ class ServeClientFasterWhisper(ServeClientBase):
self.task = task self.task = task
self.initial_prompt = initial_prompt self.initial_prompt = initial_prompt
self.vad_parameters = vad_parameters or {"threshold": 0.5} self.vad_parameters = vad_parameters or {"threshold": 0.5}
self.hotwords = hotwords
device = "cuda" if torch.cuda.is_available() else "cpu" device = "cuda" if torch.cuda.is_available() else "cpu"
if device == "cuda": if device == "cuda":
@@ -231,7 +233,8 @@ class ServeClientFasterWhisper(ServeClientBase):
language=self.language, language=self.language,
task=self.task, task=self.task,
vad_filter=self.use_vad, vad_filter=self.use_vad,
vad_parameters=self.vad_parameters if self.use_vad else None) vad_parameters=self.vad_parameters if self.use_vad else None,
hotwords=self.hotwords)
if ServeClientFasterWhisper.SINGLE_MODEL: if ServeClientFasterWhisper.SINGLE_MODEL:
ServeClientFasterWhisper.SINGLE_MODEL_LOCK.release() ServeClientFasterWhisper.SINGLE_MODEL_LOCK.release()
+5
View File
@@ -43,6 +43,7 @@ class Client:
translation_srt_file_path="output_translated.srt", translation_srt_file_path="output_translated.srt",
enable_timestamps=False, enable_timestamps=False,
display_segments=4, display_segments=4,
hotwords=None,
): ):
""" """
Initializes a Client instance for audio recording and streaming to a server. Initializes a Client instance for audio recording and streaming to a server.
@@ -101,6 +102,7 @@ class Client:
self.task = "translate" self.task = "translate"
self.enable_timestamps = enable_timestamps self.enable_timestamps = enable_timestamps
self.display_segments = display_segments self.display_segments = display_segments
self.hotwords = hotwords
self.audio_bytes = None self.audio_bytes = None
@@ -299,6 +301,7 @@ class Client:
"same_output_threshold": self.same_output_threshold, "same_output_threshold": self.same_output_threshold,
"enable_translation": self.enable_translation, "enable_translation": self.enable_translation,
"target_language": self.target_language, "target_language": self.target_language,
"hotwords": self.hotwords,
} }
) )
) )
@@ -820,6 +823,7 @@ class TranscriptionClient(TranscriptionTeeClient):
translation_srt_file_path="./output_translated.srt", translation_srt_file_path="./output_translated.srt",
enable_timestamps=False, enable_timestamps=False,
display_segments=4, display_segments=4,
hotwords=None,
): ):
self.client = Client( self.client = Client(
host, host,
@@ -842,6 +846,7 @@ class TranscriptionClient(TranscriptionTeeClient):
translation_srt_file_path=translation_srt_file_path, translation_srt_file_path=translation_srt_file_path,
enable_timestamps=enable_timestamps, enable_timestamps=enable_timestamps,
display_segments=display_segments, display_segments=display_segments,
hotwords=hotwords,
) )
if save_output_recording and not output_recording_filename.endswith(".wav"): if save_output_recording and not output_recording_filename.endswith(".wav"):
+6 -3
View File
@@ -288,7 +288,8 @@ class TranscriptionServer:
clip_audio=options.get("clip_audio", False), clip_audio=options.get("clip_audio", False),
same_output_threshold=options.get("same_output_threshold", 10), same_output_threshold=options.get("same_output_threshold", 10),
cache_path=self.cache_path, cache_path=self.cache_path,
translation_queue=translation_queue translation_queue=translation_queue,
hotwords=options.get("hotwords"),
) )
logging.info("Running faster_whisper backend.") logging.info("Running faster_whisper backend.")
@@ -533,7 +534,8 @@ class TranscriptionServer:
include: Optional[List[str]] = Form(default=None), include: Optional[List[str]] = Form(default=None),
known_speaker_names: Optional[List[str]] = Form(default=None), known_speaker_names: Optional[List[str]] = Form(default=None),
known_speaker_references: Optional[List[str]] = Form(default=None), known_speaker_references: Optional[List[str]] = Form(default=None),
stream: bool = Form(default=False) stream: bool = Form(default=False),
hotwords: Optional[str] = Form(default=None),
): ):
if stream: if stream:
return JSONResponse({"error": "Streaming not supported in this backend."}, status_code=400) return JSONResponse({"error": "Streaming not supported in this backend."}, status_code=400)
@@ -564,7 +566,8 @@ class TranscriptionServer:
initial_prompt=prompt, initial_prompt=prompt,
temperature=temperature, temperature=temperature,
vad_filter=False, vad_filter=False,
word_timestamps=(timestamp_granularities and "word" in timestamp_granularities) word_timestamps=(timestamp_granularities and "word" in timestamp_granularities),
hotwords=hotwords,
) )
text = " ".join([s.text.strip() for s in segments]) text = " ".join([s.text.strip() for s in segments])