Make initial_prompt and vad_parameters accessible from the client

Expose initial_prompt and vad_parameters as flat client parameters
(consistent with hotwords, send_last_n_segments, etc.), send them as
flat handshake keys, and read them server-side with null-safe
options.get(...). Supersedes #283; avoids the options-bag None.get crash.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Aaron Boxer
2026-06-26 11:05:26 -04:00
committed by Aaron Boxer
parent 9f7a043d8b
commit 2debc0ee80
2 changed files with 15 additions and 0 deletions
+1
View File
@@ -168,6 +168,7 @@ client = TranscriptionClient(
mute_audio_playback=False, # Only used for file input, False by Default mute_audio_playback=False, # Only used for file input, False by Default
enable_translation=True, enable_translation=True,
target_language="hi", target_language="hi",
initial_prompt=None, # Add context for the model, e.g. 'Jane Doe context'
) )
``` ```
It connects to the server running on localhost at port 9090. Using a multilingual model, language for the transcription will be automatically detected. You can also use the language option to specify the target language for the transcription, in this case, English ("en"). The translate option should be set to `True` if we want to translate from the source language to English and `False` if we want to transcribe in the source language. It connects to the server running on localhost at port 9090. Using a multilingual model, language for the transcription will be automatically detected. You can also use the language option to specify the target language for the transcription, in this case, English ("en"). The translate option should be set to `True` if we want to translate from the source language to English and `False` if we want to transcribe in the source language.
+14
View File
@@ -49,6 +49,8 @@ class Client:
word_timestamps=False, word_timestamps=False,
max_retries=0, max_retries=0,
retry_delay=5, retry_delay=5,
initial_prompt=None,
vad_parameters=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.
@@ -75,6 +77,8 @@ class Client:
target_language (str, optional): Target language for translation. Defaults to 'fr'. target_language (str, optional): Target language for translation. Defaults to 'fr'.
translation_callback (callable, optional): A callback function to handle translation results. Default is None. translation_callback (callable, optional): A callback function to handle translation results. Default is None.
translation_srt_file_path (str, optional): The file path to save the translated output SRT file. Default is "output_translated.srt". translation_srt_file_path (str, optional): The file path to save the translated output SRT file. Default is "output_translated.srt".
initial_prompt (str, optional): Optional text to provide context to the model (e.g. domain vocabulary or names). Default is None.
vad_parameters (dict, optional): Optional voice-activity-detection parameters passed to the server backend. Default is None.
""" """
self.recording = False self.recording = False
self.task = "transcribe" self.task = "transcribe"
@@ -103,6 +107,10 @@ class Client:
self.translation_callback = translation_callback self.translation_callback = translation_callback
self.translation_srt_file_path = translation_srt_file_path self.translation_srt_file_path = translation_srt_file_path
self.last_translated_segment = None self.last_translated_segment = None
self.initial_prompt = initial_prompt
self.vad_parameters = vad_parameters
if translate: if translate:
self.task = "translate" self.task = "translate"
self.enable_timestamps = enable_timestamps self.enable_timestamps = enable_timestamps
@@ -330,6 +338,8 @@ class Client:
"enable_diarization": self.enable_diarization, "enable_diarization": self.enable_diarization,
"max_speakers": self.max_speakers, "max_speakers": self.max_speakers,
"word_timestamps": self.word_timestamps, "word_timestamps": self.word_timestamps,
"initial_prompt": self.initial_prompt,
"vad_parameters": self.vad_parameters,
} }
) )
) )
@@ -855,6 +865,8 @@ class TranscriptionClient(TranscriptionTeeClient):
enable_diarization=False, enable_diarization=False,
max_speakers=10, max_speakers=10,
word_timestamps=False, word_timestamps=False,
initial_prompt=None,
vad_parameters=None,
): ):
self.client = Client( self.client = Client(
@@ -882,6 +894,8 @@ class TranscriptionClient(TranscriptionTeeClient):
enable_diarization=enable_diarization, enable_diarization=enable_diarization,
max_speakers=max_speakers, max_speakers=max_speakers,
word_timestamps=word_timestamps, word_timestamps=word_timestamps,
initial_prompt=initial_prompt,
vad_parameters=vad_parameters,
) )
if save_output_recording and not output_recording_filename.endswith(".wav"): if save_output_recording and not output_recording_filename.endswith(".wav"):