(path: Path)
| 90 | |
| 91 | |
| 92 | def audio_duration_seconds(path: Path) -> Optional[float]: |
| 93 | try: |
| 94 | import soundfile as sf |
| 95 | |
| 96 | info = sf.info(str(path)) |
| 97 | if info.samplerate: |
| 98 | return float(info.frames) / float(info.samplerate) |
| 99 | except Exception: |
| 100 | pass |
| 101 | |
| 102 | if path.suffix.lower() == ".wav": |
| 103 | try: |
| 104 | with wave.open(str(path), "rb") as wav_file: |
| 105 | frames = wav_file.getnframes() |
| 106 | rate = wav_file.getframerate() |
| 107 | if rate: |
| 108 | return float(frames) / float(rate) |
| 109 | except Exception: |
| 110 | return None |
| 111 | return None |
| 112 | |
| 113 | |
| 114 | def metadata_dict(items: Iterable[str]) -> Dict[str, str]: |
no outgoing calls
no test coverage detected
searching dependent graphs…