forked from wlkns-dev/stimmwerk
Melodie- und Text-Import aus Gesangsspur mit Whisper-Ankern
- extract-Befehl: Noten aus der Gesangsspur (YIN), Teilen an Energie- Einbrüchen, Silben aus dem Liedtext, Zuordnung per Dynamic Programming - Whisper-Wortzeiten als Anker (tools/transcribe_words.py, align_words.py) über die vorhandene faster-whisper-Umgebung - Prüfbericht und Plausibilitätskennzahlen, --set für Parameter - Test: alle Charts laden, Audio passt zusammen - Chart "What Made Me"; Audiodateien bleiben per .gitignore draußen Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
79
src/main.rs
79
src/main.rs
@ -2,6 +2,7 @@ mod audio;
|
||||
mod calib;
|
||||
mod chart;
|
||||
mod config;
|
||||
mod import;
|
||||
mod pitch;
|
||||
mod review;
|
||||
mod score;
|
||||
@ -9,7 +10,85 @@ mod session;
|
||||
mod ui;
|
||||
mod voice;
|
||||
|
||||
/// `singtrainer extract <gesangsspur> --out <chart.toml> [--title T] [--backing P] [--vocals P] [--lyrics datei.txt [--anchors wortzeiten.json]]`:
|
||||
/// leitet aus einer isolierten Gesangsspur einen Chart-Entwurf ab (ohne Oberfläche).
|
||||
fn extract_cli(args: &[String]) -> Result<(), String> {
|
||||
let mut it = args.iter();
|
||||
let input = it.next().ok_or("Gesangsspur angeben")?;
|
||||
let (mut out, mut title, mut backing, mut vocals, mut lyrics, mut anchors) =
|
||||
(None, None, None, None, None, None);
|
||||
let mut overrides: Vec<(String, f64)> = Vec::new();
|
||||
while let Some(a) = it.next() {
|
||||
let val = it.next().cloned();
|
||||
match a.as_str() {
|
||||
"--out" => out = val,
|
||||
"--title" => title = val,
|
||||
"--backing" => backing = val,
|
||||
"--vocals" => vocals = val,
|
||||
"--lyrics" => lyrics = val,
|
||||
"--anchors" => anchors = val,
|
||||
// Zum Ausprobieren: --set <import-parameter>=<wert> (Namen wie in [import] der Config).
|
||||
"--set" => {
|
||||
let v = val.ok_or("--set braucht name=wert")?;
|
||||
let (k, x) = v.split_once('=').ok_or("--set braucht name=wert")?;
|
||||
overrides.push((
|
||||
k.to_string(),
|
||||
x.parse().map_err(|_| format!("Ungültiger Wert: {v}"))?,
|
||||
));
|
||||
}
|
||||
other => return Err(format!("Unbekannte Option {other}")),
|
||||
}
|
||||
}
|
||||
let out = out.ok_or("--out <chart.toml> fehlt")?;
|
||||
let mut cfg = config::Config::load();
|
||||
for (k, v) in &overrides {
|
||||
cfg.import.set(k, *v)?;
|
||||
}
|
||||
let input = std::path::Path::new(input);
|
||||
let notes = match lyrics {
|
||||
Some(path) => {
|
||||
let text = std::fs::read_to_string(&path).map_err(|e| format!("{path}: {e}"))?;
|
||||
let anchor_file = anchors
|
||||
.map(|p| import::anchors::load(std::path::Path::new(&p)))
|
||||
.transpose()
|
||||
.map_err(|e| format!("Anker: {e:#}"))?;
|
||||
let r = import::import_with_lyrics(
|
||||
input,
|
||||
&text,
|
||||
anchor_file.as_ref(),
|
||||
&cfg.pitch,
|
||||
&cfg.import,
|
||||
)
|
||||
.map_err(|e| format!("{e:#}"))?;
|
||||
print!("{}", r.report);
|
||||
r.notes
|
||||
}
|
||||
None => {
|
||||
let frames = import::analyze_file(input, &cfg.pitch).map_err(|e| format!("{e:#}"))?;
|
||||
import::segment_notes(&frames, &cfg.import)
|
||||
}
|
||||
};
|
||||
let chart = import::build_chart(
|
||||
&title.unwrap_or_else(|| "Import".into()),
|
||||
notes,
|
||||
backing.map(Into::into),
|
||||
vocals.map(Into::into),
|
||||
);
|
||||
let text = toml::to_string_pretty(&chart).map_err(|e| e.to_string())?;
|
||||
std::fs::write(&out, text).map_err(|e| format!("{out}: {e}"))?;
|
||||
println!("{out}: {}", import::summary(&chart));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn main() -> eframe::Result {
|
||||
let args: Vec<String> = std::env::args().skip(1).collect();
|
||||
if args.first().map(String::as_str) == Some("extract") {
|
||||
if let Err(e) = extract_cli(&args[1..]) {
|
||||
eprintln!("Fehler: {e}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
// `--sim`: künstlicher Pitch-Verlauf ohne Audiogerät (Entwicklung ohne Mikrofon).
|
||||
// `--autostart`: wechselt in den Chart-Modus und startet die Session sofort.
|
||||
let sim = std::env::args().any(|a| a == "--sim");
|
||||
|
||||
Reference in New Issue
Block a user