Skip to content

Rx wrapper library for Android's AudioRecord API. (aka RxAudioRecord)

Notifications You must be signed in to change notification settings

ahmedrizwan/ReactiveAudioRecord

Repository files navigation

ReactiveAudioRecord

Release GitHub license Android Arsenal

A reactive (Rx) implementation of the AudioRecord API for recording raw (pcm) audio-data. Also includes helper methods for the creation of Wave audio files.

How to use it?

Create an instance of RecorderOnSubscribe giving it the path to the file
final String filePath = Environment.getExternalStorageDirectory() + "/sample.wav"; //dummy file 
RecorderOnSubscribe recorder = new RecorderOnSubscribe.Builder(filePath)
                                                      .sampleRate(22000)       //by default 44100
                                                      .stereo()                //by default mono
                                                      .audioSourceCamcorder()  //by default MIC
                                                      .build();
Use the recorder OnSubscribe to create an observable
Observable.create(recorder)
          .subscribe( shorts -> {
              ...
              recorder.writeShortsToFile(shorts); //a helper method that writes the buffers to (wave) file
          });

After setting up the Observer, manipulate the recording-process by using these methods

Name Description
start() Starts the recorder and moves it to Recording state
stop() Stops the recorder and moves it to Stopped state
pause() Pauses the recorder and moves it to Paused state
resume() Resumes the recorder if it's in Paused state
isRecording() Returns true if the recorder is in Recording state
isRecordingStopped() Checks whether the recorder is in Stopped state or not

Helper methods for wave file write operations

Name Description
writeShortsToFile(shorts) Writes the short buffers to wave file
completeRecording() Writes the Wave header info to the file (Call it after stop() method)

And that's it! Check out the sample code for a working example!

Download

Repository available on jCenter

compile 'com.minimize.library:reactiveaudiorecord:1.0.2'

License

Copyright 2015 Ahmed Rizwan

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.

About

Rx wrapper library for Android's AudioRecord API. (aka RxAudioRecord)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages