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):
|
||||
|
||||
34
tools/draft_lyrics.py
Normal file
34
tools/draft_lyrics.py
Normal file
@ -0,0 +1,34 @@
|
||||
"""Textentwurf aus Whisper-Wortzeiten (tools/transcribe_words.py): eine Zeile je Segment, zusätzlich geteilt
|
||||
an Pausen und bei langen Zeilen. Nur ein Notbehelf, wenn kein Liedtext vorliegt: Whisper hört nicht
|
||||
perfekt (Eigennamen, Gesang), der echte Text ist immer besser.
|
||||
|
||||
Aufruf: python tools/draft_lyrics.py <words.json> --out lyrics.txt [--gap 0.6] [--max-words 10]
|
||||
"""
|
||||
import argparse
|
||||
import json
|
||||
|
||||
ap = argparse.ArgumentParser()
|
||||
ap.add_argument("words")
|
||||
ap.add_argument("--out", required=True)
|
||||
ap.add_argument("--gap", type=float, default=0.6, help="Pause (s), ab der eine neue Zeile beginnt")
|
||||
ap.add_argument("--max-words", type=int, default=10)
|
||||
args = ap.parse_args()
|
||||
|
||||
lines, cur, prev_end = [], [], None
|
||||
for seg in json.load(open(args.words))["segments"]:
|
||||
for i, w in enumerate(seg["words"]):
|
||||
word = w["w"].strip()
|
||||
if not word:
|
||||
continue
|
||||
new_line = (
|
||||
cur and (i == 0 or len(cur) >= args.max_words or (prev_end is not None and w["start"] - prev_end >= args.gap))
|
||||
)
|
||||
if new_line:
|
||||
lines.append(cur)
|
||||
cur = []
|
||||
cur.append(word)
|
||||
prev_end = w["end"]
|
||||
if cur:
|
||||
lines.append(cur)
|
||||
open(args.out, "w", encoding="utf-8").write("\n".join(" ".join(l) for l in lines) + "\n")
|
||||
print(f"{len(lines)} Zeilen, {sum(len(l) for l in lines)} Wörter")
|
||||
Reference in New Issue
Block a user