More settings tests

drew/3-whisper-settings
Drew Bednar 2 years ago
parent a4a09b37f0
commit 0ff912be1b

@ -3,7 +3,9 @@ from typing import BinaryIO
import ffmpeg import ffmpeg
import numpy as np import numpy as np
DEFAULT_SAMPLE_RATE = 16000 from .settings import whisper_settings
DEFAULT_SAMPLE_RATE = whisper_settings.default_sample_rate
# TODO probably can offload this on a worker queue too # TODO probably can offload this on a worker queue too

@ -10,6 +10,10 @@ class WhisperSettings(BaseSettings):
base_asr_model: str = Field( base_asr_model: str = Field(
default="medium.en", description="The base whisper model to host." default="medium.en", description="The base whisper model to host."
) )
default_sample_rate: int = Field(
default=16000,
description="The default sample rate used to resample the audio if necessary",
)
class Config: class Config:
env_prefix = "WHISPER_" env_prefix = "WHISPER_"

@ -8,6 +8,6 @@ def test_transcribe(sample_audio):
result = transcribe(audio) result = transcribe(audio)
assert ( assert (
result["text"].strip().lower() result["text"].strip().lower()
== "Let's see, right now I'm playing Horizon Zero Dawn. \ == "Let's see, right now I'm playing Horizon Zero Dawn."
I also had just recently finished BioShock Infinite.".lower() " I also had just recently finished BioShock Infinite.".lower()
) )

@ -5,9 +5,7 @@ from pydantic.types import SecretStr
from local_whisper.settings import WhisperSettings from local_whisper.settings import WhisperSettings
SETTING_DEFAULTS = { SETTING_DEFAULTS = {"BASE_ASR_MODEL": "medium.en", "DEFAULT_SAMPLE_RATE": 16000}
"BASE_ASR_MODEL": "medium.en",
}
def test_setting_defaults(): def test_setting_defaults():
@ -23,3 +21,9 @@ def test_setting_defaults():
else _setting_value else _setting_value
) )
unmasked_setting == v unmasked_setting == v
def test_with_envvar_prefix():
with patch.dict(os.environ, {"WHISPER_DEFAULT_SAMPLE_RATE": "22500"}, clear=True):
whisper_settings = WhisperSettings()
assert whisper_settings.default_sample_rate == 22500

Loading…
Cancel
Save