Giter Site home page Giter Site logo

squti / android-wave-recorder Goto Github PK

View Code? Open in Web Editor NEW
214.0 11.0 40.0 212 KB

A powerful and efficient library to record WAVE form audio files (WAV) in Android

License: MIT License

Kotlin 100.00%
wav-recorder wave-recorder wave wav android-wave-recorder android-wav-recorder audio-recorder android recorder

android-wave-recorder's Introduction

Android Wave Recorder

Android Arsenal

A powerful and efficient library to record WAVE form audio files (WAV) in Android

Android Wave Recorder is a lightweight library written in Kotlin to record audio files with WAVE (WAV due to its filename extension) format in Android. It's very memory efficient and easy to use library with recording customizations.

Download

Step 1. Add this in your root (Project) build.gradle at the end of repositories:

allprojects {
        repositories {
            ...
            maven { url "https://jitpack.io" }
        }
    }

Step 2. Add the dependency

dependencies{
    implementation 'com.github.squti:Android-Wave-Recorder:1.7.0'
}

Permission

Add these permissions into your AndroidManifest.xml and request for them in Android 6.0+

<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

Usage

Pass in the path of the output file to WaveRecorder class and call startRecording() like this:

/**
 * This path points to application cache directory.
 * you could change it based on your usage
 */
val filePath:String = externalCacheDir?.absolutePath + "/audioFile.wav"

val waveRecorder = WaveRecorder(filePath)
waveRecorder.startRecording()

To stop recording call stopRecording() function:

waveRecorder.stopRecording()

To pause and resume recording you could use pauseRecording() and resumeRecording() functions:

//Pause
waveRecorder.pauseRecording()

//Resume
waveRecorder.resumeRecording()

To activate Noise Suppressor you could set noiseSuppressorActive to true:

waveRecorder.noiseSuppressorActive = true

To listen to audio amplitude during recording you need to register a listener to onAmplitudeListener:

waveRecorder.onAmplitudeListener = {
    Log.i(TAG, "Amplitude : $it")
}

To listen to recording state changes (RECORDING, STOP and PAUSE) you need to register a listener to onStateChangeListener:

waveRecorder.onStateChangeListener = {
    when (it) {
        RecorderState.RECORDING -> TODO()
        RecorderState.STOP -> TODO()
        RecorderState.PAUSE -> TODO()
    }
}

Configuration

The default configuration for recording audio is like so:

Property Value
sampleRate 16000
channels AudioFormat.CHANNEL_IN_MONO
audioEncoding AudioFormat.ENCODING_PCM_16BIT

But you could change it using waveConfig property in WaveRecorder class based on your usage. This is an example:

val waveRecorder = WaveRecorder(filePath)
waveRecorder.waveConfig.sampleRate = 44100
waveRecorder.waveConfig.channels = AudioFormat.CHANNEL_IN_STEREO
waveRecorder.waveConfig.audioEncoding = AudioFormat.ENCODING_PCM_8BIT
waveRecorder.startRecording()

Note: Wrong configuration may impacts output quality

License

MIT License

Copyright (c) 2019 squti

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

android-wave-recorder's People

Contributors

abkoradiya avatar dachelimo avatar squti avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

android-wave-recorder's Issues

Recording playback is buzzing sound, not detecting any audio data i think

I'm sure this program works completely fine, I am trying to use it for an audio recording app for sound engineers. I know it is probably one small thing that I am missing but I am not sure, the code looks fine and all I did was use the classes so. I have a github repo of the project if you want to skim the code. I'm really thankful to have this since I'm not really an audio programmer but I've learned so much. If you could help me that would be awesome. The playback is just a buzzing sound like an aux cord when it's not plugged in.

Crash on Android 9 and higher for being uninitialized

The crash log:
Fatal Exception: java.lang.IllegalStateException: startRecording() called on an uninitialized AudioRecord. at android.media.AudioRecord.startRecording(AudioRecord.java:1097) at com.github.squti.androidwaverecorder.WaveRecorder.startRecording(WaveRecorder.kt:83) ...

and It has occurred in Android 9 & 10. Any fix on this?

Failed to resolve: com.github.squti:AndroidWaveRecorder:1.6.0

Failed to resolve: com.github.squti:AndroidWaveRecorder:1.6.0

I am adding library by making new project
implementation ("com.github.squti:AndroidWaveRecorder:1.6.0") // For waveform visualization

Android Studio Hedgehog | 2023.1.1 Patch 1
dependencies {

implementation("androidx.core:core-ktx:1.12.0")
implementation("androidx.appcompat:appcompat:1.6.1")
implementation("com.google.android.material:material:1.11.0")
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")

implementation ("com.github.squti:AndroidWaveRecorder:1.6.0") // For waveform visualization

}

Double speed with onTimeElapsed

When you are getting the timeElapsed and you have added waveConfig.channels = AudioFormat.CHANNEL_IN_STEREO it make the time elapse at double speed.

This can easily be reproduced by adding this line in the Sample.
waveRecorder.waveConfig.channels = AudioFormat.CHANNEL_IN_STEREO

Pause/Resume issue

when I pause the recording it is stopping the record but the paused time is added to final track as a blank piece

Add `changeFile` feature

If I have to do two recordings, I'm forced to created a new instance of WaveRecorder since the filePath is private in WaveRecorder():

class WaveRecorder(private var filePath: String)

@squti I'm thinking the changeFile(newFilePath: String) function should change the filePath when the isRecording = false and throw an IllegalStateException if otherwise.

Audio Session Id

Is it possible to get the audioSessionId from the voice recorder?

Not working with ENCODING_PCM_FLOAT

When I configure the wave with waveRecorder.waveConfig.audioEncoding = AudioFormat.ENCODING_PCM_FLOAT the recorder bugs and creates a audio file with 44bytes. Any chance to implement this feature to allow recording audio with AudioFormat.ENCODING_PCM_FLOAT ?

Thanks.

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.