Coder Social home page Coder Social logo

math3ussdl / plugin.maui.audiorecorder Goto Github PK

View Code? Open in Web Editor NEW
11.0 3.0 1.0 27 KB

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.

License: GNU Affero General Public License v3.0

C# 100.00%
android audio audio-processing ios macos maui tizen windows

plugin.maui.audiorecorder's Introduction

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

  • Record audio from device microphone
  • Real-time transcription of spoken text to written format
  • Ability to save the audio file with transcription

Installation

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

using Plugin.Maui.AudioRecorder;

3 - Add this plugin to the MauiApp pipeline:

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:

  • Without parameters: In this way we only save the audio in the chosen path, i.e. we do not transcribe the audio for you.
[RelayCommand]
private async void HandleRecord()
{
  // Setting the path of the file
  _audioRecorderService.FilePath = Path.Combine("/storage/emulated/0/Download", fileName);

  await audioService.StartRecordAsync();
}
  • With parameters: If you want us to return to you, in addition to saving the audio, the transcribed text, you will need to pass three arguments to this method: An CultureInfo instance so we know what language your input audio will be, an IProgress instance, so you decide how the text will be processed, and a CancellationToken, standard for asynchronous methods.
[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

  • Transcription accuracy may vary depending on factors such as background noise, speaker accent, and speech speed.
  • This plugin only works on android. If you want, you can add support for other platforms via PRs.

License

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

plugin.maui.audiorecorder's People

Contributors

math3ussdl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

michaelstgt

plugin.maui.audiorecorder's Issues

Can't get anything to transcribe.

The transcribing parameters don't appear to do anything when passed in, the recording works great but I'm not able to get anything back from the partialText.

[RelayCommand]
private async Task HandleRecordAsync()
{
    var status = await Permissions.RequestAsync<Permissions.Microphone>();
    if (status == PermissionStatus.Granted)
    {
        try
        {
            var documentsPath = FileSystem.AppDataDirectory;
            var filePath = Path.Combine("/storage/emulated/0/Download", "testfile.wav");

            _audioRecorderService.FilePath = filePath;

            await _audioRecorderService.StartRecordingAsync(
                CultureInfo.GetCultureInfo("en-us"),
                new Progress<string>(partialText =>
                {
                    transcribedText += partialText + " ";
                }),
                CancellationToken.None);

            IsRecording = true;
        }
        catch (Exception ex)
        {
            IsRecording = false;

        }
    }
    else
    {
        IsRecording = false;
    }
}

iOS availability

The plugins work perfectly fine in Android. Is there any workaround to make this work for iOS as well?

API 33 Compatibility

I created this issue so that you can follow the process of adjusting this feature. At first, this project was created on top of API 29, but it presented instabilities on API 30+.

One of the instabilities was the fact that the plugin only saves the audio, and does not transcribe it, i.e. anyone who uses the StartRecordAsync method without any parameters will be able to save without any problems.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.