nightlybuilds-net / nightly.xam.audiorecorder

Xamarin Forms audio recorder library
MIT License
8 stars 1 forks source link

nightly.xam.audiorecorder

Xamarin Forms Audio Recorder Library

Features

Installation

Add nighlty.xam.audiorecorder nuget package to forms and native (iOS and Droid) apps HERE

dotnet add package nightly.xam.audiorecorder 

Usage

See Sample project in this repo. Just create a record service:

this._recordService = new NightlyRecorderService();

Start record audio:

var streamFile = await this._recordService.RecordAsync();
this._stream = streamFile;

Stop Record

this._recordService.Stop();

Isn't it easy?

The default output stream is MP4 AAR. You can easily customize SampleRate in this way:

this._recordService = new RecorderSettings.Default.WithSampleRate(SampleRate.Low);

or you can use others ready to use configurations in this way:

 this._recordService = new NightlyRecorderService(new RecorderSettings
  {
     IosRecorderSettings = new IosAppleLossLess(),
     DroidRecorderSettings = new DroidOggOpus()
 });

Permission

This library doesn't manage permission for record audio from device MIC. I Suggest you to use Xamarin Essentials Permission API like this:

var status = await Permissions.CheckStatusAsync<Permissions.Microphone>();

    if (status != PermissionStatus.Granted)
    {
        status = await Permissions.RequestAsync<Permissions.Microphone>();
        if (status != PermissionStatus.Granted)
        {
            await this.DisplayAlert("Alert","you need pemrission to mic", "ok");
            return;
        }
    }

API

You can customize iOS and Android record settings implementing the following interfaces

  public interface IIosRecorderSettings
    {
        IosAudioFormat AudioFormat { get; set; }
        double? SampleRate { get; set; }
        int? NumberChannels { get; set; }
        int? LinearPcmBitDepth { get; set; }
        bool? LinearPcmBigEndian { get; set; }
        bool? LinearPcmFloat { get; set; }
        bool? LinearPcmNonInterleaved { get; set; }
        IosAudioQuality? AudioQuality { get; set; }
        IosAudioQuality? SampleRateConverterAudioQuality { get; set; }
        int? EncoderBitRate { get; set; }
        int? EncoderBitRatePerChannel { get; set;}
        int? EncoderBitDepthHint { get; set; }
    }

    public interface IDroidRecorderSettings
    {
        DroidAudioEncoder AudioEncoder { get; }
        DroidOutPutFormat OutPutFormat { get; }
        int? SamplingRate { get; set; }
        int? AudioChannels { get; set; }
        int? CaptureRate { get; set; }
        int? AudioEncodingBitRate { get; set; }
    }

After implementing those interfaces you can create a record service:

this._recordService = new NightlyRecorderService(new RecorderSettings
  {
     IosRecorderSettings = new YourIosImplementation(),
     DroidRecorderSettings = new YourDroidImplementation()
 });

OOB Record Configuration

There are some ready to use implementation:

iOS

Droid

License

MIT

Free Software, Hell Yeah!