├── .gitignore ├── .idea ├── .name ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── gradle.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── carlos │ │ └── voiceline │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── carlos │ │ │ └── voiceline │ │ │ └── MainActivity.java │ └── res │ │ ├── layout │ │ ├── activity_main.xml │ │ └── content_main.xml │ │ ├── menu │ │ └── menu_main.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ ├── values-v21 │ │ └── styles.xml │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── carlos │ └── voiceline │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── line.gif ├── mylibrary ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── carlos │ │ └── voiceline │ │ └── mylibrary │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── carlos │ │ │ └── voiceline │ │ │ └── mylibrary │ │ │ ├── Arith.java │ │ │ └── VoiceLineView.java │ └── res │ │ └── values │ │ ├── attrs.xml │ │ └── strings.xml │ └── test │ └── java │ └── com │ └── carlos │ └── voiceline │ └── mylibrary │ └── ExampleUnitTest.java ├── rect.gif └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | VoiceLine -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 26 | 27 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | ####VoiceLine,一个可以根据麦克风音量大小,显示一些波形效果的控件。一共有两种效果,波开和矩形,如下。也有一些自定义属性,包括波形的颜色,灵敏度,间隔等。 3 | 4 | ![image](https://github.com/ws123/VoiceLine/blob/master/line.gif) 5 | ![image](https://github.com/ws123/VoiceLine/blob/master/rect.gif) 6 | 7 | 引用方法: 8 | 9 | ```groovy 10 | compile 'com.carlos.voiceline:mylibrary:1.0.6' 11 | ``` 12 | ####自定义属性列表如下: 13 | ```xml 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | ``` 56 | 实际使用过程中,可以这样配置: 57 | 58 | ```xml 59 | 73 | ``` 74 | 75 | ### License 76 | 77 | Copyright 2016 carlos 78 | 79 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. 80 | You may obtain a copy of the License at 81 | 82 | http://www.apache.org/licenses/LICENSE-2.0 83 | 84 | Unless required by applicable law or agreed to in writing, software 85 | distributed under the License is distributed on an "AS IS" BASIS, 86 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 87 | See the License for the specific language governing permissions and 88 | limitations under the License. 89 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.2" 6 | 7 | defaultConfig { 8 | applicationId "com.carlos.voiceline" 9 | minSdkVersion 15 10 | targetSdkVersion 22 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | testCompile 'junit:junit:4.12' 25 | compile 'com.android.support:appcompat-v7:23.1.1' 26 | compile 'com.android.support:design:23.1.1' 27 | compile project(':mylibrary') 28 | } 29 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in f:\Android\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/carlos/voiceline/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.carlos.voiceline; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 14 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /app/src/main/java/com/carlos/voiceline/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.carlos.voiceline; 2 | 3 | import android.media.MediaRecorder; 4 | import android.os.Bundle; 5 | import android.os.Environment; 6 | import android.os.Handler; 7 | import android.os.Message; 8 | import android.support.v7.app.AppCompatActivity; 9 | 10 | import com.carlos.voiceline.mylibrary.VoiceLineView; 11 | 12 | import java.io.File; 13 | import java.io.IOException; 14 | 15 | public class MainActivity extends AppCompatActivity implements Runnable { 16 | private MediaRecorder mMediaRecorder; 17 | private boolean isAlive = true; 18 | private VoiceLineView voiceLineView; 19 | private Handler handler = new Handler() { 20 | @Override 21 | public void handleMessage(Message msg) { 22 | super.handleMessage(msg); 23 | if(mMediaRecorder==null) return; 24 | double ratio = (double) mMediaRecorder.getMaxAmplitude() / 100; 25 | double db = 0;// 分贝 26 | //默认的最大音量是100,可以修改,但其实默认的,在测试过程中就有不错的表现 27 | //你可以传自定义的数字进去,但需要在一定的范围内,比如0-200,就需要在xml文件中配置maxVolume 28 | //同时,也可以配置灵敏度sensibility 29 | if (ratio > 1) 30 | db = 20 * Math.log10(ratio); 31 | //只要有一个线程,不断调用这个方法,就可以使波形变化 32 | //主要,这个方法必须在ui线程中调用 33 | voiceLineView.setVolume((int) (db)); 34 | } 35 | }; 36 | 37 | @Override 38 | protected void onCreate(Bundle savedInstanceState) { 39 | super.onCreate(savedInstanceState); 40 | setContentView(R.layout.activity_main); 41 | voiceLineView = (VoiceLineView) findViewById(R.id.voicLine); 42 | if (mMediaRecorder == null) 43 | mMediaRecorder = new MediaRecorder(); 44 | 45 | mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); 46 | mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.AMR_NB); 47 | mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT); 48 | File file = new File(Environment.getExternalStorageDirectory().getPath(), "hello.log"); 49 | if (!file.exists()) { 50 | try { 51 | file.createNewFile(); 52 | } catch (IOException e) { 53 | e.printStackTrace(); 54 | } 55 | } 56 | mMediaRecorder.setOutputFile(file.getAbsolutePath()); 57 | mMediaRecorder.setMaxDuration(1000 * 60 * 10); 58 | try { 59 | mMediaRecorder.prepare(); 60 | } catch (IOException e) { 61 | e.printStackTrace(); 62 | } 63 | mMediaRecorder.start(); 64 | 65 | Thread thread = new Thread(this); 66 | thread.start(); 67 | } 68 | 69 | @Override 70 | protected void onDestroy() { 71 | isAlive = false; 72 | mMediaRecorder.release(); 73 | mMediaRecorder = null; 74 | super.onDestroy(); 75 | } 76 | 77 | @Override 78 | public void run() { 79 | while (isAlive) { 80 | handler.sendEmptyMessage(0); 81 | try { 82 | Thread.sleep(100); 83 | } catch (InterruptedException e) { 84 | e.printStackTrace(); 85 | } 86 | } 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 23 | 24 | -------------------------------------------------------------------------------- /app/src/main/res/layout/content_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 14 | 15 | 19 | 20 | -------------------------------------------------------------------------------- /app/src/main/res/menu/menu_main.xml: -------------------------------------------------------------------------------- 1 | 5 | 10 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ws123/VoiceLine/0e78297f4b8f51f95557c61f303d81a9cdac4635/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ws123/VoiceLine/0e78297f4b8f51f95557c61f303d81a9cdac4635/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ws123/VoiceLine/0e78297f4b8f51f95557c61f303d81a9cdac4635/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ws123/VoiceLine/0e78297f4b8f51f95557c61f303d81a9cdac4635/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ws123/VoiceLine/0e78297f4b8f51f95557c61f303d81a9cdac4635/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/values-v21/styles.xml: -------------------------------------------------------------------------------- 1 | > 2 | 3 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 16dp 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | VoiceLine 3 | Settings 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 15 | 16 |