Home

Awesome

Plugin.Maui.AudioRecorder

Overview

This plugin provides functionality to record audio and transcribe spoken text into written format in real-time, while saving the audio file. It is designed for use with .NET Multi-platform App UI (MAUI) framework.

Features

Installation

1 - Install the NuGet package Plugin.Maui.AudioRecorder <br/> 2 - In your .NET MAUI project, add the following using statement to MauiProgram.cs file to use this plugin: <br />

using Plugin.Maui.AudioRecorder;

3 - Add this plugin to the MauiApp pipeline: <br />

builder
  // ...
  .UseAudioRecorder()
  // ...

4 - Enjoy it!

Usage

Inject the Audio service

First of all, you must inject the IAudioRecorder service, remembering that in this example we will consider a class that uses MVVM with the CommunityToolkit.Mvvm module.

using CommunityToolkit.Mvvm.ComponentModel;
using Plugin.Maui.AudioRecorder;

namespace MyAwesomeProject.ViewModels;

[ObservableObject]
public partial class RecordingPageViewModel
{
  private readonly IAudioRecorder _audioRecorderService;

  public RecordingPageViewModel(IAudioRecorder audioRecorderService)
  {
    _audioRecorderService = audioRecorderService;
  }

  [ObservableProperty]
  private bool isRecording;

  // ...
}

If you prefer, you can call the instance as follows:

var audioRecorderService = Services.GetService(typeof(IAudioRecorder)) as IAudioRecorder;

// ...

Start Recording

To start the recording we offer the StartRecordAsync method, which can be called in two ways:

[RelayCommand]
private async void HandleRecord()
{
  // Setting the path of the file
  _audioRecorderService.FilePath = Path.Combine("/storage/emulated/0/Download", fileName);

  await audioService.StartRecordAsync();
}
[RelayCommand]
private async void HandleRecord()
{
  // Setting the path of the file
  _audioRecorderService.FilePath = Path.Combine("/storage/emulated/0/Download", fileName);

  await _audioService.StartRecordAsync(
    CultureInfo.GetCultureInfo("en-us"),
    new Progress<string>(partialText =>
    {
      // ...
    }),
    CancellationToken.None,
  );
}

Stop Recording

To stop the recording we offer the StopRecordAsync method:

[RelayCommand]
private async void HandleStopRecord()
{
  // will returns a Audio instance!
  var audio = await _audioService.StopRecordAsync();
}

Limitations

License

This plugin is released under the GNU AFFERO GENERAL PUBLIC License. See the LICENSE file for details.