refactor: change test folder structure, rename functions to account for (non)changing behaviours and clarity

ref: N25B-257
This commit is contained in:
Björn Otgaar
2025-11-12 12:42:54 +01:00
parent 9365f109ab
commit 7a707cf9a0
19 changed files with 79 additions and 79 deletions

View File

@@ -0,0 +1,39 @@
import numpy as np
from control_backend.agents.per_agents.per_transcription_agent.speech_recognizer import (
OpenAIWhisperSpeechRecognizer,
SpeechRecognizer,
)
def test_estimate_max_tokens():
"""Inputting one minute of audio, assuming 450 words per minute and adding a 10 token padding,
expecting 610 tokens."""
audio = np.empty(shape=(60 * 16_000), dtype=np.float32)
actual = SpeechRecognizer._estimate_max_tokens(audio)
assert actual == 610
assert isinstance(actual, int)
def test_get_decode_options():
"""Check whether the right decode options are given under different scenarios."""
audio = np.empty(shape=(60 * 16_000), dtype=np.float32)
# With the defaults, it should limit output length based on input size
recognizer = OpenAIWhisperSpeechRecognizer()
options = recognizer._get_decode_options(audio)
assert "sample_len" in options
assert isinstance(options["sample_len"], int)
# When explicitly enabled, it should limit output length based on input size
recognizer = OpenAIWhisperSpeechRecognizer(limit_output_length=True)
options = recognizer._get_decode_options(audio)
assert "sample_len" in options
assert isinstance(options["sample_len"], int)
# When disabled, it should not limit output length based on input size
assert "sample_rate" not in options