Polish weather news and STT filtering

This commit is contained in:
Jacob Dubin
2026-05-21 06:09:27 -05:00
parent 1b9efc4226
commit eb509a66e0
8 changed files with 157 additions and 15 deletions

View File

@@ -77,6 +77,31 @@ public sealed class LocalWhisperCppBufferedAudioSttStrategyTests
Assert.False(strategy.CanHandle(turn));
}
[Fact]
public void CanHandle_ReturnsFalse_WhenBufferedAudioIsBelowNoiseFloor()
{
var strategy = new LocalWhisperCppBufferedAudioSttStrategy(
new BufferedAudioSttOptions
{
EnableLocalWhisperCpp = true,
FfmpegPath = "ffmpeg",
WhisperCliPath = "whisper-cli",
WhisperModelPath = "model.bin"
},
new FakeExternalProcessRunner());
var turn = new TurnContext
{
Attributes = new Dictionary<string, object?>
{
["bufferedAudioBytes"] = 47,
["bufferedAudioFrames"] = new[] { BuildMinimalOggPage() }
}
};
Assert.False(strategy.CanHandle(turn));
}
[Fact]
public async Task TranscribeAsync_UsesFfmpegAndWhisperCpp_WhenConfigured()
{
@@ -103,7 +128,7 @@ public sealed class LocalWhisperCppBufferedAudioSttStrategyTests
Locale = "en-US",
Attributes = new Dictionary<string, object?>
{
["bufferedAudioBytes"] = 47,
["bufferedAudioBytes"] = 147,
["bufferedAudioFrames"] = new[] { BuildMinimalOggPage() }
}
};
@@ -115,7 +140,7 @@ public sealed class LocalWhisperCppBufferedAudioSttStrategyTests
Assert.Equal(2, runner.Calls.Count);
Assert.Equal("ffmpeg", runner.Calls[0].FileName);
Assert.Equal("whisper-cli", runner.Calls[1].FileName);
Assert.Equal(47, result.Metadata["bufferedAudioBytes"]);
Assert.Equal(147, result.Metadata["bufferedAudioBytes"]);
}
finally
{
@@ -149,7 +174,7 @@ public sealed class LocalWhisperCppBufferedAudioSttStrategyTests
Locale = "en-US",
Attributes = new Dictionary<string, object?>
{
["bufferedAudioBytes"] = 47,
["bufferedAudioBytes"] = 147,
["bufferedAudioFrames"] = new[] { BuildMinimalOggPage() }
}
};
@@ -165,6 +190,47 @@ public sealed class LocalWhisperCppBufferedAudioSttStrategyTests
}
}
[Fact]
public async Task TranscribeAsync_Throws_WhenBufferedAudioIsBelowNoiseFloor()
{
var tempDirectory = Path.Combine(Path.GetTempPath(), $"openjibo-stt-test-{Guid.NewGuid():N}");
Directory.CreateDirectory(tempDirectory);
try
{
var runner = new FakeExternalProcessRunner();
var strategy = new LocalWhisperCppBufferedAudioSttStrategy(
new BufferedAudioSttOptions
{
EnableLocalWhisperCpp = true,
FfmpegPath = "ffmpeg",
WhisperCliPath = "whisper-cli",
WhisperModelPath = "model.bin",
TempDirectory = tempDirectory
},
runner);
var turn = new TurnContext
{
TurnId = "turn-local-stt-noise-floor",
Locale = "en-US",
Attributes = new Dictionary<string, object?>
{
["bufferedAudioBytes"] = 47,
["bufferedAudioFrames"] = new[] { BuildMinimalOggPage() }
}
};
var ex = await Assert.ThrowsAsync<InvalidOperationException>(() => strategy.TranscribeAsync(turn));
Assert.Contains("too short or noisy", ex.Message, StringComparison.OrdinalIgnoreCase);
Assert.Empty(runner.Calls);
}
finally
{
if (Directory.Exists(tempDirectory)) Directory.Delete(tempDirectory, true);
}
}
private static byte[] BuildMinimalOggPage()
{
return
@@ -209,4 +275,4 @@ public sealed class LocalWhisperCppBufferedAudioSttStrategyTests
return Task.FromResult(new ExternalProcessResult(0, string.Empty, string.Empty));
}
}
}
}