import os import sys import wave import pytest sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) def make_item(iid, subset, stratum, text='はじめにぽぽろをかう。', span=(4, 7), accepted=('ぽぽろ',), known_wrong=('ぼぼろ',), weight=None, flags=None): return {'id': iid, 'subset': subset, 'stratum': stratum, 'text': text, 'span_start': span[0], 'span_end': span[1], 'surface': text[span[0]:span[1]], 'key_kana': accepted[0], 'accepted': list(accepted), 'known_wrong': list(known_wrong), 'headline_weight': weight, **(flags or {})} @pytest.fixture def wav_path(tmp_path): p = tmp_path / 'a.wav' import array import math x = array.array('h', [int(8000 * math.sin(2 * math.pi * 220 * i / 16000)) for i in range(16000)]) with wave.open(str(p), 'wb') as w: w.setnchannels(1) w.setsampwidth(2) w.setframerate(16000) w.writeframes(x.tobytes()) return str(p)