[refactor] remove feature flags and simplify native whisper integration

This commit is contained in:
2025-08-08 09:07:09 +02:00
parent a6009693ef
commit f991a47b5b
3 changed files with 6 additions and 21 deletions

View File

@@ -12,8 +12,4 @@ toml = "0.8"
chrono = { version = "0.4", features = ["clock"] }
reqwest = { version = "0.12", features = ["blocking", "json"] }
sha2 = "0.10"
whisper-rs = { git = "https://github.com/tazz4843/whisper-rs", optional = true }
[features]
default = ["native-whisper"]
native-whisper = ["whisper-rs"]
whisper-rs = { git = "https://github.com/tazz4843/whisper-rs" }

View File

@@ -1,4 +1,4 @@
- update the project to no more use features
- [x] update the project to no more use features
- update last_model to be only used during one run
- rename project to "PolyScribe"

View File

@@ -9,7 +9,6 @@ use clap::Parser;
use serde::{Deserialize, Serialize};
use chrono::Local;
#[cfg(feature = "native-whisper")]
use whisper_rs::{FullParams, SamplingStrategy, WhisperContext, WhisperContextParameters};
mod models;
@@ -138,7 +137,6 @@ fn normalize_lang_code(input: &str) -> Option<String> {
#[cfg(feature = "native-whisper")]
fn find_model_file() -> Result<PathBuf> {
let models_dir = Path::new("models");
if !models_dir.exists() {
@@ -245,7 +243,6 @@ fn find_model_file() -> Result<PathBuf> {
Ok(chosen)
}
#[cfg(feature = "native-whisper")]
fn decode_audio_to_pcm_f32_ffmpeg(audio_path: &Path) -> Result<Vec<f32>> {
let output = Command::new("ffmpeg")
.arg("-i").arg(audio_path)
@@ -282,7 +279,6 @@ fn decode_audio_to_pcm_f32_ffmpeg(audio_path: &Path) -> Result<Vec<f32>> {
}
}
#[cfg(feature = "native-whisper")]
fn transcribe_native(audio_path: &Path, speaker: &str, lang_opt: Option<&str>) -> Result<Vec<OutputEntry>> {
let pcm = decode_audio_to_pcm_f32_ffmpeg(audio_path)?;
let model = find_model_file()?;
@@ -389,18 +385,11 @@ fn main() -> Result<()> {
let mut buf = String::new();
if is_audio_file(path) {
#[cfg(feature = "native-whisper")]
{
let items = transcribe_native(path, &speaker, lang_hint.as_deref())?;
for e in items {
entries.push(e);
}
continue;
}
#[cfg(not(feature = "native-whisper"))]
{
return Err(anyhow!("Python transcription has been removed. Please build with --features native-whisper to transcribe audio."));
let items = transcribe_native(path, &speaker, lang_hint.as_deref())?;
for e in items {
entries.push(e);
}
continue;
} else if is_json_file(path) {
File::open(path)
.with_context(|| format!("Failed to open: {}", input_path))?