Skip to content

Microsoft.Extensions.AI Integration

Cross-SDK comparison

See the centralized MEAI documentation for feature matrices and comparisons across all tryAGI SDKs.

The RevAI SDK implements ISpeechToTextClient and provides AIFunction tool wrappers, all compatible with Microsoft.Extensions.AI.

Installation

1
dotnet add package tryAGI.RevAI

ISpeechToTextClient

The RevAIClient implements ISpeechToTextClient for speech-to-text transcription. It supports both file upload and URL-based transcription, with automatic polling until the job completes.

File-Based Transcription

Transcribe an audio file to text. The client uploads the audio via multipart form data, submits a transcription job, and polls until completion:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
using Microsoft.Extensions.AI;
using RevAI;

using var client = new RevAIClient(
    apiKey: Environment.GetEnvironmentVariable("REVAI_API_KEY")!);
ISpeechToTextClient sttClient = client;

using var audioStream = File.OpenRead("audio.mp3");
var response = await sttClient.GetTextAsync(audioStream);

Console.WriteLine(response.Text);
Console.WriteLine($"Duration: {response.StartTime} - {response.EndTime}");

Transcription with Language Hint

Specify a language code for more accurate transcription (31 languages supported):

1
2
3
4
5
6
7
8
9
ISpeechToTextClient sttClient = client;

using var audioStream = File.OpenRead("spanish-audio.mp3");
var response = await sttClient.GetTextAsync(audioStream, new SpeechToTextOptions
{
    SpeechLanguage = "es",
});

Console.WriteLine(response.Text);

URL-Based Transcription with RawRepresentationFactory

Use RawRepresentationFactory to transcribe audio from a URL instead of uploading a file:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
ISpeechToTextClient sttClient = client;

var response = await sttClient.GetTextAsync(Stream.Null, new SpeechToTextOptions
{
    RawRepresentationFactory = _ => new SubmitTranscriptionJobRequest
    {
        MediaUrl = "https://example.com/meeting-recording.mp3",
    },
});

Console.WriteLine(response.Text);

// Access full Rev.ai transcript for advanced features (monologues, speaker info)
var raw = (Transcript)response.RawRepresentation!;
Console.WriteLine($"Monologues: {raw.Monologues?.Count}");

Streaming Behavior

GetStreamingTextAsync delegates to the non-streaming GetTextAsync method internally. The batch transcription job (submit + poll + get transcript) runs to completion first, and then the full result is yielded as a single TextUpdated update bracketed by SessionOpen and SessionClose events.

This means you will not receive incremental transcription updates as audio is processed. The entire transcript is returned at once after the job finishes. For most use cases, calling GetTextAsync directly is equivalent and simpler.

Note

Rev.ai does offer a real-time streaming WebSocket API, but it is not exposed through the MEAI ISpeechToTextClient interface. Use the RevAIClient directly for real-time streaming needs.

Accessing the Underlying Client

Retrieve the RevAIClient from the MEAI interface:

1
2
3
4
5
6
7
ISpeechToTextClient sttClient = client;

var metadata = sttClient.GetService<SpeechToTextClientMetadata>();
Console.WriteLine($"Provider: {metadata?.ProviderName}"); // "rev.ai"

var revClient = sttClient.GetService<RevAIClient>();
// Use revClient for Rev.ai-specific APIs (captions, sentiment analysis, topic extraction, etc.)

Available Tools

Method Tool Name Description
AsTranscribeUrlTool() RevAI_TranscribeUrl Transcribe audio/video from URL
AsGetJobStatusTool() RevAI_GetJobStatus Get transcription job status
AsListJobsTool() RevAI_ListJobs List recent transcription jobs

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using Microsoft.Extensions.AI;
using RevAI;

var client = new RevAIClient(
    apiKey: Environment.GetEnvironmentVariable("REVAI_API_KEY")!);

var options = new ChatOptions
{
    Tools = [client.AsTranscribeUrlTool()],
};

IChatClient chatClient = /* your chat client */;

var messages = new List<ChatMessage>
{
    new(ChatRole.User, "Transcribe the audio at https://example.com/meeting.mp3"),
};

while (true)
{
    var response = await chatClient.GetResponseAsync(messages, options);
    messages.AddRange(response.ToChatMessages());

    if (response.FinishReason == ChatFinishReason.ToolCalls)
    {
        var results = await response.CallToolsAsync(options);
        messages.AddRange(results);
        continue;
    }

    Console.WriteLine(response.Text);
    break;
}