Add audio_visualizer/src/audio_visualizer/cli.py
This commit is contained in:
parent
05488822ee
commit
ee5bf65157
1 changed files with 51 additions and 0 deletions
51
audio_visualizer/src/audio_visualizer/cli.py
Normal file
51
audio_visualizer/src/audio_visualizer/cli.py
Normal file
|
|
@ -0,0 +1,51 @@
|
||||||
|
import argparse
|
||||||
|
import logging
|
||||||
|
from pathlib import Path
|
||||||
|
from audio_visualizer.core import generate_visualization
|
||||||
|
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
logging.basicConfig(level=logging.INFO, format='[%(levelname)s] %(message)s')
|
||||||
|
|
||||||
|
|
||||||
|
def _parse_args() -> argparse.Namespace:
|
||||||
|
parser = argparse.ArgumentParser(
|
||||||
|
description="Echo der Wellen – Visualisierung von Audio- oder Sensordaten"
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--input",
|
||||||
|
required=True,
|
||||||
|
help="Pfad zur Eingabedatei (CSV oder Audiodatei)."
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--output",
|
||||||
|
required=False,
|
||||||
|
help="Pfad zur Ausgabedatei (PNG). Optional."
|
||||||
|
)
|
||||||
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> None:
|
||||||
|
"""Kommandozeilenschnittstelle für den Audio Visualizer."""
|
||||||
|
args = _parse_args()
|
||||||
|
|
||||||
|
input_path = Path(args.input)
|
||||||
|
if not input_path.exists():
|
||||||
|
raise FileNotFoundError(f"Eingabedatei nicht gefunden: {input_path}")
|
||||||
|
|
||||||
|
output_path = args.output
|
||||||
|
if output_path:
|
||||||
|
out_dir = Path(output_path).parent
|
||||||
|
out_dir.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
|
logger.info("Starte Visualisierung: %s", input_path)
|
||||||
|
try:
|
||||||
|
generate_visualization(str(input_path))
|
||||||
|
logger.info("Visualisierung abgeschlossen.")
|
||||||
|
except Exception as e:
|
||||||
|
logger.error("Fehler bei der Visualisierung: %s", e)
|
||||||
|
raise
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Loading…
Reference in a new issue