helpers.py
Language Python1.6 KB39 lines
import mathimport structimport wavefrom pathlib import Pathdef write_tone(path: Path, seconds: float = 1.5, rate: int = 16000, freq: float = 440.0) -> Path:with wave.open(str(path), "wb") as w:w.setnchannels(1)w.setsampwidth(2)w.setframerate(rate)n = int(seconds * rate)w.writeframes(b"".join(struct.pack("<h", int(8000 * math.sin(2 * math.pi * freq * i / rate)))for i in range(n)))return pathdef fake_result(speakers=True):"""What alignment plus diarization hand to shape.py for a short two-person call."""def w(word, s, e, spk):d = {"word": word, "start": s, "end": e}if speakers:d["speaker"] = spkreturn dreturn {"language": "en", "model": "fake","segments": [{"start": 0.5, "end": 3.1, "text": "Hi, thanks for calling back. No problem.","words": [w("Hi,", 0.5, 0.7, "SPEAKER_01"), w("thanks", 0.8, 1.0, "SPEAKER_01"),w("for", 1.0, 1.1, "SPEAKER_01"), w("calling", 1.1, 1.4, "SPEAKER_01"),w("back.", 1.4, 1.7, "SPEAKER_01"), w("No", 2.2, 2.5, "SPEAKER_00"),w("problem.", 2.5, 3.1, "SPEAKER_00")]},{"start": 3.5, "end": 5.0, "text": "Did the draft come through?","words": [w("Did", 3.5, 3.7, "SPEAKER_00"), w("the", 3.7, 3.8, "SPEAKER_00"),w("draft", 3.8, 4.2, "SPEAKER_00"), w("come", 4.2, 4.5, "SPEAKER_00"),w("through?", 4.5, 5.0, "SPEAKER_00")]},],}