Giter Site home page Giter Site logo

rxaudiorecorder's Introduction

RxJava2 Reactive Audio Recorder

GitHub license

A reactive (RxJava 2) implementation of the AudioRecord API for recording raw (pcm) audio-data

Usage

Create an instance of RecorderOnSubscribe giving it the path to the file
Java
ObservableAudioRecorder recorder = new ObservableAudioRecorder.Builder(MediaRecorder.AudioSource.CAMCORDER)
                                          .sampleRate(22050)
                                          .stereo()
                                          .file(Environment.getExternalStorageDirectory() + "/sample.wav")
                                          .build();
Kotlin
ObservableAudioRecorder recorder = ObservableAudioRecorder.Builder(MediaRecorder.AudioSource.CAMCORDER)
                                      .sampleRate(22050)
                                      .stereo()
                                      .file(Environment.getExternalStorageDirectory().absolutePath + "/sample.wav")
                                      .build()
Use the recorder OnSubscribe to create an observable
Java
Observable.create(recorder)
          .subscribe(shorts -> {
              ...
              recorder.writeDataToFile(shorts);
          }, throwable -> errorhandling(throwable));
Kotlin
Observable.create(observableAudioRecorder)
        .subscribe({ shorts ->
            ...
            observableAudioRecorder!!.writeDataToFile(shorts)
        }) { throwable -> errorhandling(throwable) }

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
writeDataToFile(shorts) Writes the short buffers to wave file
completeRecording() Writes the Wave header info to the file (Call it after stop() method)

Download

Repository available on https://jitpack.io/#hannesa2/RxAudioRecorder

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}
dependencies {
    implementation 'com.github.hannesa2:RxAudioRecorder:2.0'
}

License

Copyright 2018 Hannes Achleitner

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.

rxaudiorecorder's People

Contributors

hannesa2 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.