Skip to content

Commit e4e80d4

Browse files
authored
Update README.md for V2.0.0 release
1 parent 9e9d8d1 commit e4e80d4

File tree

1 file changed

+71
-29
lines changed

1 file changed

+71
-29
lines changed

README.md

Lines changed: 71 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
[![](https://jitpack.io/v/squti/Android-Wave-Recorder.svg)](https://jitpack.io/#squti/Android-Wave-Recorder)
33
[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-Android%20Wave%20Recorder-brightgreen.svg?style=flat)](https://android-arsenal.com/details/1/7939)
44

5-
A powerful and efficient library to record WAVE form audio files (WAV) in Android
5+
A powerful and efficient library to record WAVE form audio files (WAV) in Android with Float and 32-bit encoding support.
66
<p align="center">
77
<img width="300" height="300" src="https://raw.githubusercontent.com/squti/Android-Wave-Recorder/master/static/android-wave-recorder-logo.png">
88
</p>
99

10-
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.
10+
Android Wave Recorder is a lightweight library written in Kotlin to record audio files in WAVE (WAV) format on Android. It’s memory efficient and easy to use, with customizable recording options like Silence Detection and high-quality audio encoding (Float and 32-bit)
1111

1212
### Download
13-
Step 1. Add this in your root (Project) build.gradle at the end of repositories:
13+
Step 1. Add this to your root (Project) `build.gradle` at the end of repositories:
1414
```gradle
1515
allprojects {
1616
repositories {
@@ -19,39 +19,59 @@ allprojects {
1919
}
2020
}
2121
```
22-
Step 2. Add the dependency
22+
Step 2. Add the following dependency to your module `build.gradle`:
2323
```gradle
2424
dependencies{
25-
implementation 'com.github.squti:Android-Wave-Recorder:1.7.0'
25+
implementation 'com.github.squti:Android-Wave-Recorder:2.0.0'
2626
}
2727
```
2828
### Permission
29-
Add these permissions into your `AndroidManifest.xml` and [request for them in Android 6.0+](https://developer.android.com/training/permissions/requesting.html)
29+
Add these permissions to your `AndroidManifest.xml` and [request them at runtime for Android 6.0+](https://developer.android.com/training/permissions/requesting.html)
3030
```xml
3131
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
3232
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
3333
```
34-
34+
If you use [Scoped Storage](https://source.android.com/docs/core/storage/scoped) there is an example in the [Sample](https://github.com/squti/Android-Wave-Recorder/tree/master/sample) project.
3535
### Usage
36-
Pass in the path of the output file to `WaveRecorder` class and call `startRecording()` like this:
36+
Pass the path of the output file to the `WaveRecorder` class and call `startRecording()`:
3737
```kotlin
3838
/**
39-
* This path points to application cache directory.
40-
* you could change it based on your usage
39+
* This path points to the file directory in the application's internal storage.
40+
* you can change it based on your usage
4141
*/
42-
val filePath:String = externalCacheDir?.absolutePath + "/audioFile.wav"
42+
val filePath:String = filesDir.absolutePath + "/audioFile.wav"
4343

4444
val waveRecorder = WaveRecorder(filePath)
4545
waveRecorder.startRecording()
4646

4747
```
48-
To stop recording call `stopRecording()` function:
48+
You can also pass a `URI` for the file path if you are dealing with [Scoped Storage](https://source.android.com/docs/core/storage/scoped):
49+
```kotlin
50+
val audioUri = MediaStore.Audio.Media.getContentUri(MediaStore.VOLUME_EXTERNAL_PRIMARY)
51+
val contentValues = ContentValues().apply {
52+
put(MediaStore.Audio.Media.DISPLAY_NAME, "audioFile.wav")
53+
put(MediaStore.Audio.Media.MIME_TYPE, "audio/x-wav")
54+
put(MediaStore.Audio.Media.RELATIVE_PATH, "Music/Android-Wave-Recorder")
55+
}
56+
/**
57+
* This URI points to audioFile.wav in the Android-Wave-Recorder directory in Android's default Music folder.
58+
* you can change it based on your usage
59+
*/
60+
val uri = contentResolver.insert(audioUri, contentValues)
61+
62+
val waveRecorder = WaveRecorder(uri, context = this)
63+
waveRecorder.startRecording()
64+
65+
```
66+
_[Here](https://github.com/squti/Android-Wave-Recorder/blob/master/sample/src/main/java/com/github/squti/androidwaverecordersample/MainActivity.kt) is an example of how to get URI before and after Android 10._
67+
68+
To stop recording, call the `stopRecording()` function:
4969
```kotlin
5070
waveRecorder.stopRecording()
5171

5272
```
5373

54-
To pause and resume recording you could use `pauseRecording()` and `resumeRecording()` functions:
74+
To pause and resume recording, use the `pauseRecording()` and `resumeRecording()` functions:
5575
```kotlin
5676
//Pause
5777
waveRecorder.pauseRecording()
@@ -61,48 +81,70 @@ waveRecorder.resumeRecording()
6181

6282
```
6383

64-
To activate `Noise Suppressor` you could set `noiseSuppressorActive` to true:
84+
To listen to audio amplitude during recording, register a listener to `onAmplitudeListener`:
6585
```kotlin
66-
waveRecorder.noiseSuppressorActive = true
67-
86+
waveRecorder.onAmplitudeListener = {
87+
Log.i(TAG, "Amplitude : $it")
88+
}
6889
```
90+
### Silence Detection
91+
To activate the *Silence Detection*, set `silenceDetection` to `true`:
92+
```kotlin
93+
waveRecorder.silenceDetection = true
6994

70-
To listen to audio amplitude during recording you need to register a listener to `onAmplitudeListener`:
95+
```
96+
You can adjust the silence amplitude level based on your needs. The default threshold is 1500, meaning amplitudes below 1500 are considered silence. The recorder will pause until the amplitude goes above 1500 again. By default, the recorder buffers the last 2 seconds of silence and adds it to the file when recording resumes. Silence detection waits for 2 seconds after detecting silence; if silence continues, recording pauses. The recorder will resume when it detects sound again. You can adjust the **buffer time, silence waiting time, and amplitude threshold** using `configureSilenceDetection`:
7197
```kotlin
72-
waveRecorder.onAmplitudeListener = {
73-
Log.i(TAG, "Amplitude : $it")
98+
waveRecorder.configureSilenceDetection {
99+
minAmplitudeThreshold = 2000
100+
bufferDurationInMillis = 1500
101+
preSilenceDurationInMillis = 1500
74102
}
103+
75104
```
105+
_Note 1: Buffer and Silence Waiting Time may have slight inaccuracies due to the conversion from milliseconds to bytes in the background. Adjust these settings to achieve more accurate results._
76106

77-
To listen to recording state changes **(RECORDING, STOP and PAUSE)** you need to register a listener to `onStateChangeListener`:
107+
_Note 2: Big buffer size can reduce the performance_
108+
109+
### Noise Suppression
110+
To activate the `Noise Suppressor`, set `noiseSuppressorActive` to `true`:
111+
```kotlin
112+
waveRecorder.noiseSuppressorActive = true
113+
114+
```
115+
_Note: If the device does not support Noise Suppressor it will not affect the output_
116+
117+
### Recording States
118+
To listen to recording state changes **(RECORDING, STOP, PAUSE and SKIPPING SILENCE)**, register a listener to `onStateChangeListener`:
78119
```kotlin
79120
waveRecorder.onStateChangeListener = {
80121
when (it) {
81122
RecorderState.RECORDING -> TODO()
82123
RecorderState.STOP -> TODO()
83124
RecorderState.PAUSE -> TODO()
125+
RecorderState.SKIPPING_SILENCE -> TODO()
84126
}
85127
}
86128
```
87129
### Configuration
88-
The default configuration for recording audio is like so:
130+
Android Wave Recorder supports **Float, 32-bit, 16-bit and 8-bit** encoding.
131+
132+
The default configuration for recording audio is:
89133

90134
| Property | Value |
91135
| :---: | :---: |
92136
| sampleRate | 16000 |
93137
| channels | AudioFormat.CHANNEL_IN_MONO |
94138
| audioEncoding | AudioFormat.ENCODING_PCM_16BIT |
95139

96-
But you could change it using `waveConfig` property in `WaveRecorder` class based on your usage. This is an example:
140+
You can change the configuration using `configureWaveSettings`:
97141
```kotlin
98-
val waveRecorder = WaveRecorder(filePath)
99-
waveRecorder.waveConfig.sampleRate = 44100
100-
waveRecorder.waveConfig.channels = AudioFormat.CHANNEL_IN_STEREO
101-
waveRecorder.waveConfig.audioEncoding = AudioFormat.ENCODING_PCM_8BIT
102-
waveRecorder.startRecording()
142+
waveRecorder.configureWaveSettings {
143+
sampleRate = 44100
144+
channels = AudioFormat.CHANNEL_IN_STEREO
145+
audioEncoding = AudioFormat.ENCODING_PCM_FLOAT
146+
}
103147
```
104-
_Note: Wrong configuration may impacts output quality_
105-
106148

107149
### License
108150
```

0 commit comments

Comments
 (0)