Function bodies 57 total
prepare_input function · rust · L139-L181 (43 LOC)src/transcribe.rs
fn prepare_input(
config: &AppConfig,
request: &TranscribeRequest,
timeout: Duration,
) -> Result<(PathBuf, Option<tempfile::NamedTempFile>)> {
let use_conversion = if request.no_convert {
false
} else {
config.convert
};
if !use_conversion {
return Ok((request.input.clone(), None));
}
let temp_wav = Builder::new()
.prefix("whisperx-")
.suffix(".wav")
.tempfile()
.context("failed to create temporary WAV file")?;
let mut ffmpeg = Command::new(&config.ffmpeg_bin);
ffmpeg
.arg("-nostdin")
.arg("-y")
.arg("-i")
.arg(&request.input)
.arg("-ar")
.arg("16000")
.arg("-ac")
.arg("1")
.arg("-c:a")
.arg("pcm_s16le")
.arg(temp_wav.path())
.stdin(Stdio::null())
.stdout(Stdio::piped())
.stderr(Stdio::piped());
run_with_timeout(ffmpeg, timeout, "ffmpeg")?;
Ok((temp_wav.path().toadd_friendly_flags function · rust · L182-L203 (22 LOC)src/transcribe.rs
fn add_friendly_flags(command: &mut Command, config: &AppConfig, request: &TranscribeRequest) {
if !has_passthrough_flag(&request.passthrough, &["-t", "--threads"]) {
let threads = request.threads.unwrap_or(config.threads);
command.arg("-t").arg(threads.to_string());
}
if !has_passthrough_flag(&request.passthrough, &["-l", "--language"]) {
let language = request.language.as_deref().unwrap_or(&config.language);
if !language.eq_ignore_ascii_case("auto") {
command.arg("-l").arg(language);
}
}
if request.translate && !has_passthrough_flag(&request.passthrough, &["--translate"]) {
command.arg("--translate");
}
if request.no_timestamps && !has_passthrough_flag(&request.passthrough, &["-nt", "--no-timestamps"]) {
command.arg("-nt");
}
}add_output_flag function · rust · L204-L220 (17 LOC)src/transcribe.rs
fn add_output_flag(command: &mut Command, format: OutputFormat) {
match format {
OutputFormat::Txt => {
command.arg("-otxt");
}
OutputFormat::Json => {
command.arg("-oj");
}
OutputFormat::Srt => {
command.arg("-osrt");
}
OutputFormat::Vtt => {
command.arg("-ovtt");
}
};
}output_file_path function · rust · L221-L231 (11 LOC)src/transcribe.rs
fn output_file_path(output_dir: &TempDir, format: OutputFormat) -> PathBuf {
let ext = match format {
OutputFormat::Txt => "txt",
OutputFormat::Json => "json",
OutputFormat::Srt => "srt",
OutputFormat::Vtt => "vtt",
};
output_dir.path().join(format!("whisperx-output.{ext}"))
}print_output function · rust · L232-L245 (14 LOC)src/transcribe.rs
fn print_output(format: OutputFormat, content: &str) {
match format {
OutputFormat::Txt => {
println!("{}", content.trim_end());
}
OutputFormat::Json | OutputFormat::Srt | OutputFormat::Vtt => {
print!("{content}");
if !content.ends_with('\n') {
println!();
}
}
}
}run_with_timeout function · rust · L250-L278 (29 LOC)src/transcribe.rs
fn run_with_timeout(mut command: Command, timeout: Duration, label: &str) -> Result<Output> {
let mut child = command
.spawn()
.with_context(|| format!("failed to start {label}"))?;
let status = match child
.wait_timeout(timeout)
.with_context(|| format!("failed waiting for {label}"))?
{
Some(status) => status,
None => {
let _ = child.kill();
let _ = child.wait();
bail!("{label} timed out after {} seconds", timeout.as_secs());
}
};
let output = child
.wait_with_output()
.with_context(|| format!("failed collecting {label} output"))?;
if !status.success() {
let stderr = String::from_utf8_lossy(&output.stderr).trim().to_string();
bail!("{label} failed: {stderr}");
}
Ok(output)
}extract_transcript_from_stdout function · rust · L279-L306 (28 LOC)src/transcribe.rs
fn extract_transcript_from_stdout(stdout: &str) -> String {
let mut lines = Vec::new();
for line in stdout.lines() {
let trimmed = line.trim();
if trimmed.is_empty() || trimmed.starts_with("main:") {
continue;
}
if trimmed.starts_with('[')
&& let Some((_, rest)) = trimmed.split_once(']')
{
let text = rest.trim();
if !text.is_empty() {
lines.push(text.to_string());
}
continue;
}
if !trimmed.contains("->") {
lines.push(trimmed.to_string());
}
}
lines.join(" ")
}‹ prevpage 2 / 2