Path: redb-route/tests/redb.Route.Tests.Llm/LiveTranscriptionTests.cs Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route Page: https://redbase.app/src/dev-2026-12-06/redb-route/tests/redb.Route.Tests.Llm/LiveTranscriptionTests.cs ---- using System.Text; using AwesomeAssertions; using redb.Route.Llm; using redb.Route.Llm.Providers; using redb.Route.Tests.Llm.TestHelpers; namespace redb.Route.Tests.Llm; /// /// A live check of the transcription transport against a real server. /// /// The stub tests () prove the shape of the request /// as the transport's author meant it. What they do not prove is that a real server accepts EXACTLY /// that shape: the form field names, the file name, the content type and how it /// reads response_format. That is exactly where multipart transports break, and a stub /// cannot show it at all. /// /// Turned on by the variable REDB_STT_BASE_URL, for example /// http://127.0.0.1:8083/v1/ (whisper.cpp server, Speaches, LM Studio or a local speech-to-text /// container). Unset, the fact is skipped, like the other live ones. /// public sealed class LiveTranscriptionTests { private const string BaseUrlVariable = "REDB_STT_BASE_URL"; private const string ModelVariable = "REDB_STT_MODEL"; private static OpenAiTranscriptionProvider Provider() { var baseUrl = Environment.GetEnvironmentVariable(BaseUrlVariable)!; return OpenAiTranscriptionProvider.Create(new LlmConnectionFactory { Name = "live-stt", Provider = "whisper", ModelId = Environment.GetEnvironmentVariable(ModelVariable) ?? "medium", BaseUrl = new Uri(baseUrl), ApiKey = Environment.GetEnvironmentVariable("REDB_STT_KEY"), RequestTimeoutMs = 300_000, }); } /// /// A valid WAV: one second of tone, one second of silence. There is no speech in it, and here that is a /// convenience, not a problem: the transport is checked, not the model's hearing. /// private static byte[] ToneWav(int seconds = 2, int rate = 16000, double hz = 220) { var samples = rate * seconds; var data = new byte[samples * 2]; for (var i = 0; i < samples; i++) { short value = i < samples / 2 ? (short)(12000 * Math.Sin(2 * Math.PI * hz * i / rate)) : (short)0; data[i * 2] = (byte)(value & 0xFF); data[i * 2 + 1] = (byte)((value >> 8) & 0xFF); } using var stream = new MemoryStream(); using var writer = new BinaryWriter(stream, Encoding.ASCII, leaveOpen: true); writer.Write("RIFF"u8.ToArray()); writer.Write(36 + data.Length); writer.Write("WAVE"u8.ToArray()); writer.Write("fmt "u8.ToArray()); writer.Write(16); // format block size writer.Write((short)1); // PCM writer.Write((short)1); // mono writer.Write(rate); writer.Write(rate * 2); // bytes per second writer.Write((short)2); // block alignment writer.Write((short)16); // bits per sample writer.Write("data"u8.ToArray()); writer.Write(data.Length); writer.Write(data); writer.Flush(); return stream.ToArray(); } [EnvFact(BaseUrlVariable)] public async Task A_live_server_accepts_our_upload_form() { var provider = Provider(); var result = await provider.TranscribeAsync( new TranscriptionRequest(ToneWav(), "probe.wav", Language: "ru")); // The text may be anything, empty included: the server may hear no speech in a tone. // What is proven is something else: the request arrived, was understood and parsed without an exception. result.Text.Should().NotBeNull(); provider.ModelId.Should().NotBeNullOrWhiteSpace(); } /// /// A recording without speech must come back EMPTY. Whisper does not stay silent on silence, it /// makes things up: on the very first run of the synthetic tone it produced a stock phrase /// (a typical hallucination learned from video subtitles). For a route this is not a curiosity: /// the invented phrase would go to the model as the words of a person. /// /// The server itself suppresses it (the no_speech_prob threshold), not the transport, so /// the fact is live: it checks the stand, not our code. /// [EnvFact(BaseUrlVariable)] public async Task A_live_server_does_not_invent_words_for_a_recording_without_speech() { var result = await Provider().TranscribeAsync( new TranscriptionRequest(ToneWav(), "probe.wav", Language: "ru")); result.Text.Should().BeEmpty( "a recording without speech must come back as an empty string: an invented phrase would go " + "into the conversation as the person's words"); } }