mattrguerra/transcription-pipelinemainPrivate on GitHub, published here in full

helpers.py

Language Python1.6 KB39 lines

tests/helpers.py

  1. import math
  2. import struct
  3. import wave
  4. from pathlib import Path
  5. def write_tone(path: Path, seconds: float = 1.5, rate: int = 16000, freq: float = 440.0) -> Path:
  6. with wave.open(str(path), "wb") as w:
  7. w.setnchannels(1)
  8. w.setsampwidth(2)
  9. w.setframerate(rate)
  10. n = int(seconds * rate)
  11. w.writeframes(b"".join(
  12. struct.pack("<h", int(8000 * math.sin(2 * math.pi * freq * i / rate)))
  13. for i in range(n)))
  14. return path
  15. def fake_result(speakers=True):
  16. """What alignment plus diarization hand to shape.py for a short two-person call."""
  17. def w(word, s, e, spk):
  18. d = {"word": word, "start": s, "end": e}
  19. if speakers:
  20. d["speaker"] = spk
  21. return d
  22. return {
  23. "language": "en", "model": "fake",
  24. "segments": [
  25. {"start": 0.5, "end": 3.1, "text": "Hi, thanks for calling back. No problem.",
  26. "words": [w("Hi,", 0.5, 0.7, "SPEAKER_01"), w("thanks", 0.8, 1.0, "SPEAKER_01"),
  27. w("for", 1.0, 1.1, "SPEAKER_01"), w("calling", 1.1, 1.4, "SPEAKER_01"),
  28. w("back.", 1.4, 1.7, "SPEAKER_01"), w("No", 2.2, 2.5, "SPEAKER_00"),
  29. w("problem.", 2.5, 3.1, "SPEAKER_00")]},
  30. {"start": 3.5, "end": 5.0, "text": "Did the draft come through?",
  31. "words": [w("Did", 3.5, 3.7, "SPEAKER_00"), w("the", 3.7, 3.8, "SPEAKER_00"),
  32. w("draft", 3.8, 4.2, "SPEAKER_00"), w("come", 4.2, 4.5, "SPEAKER_00"),
  33. w("through?", 4.5, 5.0, "SPEAKER_00")]},
  34. ],
  35. }