Click here to Skip to main content
15,887,135 members
Articles / Artificial Intelligence
Tip/Trick

Effortlessly Transcribe Audio in .NET with OpenAI's Transcriptions Feature

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
13 Oct 2023CPOL1 min read 5.8K   4  
Unlock seamless audio transcription capabilities in .NET with OpenAI's API
Dive into the world of audio transcriptions in .NET as we explore OpenAI's transcriptions feature. This article unveils how developers can harness the power of artificial intelligence to effortlessly convert audio content into text, broadening the horizon for application functionalities and enhancing user experiences.

Introduction

The ever-evolving landscape of artificial intelligence offers numerous opportunities for developers to simplify and enrich their applications. The ConnectingApps.Refit.OpenAI NuGet package continues to rise to the occasion by introducing support for audio transcriptions. This capability allows developers to transcribe audio content and retrieve the corresponding text, even when it's not in English. In this article, we'll delve into how to effortlessly incorporate this feature into your .NET applications.

Background

OpenAI's API has been a game-changer in the realm of artificial intelligence and machine learning. The ability to seamlessly interface with OpenAI's services can offer a significant edge for .NET applications. Previously, I discussed the introduction of the ConnectingApps.Refit.OpenAI NuGet package and its audio translations feature. The newly added audio transcription functionality further elevates its utility.

Using the Code

Implementing the audio transcription feature is straightforward:

  1. Ensure the ConnectingApps.Refit.OpenAI NuGet package is installed in your project.
  2. Retrieve your OpenAI API key.
  3. Transcribe the audio file using the provided C# code snippet.

Below is a demonstration of the audio transcription process in C#:

C#
using ConnectingApps.Refit.OpenAI;
using ConnectingApps.Refit.OpenAI.Transcriptions;
using Refit;

var apiKey = Environment.GetEnvironmentVariable("OPENAI_KEY");
var authorizationHeader = $"Bearer {apiKey}";
await using (var recording = new FileStream("HalloWereld.mp3", 
             FileMode.Open, FileAccess.Read))
{
    var openAiApi = RestService.For<itranscription>
    ("https://api.openai.com", OpenAiRefitSettings.RefitSettings);
    var streamPart = new StreamPart(recording, "HalloWereld.mp3");
    var response = await openAiApi.GetAudioTranscription
                   (authorizationHeader, streamPart, "whisper-1");
    Console.WriteLine($"Returned response status code {response.StatusCode}");
    Console.WriteLine($"Actual text {response.Content!.Text}");
} 

Further examples and insights can be found in the package's GitHub repository.

Points of Interest

The introduction of the audio transcription feature in the ConnectingApps.Refit.OpenAI NuGet package underscores the limitless potential of integrating AI into modern development. It paves the way for diverse applications, from content creators aiming for multilingual reach to developers crafting accessibility tools. The ability to transcribe non-English audio further breaks down language barriers, offering a more inclusive experience.

History

  • 13th October, 2023: Introduced the audio transcription feature
  • Earlier in October, 2023: Delved into the audio translations feature
  • Previously: Initial introduction of the NuGet package

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Netherlands Netherlands
I am a self-employed software engineer working on .NET Core. I love TDD.

Comments and Discussions

 
-- There are no messages in this forum --