File size: 728 Bytes
de01f6a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
"""Shared pytest fixtures."""

from __future__ import annotations

import wave
from pathlib import Path

import numpy as np
import pytest


def _write_sine_wav(path: Path, duration: float = 3.0, sr: int = 16000) -> Path:
    t = np.linspace(0, duration, int(sr * duration), endpoint=False)
    tone = 0.3 * np.sin(2 * np.pi * 220 * t)
    ints = (tone * 32767).astype(np.int16)
    with wave.open(str(path), "wb") as wf:
        wf.setnchannels(1)
        wf.setsampwidth(2)
        wf.setframerate(sr)
        wf.writeframes(ints.tobytes())
    return path


@pytest.fixture
def sine_wav(tmp_path: Path) -> Path:
    return _write_sine_wav(tmp_path / "tone.wav")


@pytest.fixture
def sample_rate() -> int:
    return 16000