forked from wlkns-dev/stimmwerk
Passagen, Übungsmodus, Stimmfinder-Überarbeitung, Gerätedesign, Metronom und Akkorde
- Passagenwahl, Original-Kurve, Spulen/Üben und Pause - Startseite, Klartext-Oberfläche, Stimmfinder mit Stimmtyp-Vorschlag - Gerätedesign (Regler, Schalter, LED) und Metronom (frei/songsynchron, Tap) - Akkorderkennung aus der Begleitung, Akkordleiste und -karte - zweiter Song als Chart Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@ -15,6 +15,7 @@ ap = argparse.ArgumentParser()
|
||||
ap.add_argument("lyrics")
|
||||
ap.add_argument("words")
|
||||
ap.add_argument("--out", required=True)
|
||||
ap.add_argument("--drop-unsung", help="schreibt den Text ohne Zeilen, die in der Aufnahme nicht vorkommen")
|
||||
args = ap.parse_args()
|
||||
|
||||
|
||||
@ -22,11 +23,15 @@ def norm(w: str) -> str:
|
||||
return re.sub(r"[^a-z0-9]", "", w.lower())
|
||||
|
||||
|
||||
lines = [
|
||||
l.strip().split()
|
||||
for l in open(args.lyrics, encoding="utf-8")
|
||||
if l.strip() and not l.strip().startswith("[")
|
||||
]
|
||||
def is_text_line(l: str) -> bool:
|
||||
"""Gleiche Regeln wie der Parser in src/import/lyrics.rs: Überschriften (#, [..]), Regieanweisungen
|
||||
und Zeilen ohne Buchstaben sind kein gesungener Text."""
|
||||
l = l.strip()
|
||||
return bool(l) and not l.startswith(("#", "[")) and any(c.isalpha() for c in l)
|
||||
|
||||
|
||||
orig_lines = open(args.lyrics, encoding="utf-8").read().splitlines()
|
||||
lines = [l.strip().split() for l in orig_lines if is_text_line(l)]
|
||||
lyr = [(li, w) for li, ws in enumerate(lines) for w in ws]
|
||||
heard = [w for seg in json.load(open(args.words))["segments"] for w in seg["words"] if norm(w["w"])]
|
||||
|
||||
@ -74,7 +79,21 @@ for li, ws in enumerate(lines):
|
||||
row.append({"w": w, "start": times[k][0], "end": times[k][1], "matched": matched[k]})
|
||||
k += 1
|
||||
out.append(row)
|
||||
# Zeilen, von denen kein einziges Wort erkannt wurde, kommen in der Aufnahme nicht vor (z. B. doppelt
|
||||
# notierte Wiederholung): sie liefern auch keine sinnvollen Zeiten.
|
||||
unsung = [li for li, row in enumerate(out) if not any(w["matched"] for w in row)]
|
||||
if args.drop_unsung:
|
||||
keep, idx, kept_lines = [], 0, []
|
||||
for l in orig_lines:
|
||||
if is_text_line(l):
|
||||
if idx not in unsung:
|
||||
keep.append(l)
|
||||
idx += 1
|
||||
else:
|
||||
keep.append(l)
|
||||
open(args.drop_unsung, "w", encoding="utf-8").write("\n".join(keep) + "\n")
|
||||
json.dump({"lines": out}, open(args.out, "w"), ensure_ascii=False, indent=1)
|
||||
print(f"nicht in der Aufnahme gehörte Zeilen: {[u + 1 for u in unsung]}")
|
||||
print(f"{sum(matched)}/{len(matched)} Wörter direkt erkannt ({100 * sum(matched) / len(matched):.0f} %), "
|
||||
f"{len(heard) - sum(matched)} erkannte Wörter ohne Entsprechung im Text")
|
||||
for li, row in enumerate(out):
|
||||
|
||||
Reference in New Issue
Block a user