ci / test (push) Successful in 24s
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
22 lines
667 B
Python
22 lines
667 B
Python
"""Hilfen für Audio (WAV-Dauer, Real-Time-Factor)."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import io
|
|
import wave
|
|
|
|
|
|
def wav_duration(data: bytes) -> float:
|
|
"""Dauer einer WAV-Datei in Sekunden; 0.0 wenn keine gültige WAV."""
|
|
try:
|
|
with wave.open(io.BytesIO(data)) as w:
|
|
rate = w.getframerate()
|
|
return w.getnframes() / rate if rate else 0.0
|
|
except (wave.Error, EOFError):
|
|
return 0.0
|
|
|
|
|
|
def rtf(seconds_compute: float, seconds_audio: float) -> float | None:
|
|
"""Real-Time-Factor: Rechenzeit ÷ Audiolänge (< 1 = schneller als Echtzeit)."""
|
|
return seconds_compute / seconds_audio if seconds_audio > 0 else None
|