├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── styles.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── layout
│ │ │ │ ├── activity_list.xml
│ │ │ │ ├── adapter_file_list.xml
│ │ │ │ └── activity_main.xml
│ │ │ ├── drawable-v24
│ │ │ │ └── ic_launcher_foreground.xml
│ │ │ └── drawable
│ │ │ │ └── ic_launcher_background.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── dreamfish
│ │ │ │ └── audiorecord
│ │ │ │ ├── ListActivity.java
│ │ │ │ ├── FileListAdapter.java
│ │ │ │ └── MainActivity.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── dreamfish
│ │ │ └── audiorecord
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── dreamfish
│ │ └── audiorecord
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── record
├── .gitignore
├── consumer-rules.pro
├── src
│ ├── main
│ │ ├── res
│ │ │ └── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── styles.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── dreamfish
│ │ │ │ └── record
│ │ │ │ ├── RecordStreamListener.java
│ │ │ │ ├── WaveHeader.java
│ │ │ │ ├── FileUtil.java
│ │ │ │ ├── PcmToWav.java
│ │ │ │ └── AudioRecorder.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── dreamfish
│ │ │ └── record
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── dreamfish
│ │ └── record
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .idea
├── misc.xml
├── runConfigurations.xml
├── checkstyle-idea.xml
└── codeStyles
│ └── Project.xml
├── gradle.properties
├── README.md
├── .gitignore
├── gradlew.bat
├── gradlew
└── LICENSE
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/record/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/record/consumer-rules.pro:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | rootProject.name='AudioRecord'
2 | include ':app'
3 | include ':record'
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | AudioRecord
3 |
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kevinchen797/AudioRecorder/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/record/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | PauseRecord
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kevinchen797/AudioRecorder/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kevinchen797/AudioRecorder/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kevinchen797/AudioRecorder/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kevinchen797/AudioRecorder/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kevinchen797/AudioRecorder/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kevinchen797/AudioRecorder/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kevinchen797/AudioRecorder/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kevinchen797/AudioRecorder/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kevinchen797/AudioRecorder/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kevinchen797/AudioRecorder/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #6200EE
4 | #3700B3
5 | #03DAC5
6 |
7 |
--------------------------------------------------------------------------------
/record/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/record/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon May 11 11:07:54 CST 2020
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
7 |
--------------------------------------------------------------------------------
/record/src/main/java/com/dreamfish/record/RecordStreamListener.java:
--------------------------------------------------------------------------------
1 | package com.dreamfish.record;
2 |
3 | /**
4 | * 获取录音的音频流,用于拓展的处理
5 | * @author chenmy0709
6 | * @version V001R001C01B001
7 | */
8 | public interface RecordStreamListener {
9 | void recordOfByte(byte[] data, int begin, int end);
10 | }
11 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_list.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/record/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/record/src/test/java/com/dreamfish/record/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.dreamfish.record;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/app/src/test/java/com/dreamfish/audiorecord/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.dreamfish.audiorecord;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/record/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/checkstyle-idea.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/record/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/record/src/androidTest/java/com/dreamfish/record/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.dreamfish.record;
2 |
3 | import android.content.Context;
4 |
5 | import androidx.test.platform.app.InstrumentationRegistry;
6 | import androidx.test.ext.junit.runners.AndroidJUnit4;
7 |
8 | import org.junit.Test;
9 | import org.junit.runner.RunWith;
10 |
11 | import static org.junit.Assert.*;
12 |
13 | /**
14 | * Instrumented test, which will execute on an Android device.
15 | *
16 | * @see Testing documentation
17 | */
18 | @RunWith(AndroidJUnit4.class)
19 | public class ExampleInstrumentedTest {
20 | @Test
21 | public void useAppContext() {
22 | // Context of the app under test.
23 | Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
24 |
25 | assertEquals("com.dreamfish.record.test", appContext.getPackageName());
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/dreamfish/audiorecord/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.dreamfish.audiorecord;
2 |
3 | import android.content.Context;
4 |
5 | import androidx.test.platform.app.InstrumentationRegistry;
6 | import androidx.test.ext.junit.runners.AndroidJUnit4;
7 |
8 | import org.junit.Test;
9 | import org.junit.runner.RunWith;
10 |
11 | import static org.junit.Assert.*;
12 |
13 | /**
14 | * Instrumented test, which will execute on an Android device.
15 | *
16 | * @see Testing documentation
17 | */
18 | @RunWith(AndroidJUnit4.class)
19 | public class ExampleInstrumentedTest {
20 | @Test
21 | public void useAppContext() {
22 | // Context of the app under test.
23 | Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
24 |
25 | assertEquals("com.dreamfish.audiorecord", appContext.getPackageName());
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/record/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 29
5 | buildToolsVersion "29.0.2"
6 |
7 | defaultConfig {
8 | minSdkVersion 14
9 | targetSdkVersion 29
10 | versionCode 1
11 | versionName "1.0"
12 |
13 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
14 | consumerProguardFiles 'consumer-rules.pro'
15 | }
16 |
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 |
24 | }
25 |
26 | dependencies {
27 | implementation fileTree(dir: 'libs', include: ['*.jar'])
28 |
29 | implementation 'androidx.appcompat:appcompat:1.1.0'
30 | testImplementation 'junit:junit:4.12'
31 | androidTestImplementation 'androidx.test.ext:junit:1.1.1'
32 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
33 | }
34 |
--------------------------------------------------------------------------------
/app/src/main/java/com/dreamfish/audiorecord/ListActivity.java:
--------------------------------------------------------------------------------
1 | package com.dreamfish.audiorecord;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.widget.ListView;
6 |
7 | import com.dreamfish.record.FileUtil;
8 |
9 | import java.io.File;
10 | import java.util.ArrayList;
11 | import java.util.List;
12 |
13 | /**
14 | * Created by HXL on 16/8/11.
15 | */
16 | public class ListActivity extends Activity {
17 | ListView listView;
18 | List list = new ArrayList<>();
19 | FileListAdapter adapter;
20 |
21 | @Override
22 | protected void onCreate(Bundle savedInstanceState) {
23 | super.onCreate(savedInstanceState);
24 | setContentView(R.layout.activity_list);
25 | listView = (ListView) findViewById(R.id.listView);
26 | if ("pcm".equals(getIntent().getStringExtra("type"))) {
27 | list = FileUtil.getPcmFiles();
28 | } else {
29 | list = FileUtil.getWavFiles();
30 | }
31 |
32 | adapter = new FileListAdapter(this, list);
33 | listView.setAdapter(adapter);
34 |
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 29
5 | buildToolsVersion "29.0.2"
6 |
7 | defaultConfig {
8 | applicationId "com.dreamfish.audiorecord"
9 | minSdkVersion 14
10 | targetSdkVersion 29
11 | versionCode 1
12 | versionName "1.0"
13 |
14 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
15 | }
16 |
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 |
24 | }
25 |
26 | dependencies {
27 | implementation fileTree(dir: 'libs', include: ['*.jar'])
28 |
29 | implementation 'androidx.appcompat:appcompat:1.1.0'
30 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
31 | testImplementation 'junit:junit:4.12'
32 | androidTestImplementation 'androidx.test.ext:junit:1.1.1'
33 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
34 | implementation project(':record')
35 | }
36 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app's APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Automatically convert third-party libraries to use AndroidX
19 | android.enableJetifier=true
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/adapter_file_list.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
16 |
17 |
26 |
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # AudioRecorder
2 | 
3 |
4 | 上一篇文章介绍了使用 MediaRecorder 实现录音功能 [Android录音实现(MediaRecorder)](http://www.jianshu.com/p/de779d509e6c) ,下面我们继续看看使用 AudioRecord 实现录音功能。
5 |
6 | ### AudioRecord
7 |
8 | 首先看看Android帮助文档中对该类的简单概述: AndioRecord 类的主要功能是让各种 Java 应用能够管理音频资源,以便它们通过此类能够录制平台的声音输入硬件所收集的声音。此功能的实现就是通过 "pulling 同步"(reading读取)AudioRecord 对象的声音数据来完成的。在录音过程中,应用所需要做的就是通过后面三个类方法中的一个去及时地获取 AudioRecord 对象的录音数据。 AudioRecord 类提供的三个获取声音数据的方法分别是 read(byte[], int, int), read(short[], int, int), read(ByteBuffer, int)。无论选择使用那一个方法都必须事先设定方便用户的声音数据的存储格式。
9 |
10 | 开始录音的时候,一个 AudioRecord 需要初始化一个相关联的声音buffer,这个 buffer 主要是用来保存新的声音数据。这个 buffer 的大小,我们可以在对象构造期间去指定。它表明一个 AudioRecord 对象还没有被读取(同步)声音数据前能录多长的音(即一次可以录制的声音容量)。声音数据从音频硬件中被读出,数据大小不超过整个录音数据的大小(可以分多次读出),即每次读取初始化 buffer 容量的数据。
11 |
12 | 采集工作很简单,我们只需要构造一个AudioRecord对象,然后传入各种不同配置的参数即可。一般情况下录音实现的简单流程如下:
13 |
14 | 1. 音频源:我们可以使用麦克风作为采集音频的数据源。
15 |
16 | 2. 采样率:一秒钟对声音数据的采样次数,采样率越高,音质越好。
17 |
18 | 3. 音频通道:单声道,双声道等,
19 |
20 | 4. 音频格式:一般选用PCM格式,即原始的音频样本。
21 |
22 | 5. 缓冲区大小:音频数据写入缓冲区的总数,可以通过AudioRecord.getMinBufferSize获取最小的缓冲区。(将音频采集到缓冲区中然后再从缓冲区中读取)。
23 |
24 |
25 | AudioRecorder 录音声音数据从音频硬件中被读出,编码格式为 PCM格式,但 PCM语音数据,如果保存成音频文件,是不能够被播放器播放的,所以必须先写代码实现数据编码以及压缩。下面实现 PCM 语音数据转为 WAV 文件。
26 |
27 | 总结:AudioRecorder 录音相比较 MediaRecorder 使用起来会麻烦一些,但优点也是显而易见的,AudioRecorder 录音时直接操纵硬件获取音频流数据,该过程是实时处理,可以用代码实现各种音频的封装,同时也可实现暂停功能,关于实现暂停录音功能今天在这里就不赘述了,推荐大家阅读 imhxl 博主的分享 http://blog.csdn.net/imhxl/article/details/52190451 。
28 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
14 |
15 |
22 |
23 |
31 |
32 |
40 |
41 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.aar
4 | *.ap_
5 | *.aab
6 |
7 | # Files for the ART/Dalvik VM
8 | *.dex
9 |
10 | # Java class files
11 | *.class
12 |
13 | # Generated files
14 | bin/
15 | gen/
16 | out/
17 | # Uncomment the following line in case you need and you don't have the release build type files in your app
18 | # release/
19 |
20 | # Gradle files
21 | .gradle/
22 | build/
23 |
24 | # Local configuration file (sdk path, etc)
25 | local.properties
26 |
27 | # Proguard folder generated by Eclipse
28 | proguard/
29 |
30 | # Log Files
31 | *.log
32 |
33 | # Android Studio Navigation editor temp files
34 | .navigation/
35 |
36 | # Android Studio captures folder
37 | captures/
38 |
39 | # IntelliJ
40 | *.iml
41 | .idea/workspace.xml
42 | .idea/tasks.xml
43 | .idea/gradle.xml
44 | .idea/assetWizardSettings.xml
45 | .idea/dictionaries
46 | .idea/libraries
47 | # Android Studio 3 in .gitignore file.
48 | .idea/caches
49 | .idea/modules.xml
50 | # Comment next line if keeping position of elements in Navigation Editor is relevant for you
51 | .idea/navEditor.xml
52 |
53 | # Keystore files
54 | # Uncomment the following lines if you do not want to check your keystore files in.
55 | #*.jks
56 | #*.keystore
57 |
58 | # External native build folder generated in Android Studio 2.2 and later
59 | .externalNativeBuild
60 | .cxx/
61 |
62 | # Google Services (e.g. APIs or Firebase)
63 | # google-services.json
64 |
65 | # Freeline
66 | freeline.py
67 | freeline/
68 | freeline_project_description.json
69 |
70 | # fastlane
71 | fastlane/report.xml
72 | fastlane/Preview.html
73 | fastlane/screenshots
74 | fastlane/test_output
75 | fastlane/readme.md
76 |
77 | # Version control
78 | vcs.xml
79 |
80 | # lint
81 | lint/intermediates/
82 | lint/generated/
83 | lint/outputs/
84 | lint/tmp/
85 | # lint/reports/
86 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
15 |
18 |
21 |
22 |
23 |
24 |
30 |
--------------------------------------------------------------------------------
/record/src/main/java/com/dreamfish/record/WaveHeader.java:
--------------------------------------------------------------------------------
1 | package com.dreamfish.record;
2 |
3 | import java.io.ByteArrayOutputStream;
4 | import java.io.IOException;
5 |
6 | /**
7 | * @author chenmy0709
8 | * @version V001R001C01B001
9 | */
10 | public class WaveHeader {
11 | public final char fileID[] = {'R', 'I', 'F', 'F'};
12 | public int fileLength;
13 | public char wavTag[] = {'W', 'A', 'V', 'E'};;
14 | public char FmtHdrID[] = {'f', 'm', 't', ' '};
15 | public int FmtHdrLeth;
16 | public short FormatTag;
17 | public short Channels;
18 | public int SamplesPerSec;
19 | public int AvgBytesPerSec;
20 | public short BlockAlign;
21 | public short BitsPerSample;
22 | public char DataHdrID[] = {'d','a','t','a'};
23 | public int DataHdrLeth;
24 |
25 | public byte[] getHeader() throws IOException {
26 | ByteArrayOutputStream bos = new ByteArrayOutputStream();
27 | WriteChar(bos, fileID);
28 | WriteInt(bos, fileLength);
29 | WriteChar(bos, wavTag);
30 | WriteChar(bos, FmtHdrID);
31 | WriteInt(bos,FmtHdrLeth);
32 | WriteShort(bos,FormatTag);
33 | WriteShort(bos,Channels);
34 | WriteInt(bos,SamplesPerSec);
35 | WriteInt(bos,AvgBytesPerSec);
36 | WriteShort(bos,BlockAlign);
37 | WriteShort(bos,BitsPerSample);
38 | WriteChar(bos,DataHdrID);
39 | WriteInt(bos,DataHdrLeth);
40 | bos.flush();
41 | byte[] r = bos.toByteArray();
42 | bos.close();
43 | return r;
44 | }
45 |
46 | private void WriteShort(ByteArrayOutputStream bos, int s) throws IOException {
47 | byte[] mybyte = new byte[2];
48 | mybyte[1] =(byte)( (s << 16) >> 24 );
49 | mybyte[0] =(byte)( (s << 24) >> 24 );
50 | bos.write(mybyte);
51 | }
52 |
53 |
54 | private void WriteInt(ByteArrayOutputStream bos, int n) throws IOException {
55 | byte[] buf = new byte[4];
56 | buf[3] =(byte)( n >> 24 );
57 | buf[2] =(byte)( (n << 8) >> 24 );
58 | buf[1] =(byte)( (n << 16) >> 24 );
59 | buf[0] =(byte)( (n << 24) >> 24 );
60 | bos.write(buf);
61 | }
62 |
63 | private void WriteChar(ByteArrayOutputStream bos, char[] id) {
64 | for (int i=0; iNUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/app/src/main/java/com/dreamfish/audiorecord/FileListAdapter.java:
--------------------------------------------------------------------------------
1 | package com.dreamfish.audiorecord;
2 |
3 | import android.content.Context;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.BaseAdapter;
8 | import android.widget.TextView;
9 |
10 | import java.io.File;
11 | import java.text.DecimalFormat;
12 | import java.util.List;
13 |
14 | /**
15 | * Created by HXL on 16/3/14.
16 | */
17 | public class FileListAdapter extends BaseAdapter {
18 | Context context;
19 | List list;
20 |
21 | public FileListAdapter(Context context, List list) {
22 | this.context = context;
23 | this.list = list;
24 | }
25 |
26 | @Override
27 | public int getCount() {
28 | return list.size();
29 | }
30 |
31 | @Override
32 | public Object getItem(int position) {
33 | return list.get(position);
34 | }
35 |
36 | @Override
37 | public long getItemId(int position) {
38 | return position;
39 | }
40 |
41 | @Override
42 | public View getView(int position, View convertView, ViewGroup parent) {
43 | ViewHolder viewHolder;
44 | if (convertView == null) {
45 | viewHolder = new ViewHolder();
46 | convertView = LayoutInflater.from(context).inflate(R.layout.adapter_file_list, null);
47 | convertView.setTag(viewHolder);
48 | viewHolder.name = (TextView) convertView.findViewById(R.id.adapter_file_list_name);
49 | viewHolder.size = (TextView) convertView.findViewById(R.id.adapter_file_list_create_size);
50 | } else {
51 | viewHolder = (ViewHolder) convertView.getTag();
52 | }
53 | viewHolder.name.setText(list.get(position).getName());
54 | viewHolder.size.setText(FormetFileSize(list.get(position).length()));
55 |
56 | return convertView;
57 | }
58 |
59 | public String FormetFileSize(long fileS) {// 转换文件大小
60 | DecimalFormat df = new DecimalFormat("#.00");
61 | String fileSizeString = "";
62 | if (fileS < 1024) {
63 | fileSizeString = df.format((double) fileS) + "B";
64 | } else if (fileS < 1048576) {
65 | fileSizeString = df.format((double) fileS / 1024) + "K";
66 | } else if (fileS < 1073741824) {
67 | fileSizeString = df.format((double) fileS / 1048576) + "M";
68 | } else {
69 | fileSizeString = df.format((double) fileS / 1073741824) + "G";
70 | }
71 | return fileSizeString;
72 | }
73 |
74 | static class ViewHolder {
75 | TextView name;
76 | TextView size;
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | xmlns:android
14 |
15 | ^$
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 | xmlns:.*
25 |
26 | ^$
27 |
28 |
29 | BY_NAME
30 |
31 |
32 |
33 |
34 |
35 |
36 | .*:id
37 |
38 | http://schemas.android.com/apk/res/android
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 | .*:name
48 |
49 | http://schemas.android.com/apk/res/android
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 | name
59 |
60 | ^$
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 | style
70 |
71 | ^$
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 | .*
81 |
82 | ^$
83 |
84 |
85 | BY_NAME
86 |
87 |
88 |
89 |
90 |
91 |
92 | .*
93 |
94 | http://schemas.android.com/apk/res/android
95 |
96 |
97 | ANDROID_ATTRIBUTE_ORDER
98 |
99 |
100 |
101 |
102 |
103 |
104 | .*
105 |
106 | .*
107 |
108 |
109 | BY_NAME
110 |
111 |
112 |
113 |
114 |
115 |
116 |
--------------------------------------------------------------------------------
/record/src/main/java/com/dreamfish/record/FileUtil.java:
--------------------------------------------------------------------------------
1 | package com.dreamfish.record;
2 |
3 | import android.os.Environment;
4 | import android.text.TextUtils;
5 |
6 | import java.io.File;
7 | import java.util.ArrayList;
8 | import java.util.List;
9 |
10 | /**
11 | * 管理录音文件的类
12 | *
13 | * @author chenmy0709
14 | * @version V001R001C01B001
15 | */
16 | public class FileUtil {
17 |
18 | private static String rootPath = "pauseRecordDemo";
19 | //原始文件(不能播放)
20 | private final static String AUDIO_PCM_BASEPATH = "/" + rootPath + "/pcm/";
21 | //可播放的高质量音频文件
22 | private final static String AUDIO_WAV_BASEPATH = "/" + rootPath + "/wav/";
23 |
24 | private static void setRootPath(String rootPath) {
25 | FileUtil.rootPath = rootPath;
26 | }
27 |
28 | public static String getPcmFileAbsolutePath(String fileName) {
29 | if (TextUtils.isEmpty(fileName)) {
30 | throw new NullPointerException("fileName isEmpty");
31 | }
32 | if (!isSdcardExit()) {
33 | throw new IllegalStateException("sd card no found");
34 | }
35 | String mAudioRawPath = "";
36 | if (isSdcardExit()) {
37 | if (!fileName.endsWith(".pcm")) {
38 | fileName = fileName + ".pcm";
39 | }
40 | String fileBasePath = Environment.getExternalStorageDirectory().getAbsolutePath() + AUDIO_PCM_BASEPATH;
41 | File file = new File(fileBasePath);
42 | //创建目录
43 | if (!file.exists()) {
44 | file.mkdirs();
45 | }
46 | mAudioRawPath = fileBasePath + fileName;
47 | }
48 |
49 | return mAudioRawPath;
50 | }
51 |
52 | public static String getWavFileAbsolutePath(String fileName) {
53 | if (fileName == null) {
54 | throw new NullPointerException("fileName can't be null");
55 | }
56 | if (!isSdcardExit()) {
57 | throw new IllegalStateException("sd card no found");
58 | }
59 |
60 | String mAudioWavPath = "";
61 | if (isSdcardExit()) {
62 | if (!fileName.endsWith(".wav")) {
63 | fileName = fileName + ".wav";
64 | }
65 | String fileBasePath = Environment.getExternalStorageDirectory().getAbsolutePath() + AUDIO_WAV_BASEPATH;
66 | File file = new File(fileBasePath);
67 | //创建目录
68 | if (!file.exists()) {
69 | file.mkdirs();
70 | }
71 | mAudioWavPath = fileBasePath + fileName;
72 | }
73 | return mAudioWavPath;
74 | }
75 |
76 | /**
77 | * 判断是否有外部存储设备sdcard
78 | *
79 | * @return true | false
80 | */
81 | public static boolean isSdcardExit() {
82 | if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))
83 | return true;
84 | else
85 | return false;
86 | }
87 |
88 | /**
89 | * 获取全部pcm文件列表
90 | *
91 | * @return
92 | */
93 | public static List getPcmFiles() {
94 | List list = new ArrayList<>();
95 | String fileBasePath = Environment.getExternalStorageDirectory().getAbsolutePath() + AUDIO_PCM_BASEPATH;
96 |
97 | File rootFile = new File(fileBasePath);
98 | if (!rootFile.exists()) {
99 | } else {
100 |
101 | File[] files = rootFile.listFiles();
102 | for (File file : files) {
103 | list.add(file);
104 | }
105 |
106 | }
107 | return list;
108 |
109 | }
110 |
111 | /**
112 | * 获取全部wav文件列表
113 | *
114 | * @return
115 | */
116 | public static List getWavFiles() {
117 | List list = new ArrayList<>();
118 | String fileBasePath = Environment.getExternalStorageDirectory().getAbsolutePath() + AUDIO_WAV_BASEPATH;
119 |
120 | File rootFile = new File(fileBasePath);
121 | if (!rootFile.exists()) {
122 | } else {
123 | File[] files = rootFile.listFiles();
124 | for (File file : files) {
125 | list.add(file);
126 | }
127 |
128 | }
129 | return list;
130 | }
131 | }
132 |
--------------------------------------------------------------------------------
/app/src/main/java/com/dreamfish/audiorecord/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.dreamfish.audiorecord;
2 |
3 | import android.Manifest;
4 | import android.app.Activity;
5 | import android.content.Intent;
6 | import android.content.pm.PackageManager;
7 | import android.os.Bundle;
8 | import android.view.View;
9 | import android.widget.Button;
10 | import android.widget.Toast;
11 |
12 | import androidx.core.app.ActivityCompat;
13 |
14 | import com.dreamfish.record.AudioRecorder;
15 |
16 | import java.text.SimpleDateFormat;
17 | import java.util.Date;
18 |
19 | public class MainActivity extends Activity implements View.OnClickListener {
20 | Button start;
21 | Button pause;
22 | Button pcmList;
23 | Button wavList;
24 |
25 | AudioRecorder audioRecorder;
26 |
27 | @Override
28 | protected void onCreate(Bundle savedInstanceState) {
29 | super.onCreate(savedInstanceState);
30 | setContentView(R.layout.activity_main);
31 | init();
32 | addListener();
33 | verifyPermissions(this);
34 | }
35 |
36 | //申请录音权限
37 |
38 | private static final int GET_RECODE_AUDIO = 1;
39 |
40 | private static String[] PERMISSION_ALL = {
41 | Manifest.permission.RECORD_AUDIO,
42 | Manifest.permission.WRITE_EXTERNAL_STORAGE,
43 | Manifest.permission.READ_EXTERNAL_STORAGE,
44 | };
45 |
46 | /** 申请录音权限*/
47 | public static void verifyPermissions(Activity activity) {
48 | boolean permission = (ActivityCompat.checkSelfPermission(activity, Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED)
49 | || (ActivityCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED)
50 | || (ActivityCompat.checkSelfPermission(activity, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED);
51 | if (permission) {
52 | ActivityCompat.requestPermissions(activity, PERMISSION_ALL,
53 | GET_RECODE_AUDIO);
54 | }
55 | }
56 |
57 | private void addListener() {
58 | start.setOnClickListener(this);
59 | pause.setOnClickListener(this);
60 | pcmList.setOnClickListener(this);
61 | wavList.setOnClickListener(this);
62 | }
63 |
64 | private void init() {
65 | start = findViewById(R.id.start);
66 | pause = findViewById(R.id.pause);
67 | pcmList = findViewById(R.id.pcmList);
68 | wavList = findViewById(R.id.wavList);
69 | pause.setVisibility(View.GONE);
70 | audioRecorder = AudioRecorder.getInstance();
71 | }
72 |
73 | @Override
74 | public void onClick(View v) {
75 | switch (v.getId()) {
76 | case R.id.start:
77 | try {
78 | if (audioRecorder.getStatus() == AudioRecorder.Status.STATUS_NO_READY) {
79 | //初始化录音
80 | String fileName = new SimpleDateFormat("yyyyMMddhhmmss").format(new Date());
81 | audioRecorder.createDefaultAudio(fileName);
82 | audioRecorder.startRecord(null);
83 |
84 | start.setText("停止录音");
85 |
86 | pause.setVisibility(View.VISIBLE);
87 |
88 | } else {
89 | //停止录音
90 | audioRecorder.stopRecord();
91 | start.setText("开始录音");
92 | pause.setText("暂停录音");
93 | pause.setVisibility(View.GONE);
94 | }
95 |
96 | } catch (IllegalStateException e) {
97 | Toast.makeText(MainActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
98 | }
99 | break;
100 |
101 | case R.id.pause:
102 | try {
103 | if (audioRecorder.getStatus() == AudioRecorder.Status.STATUS_START) {
104 | //暂停录音
105 | audioRecorder.pauseRecord();
106 | pause.setText("继续录音");
107 | break;
108 |
109 | } else {
110 | audioRecorder.startRecord(null);
111 | pause.setText("暂停录音");
112 | }
113 | } catch (IllegalStateException e) {
114 | Toast.makeText(MainActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
115 | }
116 | break;
117 |
118 | case R.id.pcmList:
119 | Intent showPcmList = new Intent(MainActivity.this, ListActivity.class);
120 | showPcmList.putExtra("type", "pcm");
121 | startActivity(showPcmList);
122 | break;
123 |
124 | case R.id.wavList:
125 | Intent showWavList = new Intent(MainActivity.this, ListActivity.class);
126 | showWavList.putExtra("type", "wav");
127 | startActivity(showWavList);
128 | break;
129 | }
130 | }
131 |
132 |
133 | @Override
134 | protected void onPause() {
135 | super.onPause();
136 | if (audioRecorder.getStatus() == AudioRecorder.Status.STATUS_START) {
137 | audioRecorder.pauseRecord();
138 | pause.setText("继续录音");
139 | }
140 |
141 | }
142 |
143 | @Override
144 | protected void onDestroy() {
145 | audioRecorder.release();
146 | super.onDestroy();
147 |
148 | }
149 | }
150 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/record/src/main/java/com/dreamfish/record/PcmToWav.java:
--------------------------------------------------------------------------------
1 | package com.dreamfish.record;
2 |
3 | import android.util.Log;
4 |
5 | import java.io.BufferedInputStream;
6 | import java.io.BufferedOutputStream;
7 | import java.io.File;
8 | import java.io.FileInputStream;
9 | import java.io.FileNotFoundException;
10 | import java.io.FileOutputStream;
11 | import java.io.IOException;
12 | import java.io.InputStream;
13 | import java.io.OutputStream;
14 | import java.text.SimpleDateFormat;
15 | import java.util.Date;
16 | import java.util.List;
17 |
18 | /**
19 | * @author chenmy0709
20 | * @version V001R001C01B001
21 | */
22 | public class PcmToWav {
23 | /**
24 | * 合并多个pcm文件为一个wav文件
25 | *
26 | * @param filePathList pcm文件路径集合
27 | * @param destinationPath 目标wav文件路径
28 | * @return true|false
29 | */
30 | public static boolean mergePCMFilesToWAVFile(List filePathList,
31 | String destinationPath) {
32 | File[] file = new File[filePathList.size()];
33 | byte buffer[] = null;
34 |
35 | int TOTAL_SIZE = 0;
36 | int fileNum = filePathList.size();
37 |
38 | for (int i = 0; i < fileNum; i++) {
39 | file[i] = new File(filePathList.get(i));
40 | TOTAL_SIZE += file[i].length();
41 | }
42 |
43 | // 填入参数,比特率等等。这里用的是16位单声道 8000 hz
44 | WaveHeader header = new WaveHeader();
45 | // 长度字段 = 内容的大小(TOTAL_SIZE) +
46 | // 头部字段的大小(不包括前面4字节的标识符RIFF以及fileLength本身的4字节)
47 | header.fileLength = TOTAL_SIZE + (44 - 8);
48 | header.FmtHdrLeth = 16;
49 | header.BitsPerSample = 16;
50 | header.Channels = 2;
51 | header.FormatTag = 0x0001;
52 | header.SamplesPerSec = 8000;
53 | header.BlockAlign = (short) (header.Channels * header.BitsPerSample / 8);
54 | header.AvgBytesPerSec = header.BlockAlign * header.SamplesPerSec;
55 | header.DataHdrLeth = TOTAL_SIZE;
56 |
57 | byte[] h = null;
58 | try {
59 | h = header.getHeader();
60 | } catch (IOException e1) {
61 | Log.e("PcmToWav", e1.getMessage());
62 | return false;
63 | }
64 |
65 | if (h.length != 44) // WAV标准,头部应该是44字节,如果不是44个字节则不进行转换文件
66 | return false;
67 |
68 | //先删除目标文件
69 | File destfile = new File(destinationPath);
70 | if (destfile.exists())
71 | destfile.delete();
72 |
73 | //合成所有的pcm文件的数据,写到目标文件
74 | try {
75 | buffer = new byte[1024 * 4]; // Length of All Files, Total Size
76 | InputStream inStream = null;
77 | OutputStream ouStream = null;
78 |
79 | ouStream = new BufferedOutputStream(new FileOutputStream(
80 | destinationPath));
81 | ouStream.write(h, 0, h.length);
82 | for (int j = 0; j < fileNum; j++) {
83 | inStream = new BufferedInputStream(new FileInputStream(file[j]));
84 | int size = inStream.read(buffer);
85 | while (size != -1) {
86 | ouStream.write(buffer);
87 | size = inStream.read(buffer);
88 | }
89 | inStream.close();
90 | }
91 | ouStream.close();
92 | } catch (FileNotFoundException e) {
93 | Log.e("PcmToWav", e.getMessage());
94 | return false;
95 | } catch (IOException ioe) {
96 | Log.e("PcmToWav", ioe.getMessage());
97 | return false;
98 | }
99 | clearFiles(filePathList);
100 | Log.i("PcmToWav", "mergePCMFilesToWAVFile success!" + new SimpleDateFormat("yyyy-MM-dd hh:mm").format(new Date()));
101 | return true;
102 |
103 | }
104 |
105 | /**
106 | * 将一个pcm文件转化为wav文件
107 | *
108 | * @param pcmPath pcm文件路径
109 | * @param destinationPath 目标文件路径(wav)
110 | * @param deletePcmFile 是否删除源文件
111 | * @return
112 | */
113 | public static boolean makePCMFileToWAVFile(String pcmPath, String destinationPath, boolean deletePcmFile) {
114 | byte buffer[] = null;
115 | int TOTAL_SIZE = 0;
116 | File file = new File(pcmPath);
117 | if (!file.exists()) {
118 | return false;
119 | }
120 | TOTAL_SIZE = (int) file.length();
121 | // 填入参数,比特率等等。这里用的是16位单声道 8000 hz
122 | WaveHeader header = new WaveHeader();
123 | // 长度字段 = 内容的大小(TOTAL_SIZE) +
124 | // 头部字段的大小(不包括前面4字节的标识符RIFF以及fileLength本身的4字节)
125 | header.fileLength = TOTAL_SIZE + (44 - 8);
126 | header.FmtHdrLeth = 16;
127 | header.BitsPerSample = 16;
128 | header.Channels = 2;
129 | header.FormatTag = 0x0001;
130 | header.SamplesPerSec = 8000;
131 | header.BlockAlign = (short) (header.Channels * header.BitsPerSample / 8);
132 | header.AvgBytesPerSec = header.BlockAlign * header.SamplesPerSec;
133 | header.DataHdrLeth = TOTAL_SIZE;
134 |
135 | byte[] h = null;
136 | try {
137 | h = header.getHeader();
138 | } catch (IOException e1) {
139 | Log.e("PcmToWav", e1.getMessage());
140 | return false;
141 | }
142 |
143 | if (h.length != 44) // WAV标准,头部应该是44字节,如果不是44个字节则不进行转换文件
144 | return false;
145 |
146 | //先删除目标文件
147 | File destfile = new File(destinationPath);
148 | if (destfile.exists())
149 | destfile.delete();
150 |
151 | //合成所有的pcm文件的数据,写到目标文件
152 | try {
153 | buffer = new byte[1024 * 4]; // Length of All Files, Total Size
154 | InputStream inStream = null;
155 | OutputStream ouStream = null;
156 |
157 | ouStream = new BufferedOutputStream(new FileOutputStream(
158 | destinationPath));
159 | ouStream.write(h, 0, h.length);
160 | inStream = new BufferedInputStream(new FileInputStream(file));
161 | int size = inStream.read(buffer);
162 | while (size != -1) {
163 | ouStream.write(buffer);
164 | size = inStream.read(buffer);
165 | }
166 | inStream.close();
167 | ouStream.close();
168 | } catch (FileNotFoundException e) {
169 | Log.e("PcmToWav", e.getMessage());
170 | return false;
171 | } catch (IOException ioe) {
172 | Log.e("PcmToWav", ioe.getMessage());
173 | return false;
174 | }
175 | if (deletePcmFile) {
176 | file.delete();
177 | }
178 | Log.i("PcmToWav", "makePCMFileToWAVFile success!" + new SimpleDateFormat("yyyy-MM-dd hh:mm").format(new Date()));
179 | return true;
180 |
181 | }
182 |
183 | /**
184 | * 清除文件
185 | *
186 | * @param filePathList
187 | */
188 | private static void clearFiles(List filePathList) {
189 | for (int i = 0; i < filePathList.size(); i++) {
190 | File file = new File(filePathList.get(i));
191 | if (file.exists()) {
192 | file.delete();
193 | }
194 | }
195 | }
196 | }
197 |
--------------------------------------------------------------------------------
/record/src/main/java/com/dreamfish/record/AudioRecorder.java:
--------------------------------------------------------------------------------
1 | package com.dreamfish.record;
2 |
3 | import android.media.AudioFormat;
4 | import android.media.AudioRecord;
5 | import android.media.MediaRecorder;
6 | import android.text.TextUtils;
7 | import android.util.Log;
8 |
9 | import java.io.File;
10 | import java.io.FileNotFoundException;
11 | import java.io.FileOutputStream;
12 | import java.io.IOException;
13 | import java.util.ArrayList;
14 | import java.util.List;
15 |
16 | /**
17 | * 实现录音
18 | *
19 | * @author chenmy0709
20 | * @version V001R001C01B001
21 | */
22 | public class AudioRecorder {
23 | //音频输入-麦克风
24 | private final static int AUDIO_INPUT = MediaRecorder.AudioSource.MIC;
25 | //采用频率
26 | //44100是目前的标准,但是某些设备仍然支持22050,16000,11025
27 | //采样频率一般共分为22.05KHz、44.1KHz、48KHz三个等级
28 | private final static int AUDIO_SAMPLE_RATE = 16000;
29 | //声道 单声道
30 | private final static int AUDIO_CHANNEL = AudioFormat.CHANNEL_IN_MONO;
31 | //编码
32 | private final static int AUDIO_ENCODING = AudioFormat.ENCODING_PCM_16BIT;
33 | // 缓冲区字节大小
34 | private int bufferSizeInBytes = 0;
35 |
36 | //录音对象
37 | private AudioRecord audioRecord;
38 |
39 | //录音状态
40 | private Status status = Status.STATUS_NO_READY;
41 |
42 | //文件名
43 | private String fileName;
44 |
45 | //录音文件
46 | private List filesName = new ArrayList<>();
47 |
48 |
49 | /**
50 | * 类级的内部类,也就是静态类的成员式内部类,该内部类的实例与外部类的实例
51 | * 没有绑定关系,而且只有被调用时才会装载,从而实现了延迟加载
52 | */
53 | private static class AudioRecorderHolder {
54 | /**
55 | * 静态初始化器,由JVM来保证线程安全
56 | */
57 | private static AudioRecorder instance = new AudioRecorder();
58 | }
59 |
60 | private AudioRecorder() {
61 | }
62 |
63 | public static AudioRecorder getInstance() {
64 | return AudioRecorderHolder.instance;
65 | }
66 |
67 | /**
68 | * 创建录音对象
69 | */
70 | public void createAudio(String fileName, int audioSource, int sampleRateInHz, int channelConfig, int audioFormat) {
71 | // 获得缓冲区字节大小
72 | bufferSizeInBytes = AudioRecord.getMinBufferSize(sampleRateInHz,
73 | channelConfig, channelConfig);
74 | audioRecord = new AudioRecord(audioSource, sampleRateInHz, channelConfig, audioFormat, bufferSizeInBytes);
75 | this.fileName = fileName;
76 | }
77 |
78 | /**
79 | * 创建默认的录音对象
80 | *
81 | * @param fileName 文件名
82 | */
83 | public void createDefaultAudio(String fileName) {
84 | // 获得缓冲区字节大小
85 | bufferSizeInBytes = AudioRecord.getMinBufferSize(AUDIO_SAMPLE_RATE,
86 | AUDIO_CHANNEL, AUDIO_ENCODING);
87 | audioRecord = new AudioRecord(AUDIO_INPUT, AUDIO_SAMPLE_RATE, AUDIO_CHANNEL, AUDIO_ENCODING, bufferSizeInBytes);
88 | this.fileName = fileName;
89 | status = Status.STATUS_READY;
90 | }
91 |
92 |
93 | /**
94 | * 开始录音
95 | *
96 | * @param listener 音频流的监听
97 | */
98 | public void startRecord(final RecordStreamListener listener) {
99 |
100 | if (status == Status.STATUS_NO_READY || TextUtils.isEmpty(fileName)) {
101 | throw new IllegalStateException("录音尚未初始化,请检查是否禁止了录音权限~");
102 | }
103 | if (status == Status.STATUS_START) {
104 | throw new IllegalStateException("正在录音");
105 | }
106 | Log.d("AudioRecorder", "===startRecord===" + audioRecord.getState());
107 | audioRecord.startRecording();
108 |
109 | new Thread(new Runnable() {
110 | @Override
111 | public void run() {
112 | writeDataTOFile(listener);
113 | }
114 | }).start();
115 | }
116 |
117 | /**
118 | * 暂停录音
119 | */
120 | public void pauseRecord() {
121 | Log.d("AudioRecorder", "===pauseRecord===");
122 | if (status != Status.STATUS_START) {
123 | throw new IllegalStateException("没有在录音");
124 | } else {
125 | audioRecord.stop();
126 | status = Status.STATUS_PAUSE;
127 | }
128 | }
129 |
130 | /**
131 | * 停止录音
132 | */
133 | public void stopRecord() {
134 | Log.d("AudioRecorder", "===stopRecord===");
135 | if (status == Status.STATUS_NO_READY || status == Status.STATUS_READY) {
136 | throw new IllegalStateException("录音尚未开始");
137 | } else {
138 | audioRecord.stop();
139 | status = Status.STATUS_STOP;
140 | release();
141 | }
142 | }
143 |
144 | /**
145 | * 释放资源
146 | */
147 | public void release() {
148 | Log.d("AudioRecorder", "===release===");
149 | //假如有暂停录音
150 | try {
151 | if (filesName.size() > 0) {
152 | List filePaths = new ArrayList<>();
153 | for (String fileName : filesName) {
154 | filePaths.add(FileUtil.getPcmFileAbsolutePath(fileName));
155 | }
156 | //清除
157 | filesName.clear();
158 | //将多个pcm文件转化为wav文件
159 | mergePCMFilesToWAVFile(filePaths);
160 |
161 | } else {
162 | //这里由于只要录音过filesName.size都会大于0,没录音时fileName为null
163 | //会报空指针 NullPointerException
164 | // 将单个pcm文件转化为wav文件
165 | //Log.d("AudioRecorder", "=====makePCMFileToWAVFile======");
166 | //makePCMFileToWAVFile();
167 | }
168 | } catch (IllegalStateException e) {
169 | throw new IllegalStateException(e.getMessage());
170 | }
171 |
172 | if (audioRecord != null) {
173 | audioRecord.release();
174 | audioRecord = null;
175 | }
176 |
177 | status = Status.STATUS_NO_READY;
178 | }
179 |
180 | /**
181 | * 取消录音
182 | */
183 | public void canel() {
184 | filesName.clear();
185 | fileName = null;
186 | if (audioRecord != null) {
187 | audioRecord.release();
188 | audioRecord = null;
189 | }
190 |
191 | status = Status.STATUS_NO_READY;
192 | }
193 |
194 |
195 | /**
196 | * 将音频信息写入文件
197 | *
198 | * @param listener 音频流的监听
199 | */
200 | private void writeDataTOFile(RecordStreamListener listener) {
201 | // new一个byte数组用来存一些字节数据,大小为缓冲区大小
202 | byte[] audiodata = new byte[bufferSizeInBytes];
203 |
204 | FileOutputStream fos = null;
205 | int readsize = 0;
206 | try {
207 | String currentFileName = fileName;
208 | if (status == Status.STATUS_PAUSE) {
209 | //假如是暂停录音 将文件名后面加个数字,防止重名文件内容被覆盖
210 | currentFileName += filesName.size();
211 |
212 | }
213 | filesName.add(currentFileName);
214 | File file = new File(FileUtil.getPcmFileAbsolutePath(currentFileName));
215 | if (file.exists()) {
216 | file.delete();
217 | }
218 | fos = new FileOutputStream(file);// 建立一个可存取字节的文件
219 | } catch (IllegalStateException e) {
220 | Log.e("AudioRecorder", e.getMessage());
221 | throw new IllegalStateException(e.getMessage());
222 | } catch (FileNotFoundException e) {
223 | Log.e("AudioRecorder", e.getMessage());
224 |
225 | }
226 | //将录音状态设置成正在录音状态
227 | status = Status.STATUS_START;
228 | while (status == Status.STATUS_START) {
229 | readsize = audioRecord.read(audiodata, 0, bufferSizeInBytes);
230 | if (AudioRecord.ERROR_INVALID_OPERATION != readsize && fos != null) {
231 | try {
232 | fos.write(audiodata);
233 | if (listener != null) {
234 | //用于拓展业务
235 | listener.recordOfByte(audiodata, 0, audiodata.length);
236 | }
237 | } catch (IOException e) {
238 | Log.e("AudioRecorder", e.getMessage());
239 | }
240 | }
241 | }
242 | try {
243 | if (fos != null) {
244 | fos.close();// 关闭写入流
245 | }
246 | } catch (IOException e) {
247 | Log.e("AudioRecorder", e.getMessage());
248 | }
249 | }
250 |
251 | /**
252 | * 将pcm合并成wav
253 | *
254 | * @param filePaths
255 | */
256 | private void mergePCMFilesToWAVFile(final List filePaths) {
257 | new Thread(new Runnable() {
258 | @Override
259 | public void run() {
260 | if (PcmToWav.mergePCMFilesToWAVFile(filePaths, FileUtil.getWavFileAbsolutePath(fileName))) {
261 | //操作成功
262 | } else {
263 | //操作失败
264 | Log.e("AudioRecorder", "mergePCMFilesToWAVFile fail");
265 | throw new IllegalStateException("mergePCMFilesToWAVFile fail");
266 | }
267 | fileName = null;
268 | }
269 | }).start();
270 | }
271 |
272 | /**
273 | * 将单个pcm文件转化为wav文件
274 | */
275 | private void makePCMFileToWAVFile() {
276 | new Thread(new Runnable() {
277 | @Override
278 | public void run() {
279 | if (PcmToWav.makePCMFileToWAVFile(FileUtil.getPcmFileAbsolutePath(fileName), FileUtil.getWavFileAbsolutePath(fileName), true)) {
280 | //操作成功
281 | } else {
282 | //操作失败
283 | Log.e("AudioRecorder", "makePCMFileToWAVFile fail");
284 | throw new IllegalStateException("makePCMFileToWAVFile fail");
285 | }
286 | fileName = null;
287 | }
288 | }).start();
289 | }
290 |
291 | /**
292 | * 获取录音对象的状态
293 | *
294 | * @return
295 | */
296 | public Status getStatus() {
297 | return status;
298 | }
299 |
300 | /**
301 | * 获取本次录音文件的个数
302 | *
303 | * @return
304 | */
305 | public int getPcmFilesCount() {
306 | return filesName.size();
307 | }
308 |
309 | /**
310 | * 录音对象的状态
311 | */
312 | public enum Status {
313 | //未开始
314 | STATUS_NO_READY,
315 | //预备
316 | STATUS_READY,
317 | //录音
318 | STATUS_START,
319 | //暂停
320 | STATUS_PAUSE,
321 | //停止
322 | STATUS_STOP
323 | }
324 |
325 | }
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------