Path: redb-route/redb.Route.Llm/Transcription/SttComponent.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/redb.Route.Llm/Transcription/SttComponent.cs ---- using redb.Route.Abstractions; using redb.Route.Core; using redb.Route.Llm.Providers; namespace redb.Route.Llm.Transcription; /// /// Speech-to-text transport. Scheme: stt. Producer-only, symmetric with /// llm:// and embed://: To("stt://<connectionFactoryName>") /// turns the exchange body (recorded audio as byte[], ReadOnlyMemory<byte> /// or a Stream) into the recognised text written to Out.Body. /// /// The URI host names an (Provider / BaseUrl / /// ApiKey / ModelId — set ModelId to the speech model), which is where local /// and paid recognition part company: point BaseUrl at a whisper server on /// 127.0.0.1 and the route costs nothing to run, point it at a paid endpoint /// and the same route bills. Neither is visible from the route. /// /// /// /// From("direct://voice") /// .To(Tg.Download(token)) // attachment file_id → bytes /// .To("stt://local") // bytes → text /// .To("direct://chat"); // and on as an ordinary reply /// /// /// [EndpointRole(EndpointRole.Producer, Hint = "Use To(\"stt://\").")] public sealed class SttComponent : ComponentBase { /// public override string Scheme => "stt"; /// /// Builds the from a resolved connection /// factory. Defaults to ; override /// for a custom provider or in tests. /// public Func ProviderFactory { get; set; } = OpenAiTranscriptionProvider.Create; /// public override IEndpoint CreateEndpoint(EndpointUri uri) { ArgumentNullException.ThrowIfNull(uri); var options = new SttEndpointOptions(); options.BindFromUri(uri.RawParameters); options.Validate(); return new SttEndpoint(uri, this, options); } } /// Options for an stt:// endpoint. public sealed class SttEndpointOptions : EndpointOptions { /// Alternative to the URI host for the connection-factory name. [RegistryReference(typeof(LlmConnectionFactory))] public string? ConnectionFactory { get; set; } /// /// ISO-639-1 language hint passed to the model (ru). Empty lets the model /// detect the language, which costs accuracy on short recordings — a few words are /// routinely detected as the wrong language. Overridable per exchange with the /// header. /// public string? Language { get; set; } /// /// Decoding hint: names and terms the model would not otherwise spell right. /// Off by default, and deliberately so — a hint can also displace what was said. /// public string? Prompt { get; set; } /// /// Name to upload the audio under. Speech endpoints pick a demuxer by extension, so /// this decides whether an Ogg/Opus voice note is decoded or rejected. When unset the /// producer derives it from the exchange ContentType, falling back to /// audio.ogg. /// public string? FileName { get; set; } /// public override void Validate() { } } /// Speech-to-text endpoint. URI path = connection-factory name. public sealed class SttEndpoint : EndpointBase { /// Connection-factory name (URI path or ?connectionFactory=). public string FactoryName { get; } /// Factory resolved from the route context (null when wired later). internal LlmConnectionFactory? ResolvedFactory { get; } /// Creates the endpoint. public SttEndpoint(EndpointUri uri, SttComponent component, SttEndpointOptions options) : base(uri, component, options) { FactoryName = !string.IsNullOrWhiteSpace(uri.Path) ? uri.Path : (options.ConnectionFactory ?? string.Empty); if (string.IsNullOrWhiteSpace(FactoryName)) throw new InvalidOperationException( "stt:// requires a connection factory — use 'stt://' or '?connectionFactory='."); if (component.Context is not null) ResolvedFactory = component.Context.GetFromRegistry(FactoryName); } /// public override IProducer CreateProducer() => new SttProducer(this, Options); /// public override IConsumer CreateConsumer(IProcessor processor) => throw new NotSupportedException("stt:// is producer-only. Use To(\"stt://\")."); }