Move audio probe off event loop
This commit is contained in:
parent
e1d36e5627
commit
8bc11fe4e4
|
|
@ -151,7 +151,8 @@ class AudioProcessor:
|
||||||
suffix = self.get_output_suffix(filename, content_type)
|
suffix = self.get_output_suffix(filename, content_type)
|
||||||
normalized_filename = self.ensure_audio_filename(filename, suffix)
|
normalized_filename = self.ensure_audio_filename(filename, suffix)
|
||||||
normalized_content_type = self.normalize_content_type(filename, content_type)
|
normalized_content_type = self.normalize_content_type(filename, content_type)
|
||||||
self._probe_audio_duration_seconds(
|
await asyncio.to_thread(
|
||||||
|
self._probe_audio_duration_seconds,
|
||||||
content,
|
content,
|
||||||
suffix,
|
suffix,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -149,6 +149,31 @@ async def test_audio_processor_extract_text_transcribes_directly():
|
||||||
assert "transcription_fallback_used" not in extracted.metadata
|
assert "transcription_fallback_used" not in extracted.metadata
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_audio_processor_extract_text_probes_in_background_thread():
|
||||||
|
processor = AudioProcessor()
|
||||||
|
mock_probe = AsyncMock(return_value=1.0)
|
||||||
|
to_thread = AsyncMock(return_value=1.0)
|
||||||
|
|
||||||
|
with (
|
||||||
|
patch.object(processor, "_probe_audio_duration_seconds", mock_probe),
|
||||||
|
patch("src.utils.files.asyncio.to_thread", to_thread),
|
||||||
|
patch("src.utils.files.transcribe_audio", new=AsyncMock(return_value="ok")),
|
||||||
|
):
|
||||||
|
extracted = await processor.extract_text(
|
||||||
|
b"bytes",
|
||||||
|
filename="voice-note.mp3",
|
||||||
|
content_type="audio/mpeg",
|
||||||
|
)
|
||||||
|
|
||||||
|
to_thread.assert_awaited_once_with(
|
||||||
|
mock_probe,
|
||||||
|
b"bytes",
|
||||||
|
".mp3",
|
||||||
|
)
|
||||||
|
assert extracted.text == "ok"
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_audio_processor_extract_text_allows_empty_transcript():
|
async def test_audio_processor_extract_text_allows_empty_transcript():
|
||||||
processor = AudioProcessor()
|
processor = AudioProcessor()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue