• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

WindSekirun/NaraeAudioRecorder: AudioRecorder for Android powered by Kotlin

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

WindSekirun/NaraeAudioRecorder

开源软件地址(OpenSource Url):

https://github.com/WindSekirun/NaraeAudioRecorder

开源编程语言(OpenSource Language):

Kotlin 100.0%

开源软件介绍(OpenSource Introduction):

NaraeAudioRecorder

Download Android Arsenal

AudioRecorder for Android powered by Kotlin.

Key Features

  • Easy to use API
  • Record on various format
    • core: pcm, wav
    • ffmpeg-recorder: mp3, m4a, wma, flac, aac
  • Pause & Resume recording
  • Integrated timer is provide maxAvailableTime feature
  • Remove background noise using NoiseSuppressor API
  • 100% write in Kotlin, but has Java Compatible
  • Detect amount of time of Silent

Import

It distributed on JCenter, but sometime it's not available.

repositories {
    maven { url "https://dl.bintray.com/windsekirun/maven/" }
}

Core

Core module will contain most feature and two format. 'pcm' and 'wav'

implementation 'com.github.WindSekirun.NaraeAudioRecorder:core:1.3.0'

FFmpeg-Recorder

FFmpeg-Recorder will contain five format, 'mp3', 'm4a', 'wma', 'flac', 'aac'

This module will increase Final APK Size about 20MB. You can reduce APK Size by this guide

implementation 'nl.bravobit:android-ffmpeg:1.1.5'
implementation 'com.github.WindSekirun.NaraeAudioRecorder:ffmpeg-recorder:1.3.0'

Usages

Core

Initialization

 val audioRecorder = NaraeAudioRecorder()
 val destFile = File(Environment.getExternalStorageDirectory(), "/NaraeAudioRecorder/$fileName$extensions")
 audioRecorder.create() {
            this.destFile = destFile
 }

Define instance of 'NaraeAudioRecorder' and create file and provide with NaraeAudioRecorder.create is fine.

If you want use NoiseSuppressor, define instance of NoiseAudioSource and provide with NaraeAudioRecorder.create.

val recordConfig = AudioRecordConfig.defaultConfig()
val audioSource = NoiseAudioSource(recordConfig)
audioRecorder.create() {
          this.destFile = this.destFile
          this.recordConfig = recordConfig
          this.audioSource = audioSource
}

Initialization in Java

This is full sample of 'initialization in Java'. other feature is same.

File destFile = new File(getContext().getExternalFilesDir(null) + String.format("/recorder/%s.mp3", fileName));
destFile.getParentFile().mkdirs();

mAudioRecorder.checkPermission(getContext());
mAudioRecorder.create(FFmpegRecordFinder.class, config -> {
    config.setDestFile(destFile);
    config.setDebugMode(true);
    config.setTimerCountListener((currentTime, maxTime) -> { 
    });
            
    return null;
});

FFmpegAudioRecorder ffmpegAudioRecorder = (FFmpegAudioRecorder) mAudioRecorder.getAudioRecorder();
ffmpegAudioRecorder.setContext(getContext());
ffmpegAudioRecorder.setOnConvertStateChangeListener(state -> {
    if (state == FFmpegConvertState.SUCCESS) {
        mRecordedPath = destFile.getPath();
    }
});

Permission

Starting from 1.2.0, if permission isn't granted, NaraeAudioRecorder will throw RuntimeException.

  • RECORD_AUDIO
  • WRITE_EXTERNAL_STORAGE
  • READ_EXTERNAL_STORAGE

So make sure grant proper permissions before using startRecording function.

Start / Stop / Pause / Resume

audioRecorder.startRecording(Context)
audioRecorder.stopRecording()
audioRecorder.pauseRecording()
audioRecorder.resumeRecording()

Custom config of AudioRecord

You can custom config of AudioRecord with AudioRecordConfig

fun defaultConfig() = AudioRecordConfig(MediaRecorder.AudioSource.MIC,
                AudioFormat.ENCODING_PCM_16BIT,
                AudioFormat.CHANNEL_IN_MONO,
                AudioConstants.FREQUENCY_44100)

Listen about state changes of record

audioRecorder.setOnRecordStateChangeListener(OnRecordStateChangeListener)

Set maxAvailableTime & Listen about changes of timer

audioRecorder.create(FFmpegRecordFinder::class.java) {
          ...
          this.maxAvailableMillis = TimeUnit.SECONDS.toMillis(20)
          this.timerCountListener = { currentTime, maxTime -> }
}

If you want use accuracy, define refreshTimerMillis in create section will be help for you. Default is 50.

FFmpeg-recorder

Using FFmpeg-recorder will need some additional info.

audioRecorder.create(FFmpegRecordFinder::class.java) {
            this.destFile = this.destFile
            this.recordConfig = recordConfig
            this.audioSource = audioSource
}

val ffmpegAudioRecorder: FFmpegAudioRecorder = audioRecorder.getAudioRecorder() as? FFmpegAudioRecorder ?: return
ffmpegAudioRecorder.setContext(this)

In parameters of create, use FFmpegRecordFinder::class.java to determine proper recorder with destFile .

FFmpeg-recorder uses WavAudioRecorder internally, recording in wav and convert them to desire format using FFmpeg command.

Change config of FFmpeg

You can custom config of FFmpeg using this options.

ffmpegAudioRecorder.setConvertConfig(FFmpegConvertConfig)

Default value is fun defaultConfig() = FFmpegConvertConfig(bitRate = FFmpegBitRate.def, samplingRate = FFmpegSamplingRate.ORIGINAL, mono = true).

Listen about state changes of convert

ffmpegAudioRecorder.setOnConvertStateChangeListener(OnConvertStateChangeListener)

Sample Application

Code

License

Core

Copyright 2019, WindSekirun (DongGil, Seo)

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.

FFmpeg-recorder




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap