Git Product home page Git Product logo

naraeaudiorecorder's Introduction

NaraeAudioRecorder

Download Codacy Badge Android Arsenal

AudioRecorder for Android powered by Kotlin

Key Features

  • Easy to use API

  • Record on various format

    • core: pcm, wav
    • ffmpeg-recorder: mp3, m4a, wma, flac, aac
  • Pause & Resume recording

  • Checking Runtime permission (RECORD_AUDIO, WRITE_EXTERNAL_STORAGE) for Android 6.0+

  • Integrated timer is provide maxAvailableTime feature

  • Remove background noise using NoiseSuppressor API

  • 100% write in Kotlin, but has Java Compatible

  • Detect amount of time of Silent

Import

It distributed on JCenter, but sometime it's not available.

repositories {
    maven { url "https://dl.bintray.com/windsekirun/maven/" }
}

Core

Core module will contain most feature and two format. 'pcm' and 'wav'

implementation 'com.github.WindSekirun.NaraeAudioRecorder:core:1.0.0'

FFmpeg-Recorder

FFmpeg-Recorder will contain five format, 'mp3', 'm4a', 'wma', 'flac', 'aac'

This module will increase Final APK Size about 20MB. You can reduce APK Size by this guide

implementation 'nl.bravobit:android-ffmpeg:1.1.5'
implementation 'com.github.WindSekirun.NaraeAudioRecorder:ffmpeg-recorder:1.0.0'

Usages

Core

Initialization

 val audioRecorder = NaraeAudioRecorder()
 val destFile = File(Environment.getExternalStorageDirectory(), "/NaraeAudioRecorder/$fileName$extensions")
 audioRecorder.create() {
            this.destFile = destFile
 }

Define instance of 'NaraeAudioRecorder' and create file and provide with NaraeAudioRecorder.create is fine.

If you want use NoiseSuppressor, define instance of NoiseAudioSource and provide with NaraeAudioRecorder.create.

val recordConfig = AudioRecordConfig.defaultConfig()
val audioSource = NoiseAudioSource(recordConfig)
audioRecorder.create() {
          this.destFile = this.destFile
          this.recordConfig = recordConfig
          this.audioSource = audioSource
}

Initialization in Java

This is full sample of 'initialization in Java'. other feature is same.

File destFile = new File(getContext().getExternalFilesDir(null) + String.format("/recorder/%s.mp3", fileName));
destFile.getParentFile().mkdirs();

mAudioRecorder.checkPermission(getContext());
mAudioRecorder.create(FFmpegRecordFinder.class, config -> {
    config.setDestFile(destFile);
    config.setDebugMode(true);
    config.setTimerCountListener((currentTime, maxTime) -> { 
    });
            
    return null;
});

FFmpegAudioRecorder ffmpegAudioRecorder = (FFmpegAudioRecorder) mAudioRecorder.getAudioRecorder();
ffmpegAudioRecorder.setContext(getContext());
ffmpegAudioRecorder.setOnConvertStateChangeListener(state -> {
    if (state == FFmpegConvertState.SUCCESS) {
        mRecordedPath = destFile.getPath();
    }
});

Permission

audioRecorder.checkPermission(this)

If permission isn't granted, NaraeAudioRecorder will grant below permission for you.

  • RECORD_AUDIO
  • WRITE_EXTERNAL_STORAGE
  • READ_EXTERNAL_STORAGE

Start / Stop / Pause / Resume

audioRecorder.startRecording()
audioRecorder.stopRecording()
audioRecorder.pauseRecording()
audioRecorder.resumeRecording()

Custom config of AudioRecord

You can custom config of AudioRecord with AudioRecordConfig

fun defaultConfig() = AudioRecordConfig(MediaRecorder.AudioSource.MIC,
                AudioFormat.ENCODING_PCM_16BIT,
                AudioFormat.CHANNEL_IN_MONO,
                AudioConstants.FREQUENCY_44100)

Listen about state changes of record

audioRecorder.setOnRecordStateChangeListener(OnRecordStateChangeListener)

Set maxAvailableTime & Listen about changes of timer

audioRecorder.create(FFmpegRecordFinder::class.java) {
          ...
          this.maxAvailableMillis = TimeUnit.SECONDS.toMillis(20)
          this.timerCountListener = { currentTime, maxTime -> }
}

If you want use accuracy, define refreshTimerMillis in create section will be help for you. Default is 50.

FFmpeg-recorder

Using FFmpeg-recorder will need some additional info.

audioRecorder.create() {
            this.destFile = this.destFile
            this.recordConfig = recordConfig
            this.audioSource = audioSource
}

val ffmpegAudioRecorder: FFmpegAudioRecorder = audioRecorder.getAudioRecorder() as? FFmpegAudioRecorder ?: return
ffmpegAudioRecorder.setContext(this)

In parameters of create, use FFmpegRecordFinder::class.java to determine proper recorder with destFile .

FFmpeg-recorder uses WavAudioRecorder internally, recording in wav and convert them to desire format using FFmpeg command.

Change config of FFmpeg

You can custom config of FFmpeg using this options.

ffmpegAudioRecorder.setConvertConfig(FFmpegConvertConfig)

Default value is fun defaultConfig() = FFmpegConvertConfig(bitRate = FFmpegBitRate.def, samplingRate = FFmpegSamplingRate.ORIGINAL, mono = true).

Listen about state changes of convert

ffmpegAudioRecorder.setOnConvertStateChangeListener(OnConvertStateChangeListener)

Sample Application

You can view sample application by APK, Code

License

Core

Copyright 2019, WindSekirun (DongGil, Seo)

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

FFmpeg-recorder

naraeaudiorecorder's People

Watchers

 avatar

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.