Datasets:
Download eval/tests/test_synth_audio.py from fishaudio/nanori: direct link, hf CLI and curl.
- Browser
- Download file 1.42 kB
-
https://huggingface.co/datasets/fishaudio/nanori/resolve/main/eval/tests/test_synth_audio.py
- Command line
-
hf download hf://datasets/fishaudio/nanori/eval/tests/test_synth_audio.py
-
curl -L -o test_synth_audio.py https://huggingface.co/datasets/fishaudio/nanori/resolve/main/eval/tests/test_synth_audio.py
1.42 kB
| import json | |
| import struct | |
| import wave | |
| from conftest import make_item | |
| from nanori_eval.audio import parse_wav_bytes, prep_wav, wav_check | |
| from nanori_eval.items import normalise | |
| from nanori_eval.synth import write_manifest | |
| def test_prep_wav(wav_path): | |
| b, meta = prep_wav(wav_path) | |
| assert b[:4] == b'RIFF' and meta['sr'] == 16000 and meta['seconds'] == 1.0 | |
| assert wav_check(wav_path).get('problem') is None | |
| def test_parse_streaming_wav(): | |
| pcm = b'\x01\x00' * 100 | |
| hdr = b'RIFF' + struct.pack('<I', 0xFFFFFFFF) + b'WAVE' + b'fmt ' + struct.pack('<IHHIIHH', 16, 1, 1, 24000, 48000, 2, 16) | |
| data = hdr + b'data' + struct.pack('<I', 0xFFFFFFFF) + pcm | |
| out, sr, ch, sw = parse_wav_bytes(data) | |
| assert out == pcm and (sr, ch, sw) == (24000, 1, 2) | |
| def test_folder_manifest(tmp_path, wav_path): | |
| items = {'JA-DRUG': {'D1': normalise(make_item('D1', 'JA-DRUG', 'D-E/x')), | |
| 'D2': normalise(make_item('D2', 'JA-DRUG', 'D-E/x'))}} | |
| (tmp_path / 'JA-DRUG').mkdir() | |
| with open(wav_path, 'rb') as f: | |
| (tmp_path / 'JA-DRUG' / 'D1.wav').write_bytes(f.read()) | |
| r = write_manifest(items, str(tmp_path), 'mysys') | |
| assert r['clips'] == 1 and r['missing'] == 1 | |
| row = json.loads(open(r['manifest']).readline()) | |
| assert row['clip_id'] == 'mysys__JA-DRUG__D1' and row['set'] == 'JA-DRUG' | |
| with wave.open(row['wav']) as w: | |
| assert w.getsampwidth() == 2 | |