diff --git a/src/faster_whisper_server/text_utils.py b/src/faster_whisper_server/text_utils.py index 87ccea24..4ffa408e 100644 --- a/src/faster_whisper_server/text_utils.py +++ b/src/faster_whisper_server/text_utils.py @@ -3,7 +3,6 @@ import re from typing import TYPE_CHECKING - if TYPE_CHECKING: from collections.abc import Iterable diff --git a/tests/speech_test.py b/tests/speech_test.py index ca3fb61e..a4bece0d 100644 --- a/tests/speech_test.py +++ b/tests/speech_test.py @@ -1,5 +1,9 @@ import io +from openai import APIConnectionError, AsyncOpenAI, UnprocessableEntityError +import pytest +import soundfile as sf + from faster_whisper_server.routers.speech import ( DEFAULT_MODEL, DEFAULT_RESPONSE_FORMAT, @@ -7,14 +11,11 @@ SUPPORTED_RESPONSE_FORMATS, ResponseFormat, ) -from openai import APIConnectionError, AsyncOpenAI, UnprocessableEntityError -import pytest -import soundfile as sf DEFAULT_INPUT = "Hello, world!" -@pytest.mark.asyncio() +@pytest.mark.asyncio @pytest.mark.parametrize("response_format", SUPPORTED_RESPONSE_FORMATS) async def test_create_speech_formats(openai_client: AsyncOpenAI, response_format: ResponseFormat) -> None: await openai_client.audio.speech.create( @@ -34,7 +35,7 @@ async def test_create_speech_formats(openai_client: AsyncOpenAI, response_format ] -@pytest.mark.asyncio() +@pytest.mark.asyncio @pytest.mark.parametrize(("model", "voice"), GOOD_MODEL_VOICE_PAIRS) async def test_create_speech_good_model_voice_pair(openai_client: AsyncOpenAI, model: str, voice: str) -> None: await openai_client.audio.speech.create( @@ -54,7 +55,7 @@ async def test_create_speech_good_model_voice_pair(openai_client: AsyncOpenAI, m ] -@pytest.mark.asyncio() +@pytest.mark.asyncio @pytest.mark.parametrize(("model", "voice"), BAD_MODEL_VOICE_PAIRS) async def test_create_speech_bad_model_voice_pair(openai_client: AsyncOpenAI, model: str, voice: str) -> None: # NOTE: not sure why `APIConnectionError` is sometimes raised @@ -70,7 +71,7 @@ async def test_create_speech_bad_model_voice_pair(openai_client: AsyncOpenAI, mo SUPPORTED_SPEEDS = [0.25, 0.5, 1.0, 2.0, 4.0] -@pytest.mark.asyncio() +@pytest.mark.asyncio async def test_create_speech_with_varying_speed(openai_client: AsyncOpenAI) -> None: previous_size: int | None = None for speed in SUPPORTED_SPEEDS: @@ -90,7 +91,7 @@ async def test_create_speech_with_varying_speed(openai_client: AsyncOpenAI) -> N UNSUPPORTED_SPEEDS = [0.1, 4.1] -@pytest.mark.asyncio() +@pytest.mark.asyncio @pytest.mark.parametrize("speed", UNSUPPORTED_SPEEDS) async def test_create_speech_with_unsupported_speed(openai_client: AsyncOpenAI, speed: float) -> None: with pytest.raises(UnprocessableEntityError): @@ -106,7 +107,7 @@ async def test_create_speech_with_unsupported_speed(openai_client: AsyncOpenAI, VALID_SAMPLE_RATES = [16000, 22050, 24000, 48000] -@pytest.mark.asyncio() +@pytest.mark.asyncio @pytest.mark.parametrize("sample_rate", VALID_SAMPLE_RATES) async def test_speech_valid_resample(openai_client: AsyncOpenAI, sample_rate: int) -> None: res = await openai_client.audio.speech.create( @@ -123,7 +124,7 @@ async def test_speech_valid_resample(openai_client: AsyncOpenAI, sample_rate: in INVALID_SAMPLE_RATES = [7999, 48001] -@pytest.mark.asyncio() +@pytest.mark.asyncio @pytest.mark.parametrize("sample_rate", INVALID_SAMPLE_RATES) async def test_speech_invalid_resample(openai_client: AsyncOpenAI, sample_rate: int) -> None: with pytest.raises(UnprocessableEntityError):