File tree Expand file tree Collapse file tree 2 files changed +29
-9
lines changed
android-wave-recorder/src/main/java/com/github/squti/androidwaverecorder
sample/src/main/java/com/github/squti/androidwaverecordersample Expand file tree Collapse file tree 2 files changed +29
-9
lines changed Original file line number Diff line number Diff line change @@ -53,12 +53,12 @@ class WaveRecorder(private var filePath: String) {
53
53
/* *
54
54
* Configuration for recording audio file.
55
55
*/
56
+ @Deprecated(
57
+ " Use configureWaveSettings to set recording configuration. Access to this property will not be available in the future."
58
+ )
56
59
var waveConfig: WaveConfig = WaveConfig ()
57
60
58
- /* *
59
- * Configuration for Silence Detection.
60
- */
61
- var silenceDetectionConfig: SilenceDetectionConfig = SilenceDetectionConfig (30 )
61
+ private var silenceDetectionConfig: SilenceDetectionConfig = SilenceDetectionConfig (30 )
62
62
63
63
/* *
64
64
* Register a callback to be invoked in every recorded chunk of audio data
@@ -106,6 +106,22 @@ class WaveRecorder(private var filePath: String) {
106
106
private var silenceDuration = 0L
107
107
private var currentState: RecorderState = RecorderState .STOP
108
108
109
+ /* *
110
+ * Set configuration for recording audio file.
111
+ */
112
+ fun configureWaveSettings (block : WaveConfig .() -> Unit ): WaveRecorder {
113
+ waveConfig.apply (block)
114
+ return this
115
+ }
116
+
117
+ /* *
118
+ * Set configuration for Silence Detection.
119
+ */
120
+ fun configureSilenceDetection (block : SilenceDetectionConfig .() -> Unit ): WaveRecorder {
121
+ silenceDetectionConfig.apply (block)
122
+ return this
123
+ }
124
+
109
125
/* *
110
126
* Starts audio recording asynchronously and writes recorded data chunks on storage.
111
127
*/
Original file line number Diff line number Diff line change @@ -35,7 +35,6 @@ import androidx.appcompat.app.AppCompatActivity
35
35
import androidx.core.app.ActivityCompat
36
36
import androidx.core.content.ContextCompat
37
37
import com.github.squti.androidwaverecorder.RecorderState
38
- import com.github.squti.androidwaverecorder.SilenceDetectionConfig
39
38
import com.github.squti.androidwaverecorder.WaveRecorder
40
39
import com.github.squti.androidwaverecordersample.databinding.ActivityMainBinding
41
40
import java.util.Locale
@@ -58,10 +57,15 @@ class MainActivity : AppCompatActivity() {
58
57
filePath = filesDir.absolutePath + " /audioFile.wav"
59
58
60
59
waveRecorder = WaveRecorder (filePath)
61
- waveRecorder.waveConfig.sampleRate = 44100
62
- waveRecorder.waveConfig.channels = AudioFormat .CHANNEL_IN_MONO
63
- waveRecorder.waveConfig.audioEncoding = AudioFormat .ENCODING_PCM_32BIT
64
- waveRecorder.silenceDetectionConfig = SilenceDetectionConfig (minAmplitudeThreshold = 80 )
60
+ .configureWaveSettings {
61
+ sampleRate = 44100
62
+ channels = AudioFormat .CHANNEL_IN_STEREO
63
+ audioEncoding = AudioFormat .ENCODING_PCM_32BIT
64
+ }.configureSilenceDetection {
65
+ minAmplitudeThreshold = 80
66
+ bufferDurationInMillis = 1500
67
+ preSilenceDurationInMillis = 1500
68
+ }
65
69
66
70
67
71
You can’t perform that action at this time.
0 commit comments