Skip to content

SpeechToText

This example assumes using RevAI; is in scope and apiKey contains your RevAI API key.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
var apiKey =
    Environment.GetEnvironmentVariable("REVAI_API_KEY") is { Length: > 0 } value
        ? value
        : throw new AssertInconclusiveException("REVAI_API_KEY environment variable is not found.");

using var client = new RevAIClient(apiKey);
ISpeechToTextClient sttClient = client;

// Provide an audio URL via RawRepresentationFactory.
var options = new SpeechToTextOptions
{
    SpeechLanguage = "en",
    RawRepresentationFactory = _ => new SubmitTranscriptionJobRequest
    {
        MediaUrl = "https://www.rev.ai/FTC_Sample_1.mp3",
    },
};

// Get the transcription result.
var response = await sttClient.GetTextAsync(
    audioSpeechStream: Stream.Null,
    options: options);

Console.WriteLine($"Transcript: {response.Text[..Math.Min(200, response.Text.Length)]}...");