Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/rai_s2s/rai_s2s/tts/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ def get_tts_params(self) -> Tuple[int, int]:
pass

def set_tts_params(self, target_sample_rate: int, channels: int):
if not isinstance(target_sample_rate, int) or isinstance(target_sample_rate, bool) or target_sample_rate <= 0:
raise ValueError(
f"target_sample_rate must be a positive int, got {target_sample_rate!r}"
)
if not isinstance(channels, int) or isinstance(channels, bool) or channels <= 0:
raise ValueError(f"channels must be a positive int, got {channels!r}")
self.sample_rate = target_sample_rate
self.channels = channels

Expand Down
32 changes: 32 additions & 0 deletions tests/s2s/test_tts_set_params.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import pytest
from typing import Tuple

from rai_s2s.tts.models.base import TTSModel


class _DummyTTS(TTSModel):
def get_speech(self, text: str):
raise NotImplementedError

def get_tts_params(self) -> Tuple[int, int]:
return self.sample_rate, self.channels


def test_set_tts_params_accepts_positive():
m = _DummyTTS()
m.set_tts_params(16000, 1)
assert m.get_tts_params() == (16000, 1)


@pytest.mark.parametrize("rate", [0, -1])
def test_set_tts_params_rejects_bad_rate(rate):
m = _DummyTTS()
with pytest.raises(ValueError, match="target_sample_rate"):
m.set_tts_params(rate, 1)


@pytest.mark.parametrize("channels", [0, -2])
def test_set_tts_params_rejects_bad_channels(channels):
m = _DummyTTS()
with pytest.raises(ValueError, match="channels"):
m.set_tts_params(16000, channels)
Loading