feat: implement custom segmentation for Japanese language and update default source language

This commit is contained in:
lml committed 2026-03-20 19:47:25 +08:00
1 parent 63dc75946e
commit b20656d6c0
3 files changed
+18 -30

No files matched your search

+15 -11
View File
@@ -200,6 +200,10 @@ def build_segmentation_options(
return options
def should_apply_custom_segmentation(language: Optional[str]) -> bool:
return language == "ja"
def load_wav_pcm_s16le(path: str) -> np.ndarray:
with wave.open(path, "rb") as wav_file:
channels = wav_file.getnchannels()
@@ -971,9 +975,6 @@ class WhisperXWorker:
self.clear_device_resources(device="cuda")
detected_language = str(result.get("language") or language or "unknown")
segmentation_options = build_segmentation_options(
detected_language, segmentation_overrides
)
normalized_segments = normalize_segments(result.get("segments"))
if not no_align and normalized_segments:
@@ -998,14 +999,17 @@ class WhisperXWorker:
del align_model
self.clear_device_resources(device="cuda")
detected_language = str(aligned.get("language") or detected_language)
segmentation_options = build_segmentation_options(
detected_language, segmentation_overrides
)
normalized_segments = normalize_transcript_segments(
aligned.get("segments"),
detected_language,
segmentation_options,
)
if should_apply_custom_segmentation(detected_language):
segmentation_options = build_segmentation_options(
detected_language, segmentation_overrides
)
normalized_segments = normalize_transcript_segments(
aligned.get("segments"),
detected_language,
segmentation_options,
)
else:
normalized_segments = normalize_segments(aligned.get("segments"))
emit_status(request_id, "finalizing")
emit_progress(request_id, 96)
+1 -17
View File
@@ -254,24 +254,8 @@ class WhisperService {
'min_split_chars': 6,
'prefer_punctuation_split': true,
};
case 'zh':
return const <String, dynamic>{
'split_on_pause': true,
'pause_threshold_sec': 0.6,
'max_segment_duration_sec': 4.2,
'max_segment_chars': 26,
'min_split_chars': 4,
'prefer_punctuation_split': true,
};
default:
return const <String, dynamic>{
'split_on_pause': true,
'pause_threshold_sec': 0.8,
'max_segment_duration_sec': 6.0,
'max_segment_chars': 42,
'min_split_chars': 10,
'prefer_punctuation_split': true,
};
return const <String, dynamic>{};
}
}
+2 -2
View File
@@ -47,7 +47,7 @@ class HomePage extends StatefulWidget {
class _HomePageState extends State<HomePage> {
String _selectedModel = AppConstants.defaultWhisperModel;
String _sourceVideoLanguage = 'en';
String _sourceVideoLanguage = 'ja';
String _targetLanguage = 'zh';
String _apiKey = '';
String _targetModel = 'gemini-2.5-flash-lite';
@@ -147,7 +147,7 @@ class _HomePageState extends State<HomePage> {
providerId: _llmProvider,
apiKey: _apiKey,
baseUrl: _llmBaseUrl,
sourceLanguage: 'en', // dummy
sourceLanguage: 'ja', // dummy
targetLanguage: 'zh', // dummy
),
);