AudioH
Android voice recording and playback processing, based on mediaplayer and MediaRecorder
Realization function
1. Realize Android voice recording function (currently, the package only supports AMR format);
2. Realize Android voice playback function (handset and speaker playback);
3. Realize the caching of network voice in voice playing;
4. Provide methods to get cache size and clean cache;
Usage method
1. Import dependency
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
compile 'com.github.lewis-v:AudioH:1.0.0'
}
2. recording
RecoderBuilder builder = new DefaultRecoderBuilder()
.setMAX_LENGTH(60*1000)//Maximum recording time 60 seconds
.setMIN_LENGTH(500)//Recording 0.5 seconds minimum
.setSAMPLEING_RATE(200)//Recording and monitoring callback interval, 200ms callback once
.setSaveFolderPath(Environment.getExternalStorageDirectory()+"/record/");
AudioRecoderManager.getInstance()//Get single case
.setAudioRecoderData(builder.create())//Set the custom configuration. There is a default configuration, which can be ignored
.setAudioRecoderListener(new AudioRecoderListener() {//Set up monitoring
@Override
public void onStart() {//Start playing
}
@Override
public void onStop(AudioRecoderData audioRecoderData) {//Stop / end playback
Log.e(TAG,audioRecoderData.getFilePath());
}
@Override
public void onFail(Exception e, String msg) {//Errors in recording
e.printStackTrace();
}
@Override
public void onCancel() {//recording canceling
}
@Override
public void onSoundSize(int level) {//Callback of sound size during recording, decibels
Log.e(TAG,"level:"+level);
}
});
AudioRecoderManager.getInstance().start(this);//Start recording
AudioRecoderManager.getInstance().stop(this);//End recording
3. play
AudioPlayManager.getInstance().init(this)//Initialize playback
.setPlayListener(new AudioPlayListener() {//Set playback monitor
@Override
public void onPlay(String audioPath) {//Start playing
}
@Override
public void onProgress(int progress, int maxSize) {//Playback progress (not implemented)
}
@Override
public void onPause() {//Playback pause (not implemented)
}
@Override
public void onStop() {//stop playing
}
@Override
public void onFail(Exception e, String msg) {//Error playing
}
});
AudioPlayManager.getInstance().play("http://39.108.236.30:47423/audio/UP699813445282012.amr"
,this, AudioPlayMode.MEGAPHONE);//Play the audio, rest assured that this audio is my friend's voice.. Hee hee
4. Cache acquisition and cleaning
The cache cleaning method is a synchronous method without thread processing, and requires developers to open sub thread calls themselves
Log.e(TAG, String.valueOf(AudioPlayManager.getInstance().getCacheSize(this)));//Get cache size
Log.e(TAG, String.valueOf(AudioPlayManager.getInstance().clearCache(this)));//Clears the cache and returns the size of the purge