android 录音代码 wav,一种漂亮的方法在Android上记录.WAV音频

68747470733a2f2f696d672e736869656c64732e696f2f62616467652f416e64726f6964253230417273656e616c2d416e64726f6964417564696f5265636f726465722d677265656e2e7376673f7374796c653d7472756568747470733a2f2f6a69747061636b2e696f2f762f61647269656c636166652f416e64726f6964417564696f5265636f726465722e737667

AndroidAudioRecorder

A fancy audio recorder for Android. It supports WAV format at 48kHz.

demo.gif

9ef6ade1ac317bc926aaf49b5076fa9d.png

How To Use

1 - Add these permissions into your AndroidManifest.xml and request for them in Android 6.0+

2 - Open the recorder activity

String filePath = Environment.getExternalStorageDirectory() + "/recorded_audio.wav";

int color = getResources().getColor(R.color.colorPrimaryDark);

int requestCode = 0;

AndroidAudioRecorder.with(this)

// Required

.setFilePath(filePath)

.setColor(color)

.setRequestCode(requestCode)

// Optional

.setSource(AudioSource.MIC)

.setChannel(AudioChannel.STEREO)

.setSampleRate(AudioSampleRate.HZ_48000)

.setAutoStart(true)

.setKeepDisplayOn(true)

// Start recording

.record();

3 - Wait for result

@Override

protected void onActivityResult(int requestCode, int resultCode, Intent data) {

super.onActivityResult(requestCode, resultCode, data);

if (requestCode == 0) {

if (resultCode == RESULT_OK) {

// Great! User has recorded and saved the audio file

} else if (resultCode == RESULT_CANCELED) {

// Oops! User has canceled the recording

}

}

}

Import to your project

Put this into your app/build.gradle:

repositories {

maven {

url "https://jitpack.io"

}

}

dependencies {

compile 'com.github.adrielcafe:AndroidAudioRecorder:0.3.0'

}

FEATURES

Record audio

Tint images to black when background color is too bright (thanks to @prakh25)

Wave visualization based on this player concept

Play recorded audio

Pause recording

Configure audio source (Mic/Camcorder), channel (Stereo/Mono) and sample rate (8kHz to 48kHz)

Auto start recording when open activity

Keep display on while recording

Skip silence

Animations

Landscape screen orientation (only supports portrait at the moment)

Dependencies

Want to CONVERT AUDIO into your app?

Take a look at AndroidAudioConverter! Example of usage here.

License

The MIT License (MIT)

Copyright (c) 2016 Adriel Café

Permission is hereby granted, free of charge, to any person obtaining a copy

of this software and associated documentation files (the "Software"), to deal

in the Software without restriction, including without limitation the rights

to use, copy, modify, merge, publish, distribute, sublicense, and/or sell

copies of the Software, and to permit persons to whom the Software is

furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in

all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR

IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,

FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE

AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER

LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,

OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN

THE SOFTWARE.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的Android播放.wav文件的代码示例: ```java import android.media.AudioManager; import android.media.SoundPool; import android.os.Bundle; import android.app.Activity; public class MainActivity extends Activity { private SoundPool soundPool; private int soundID; boolean loaded = false; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // 初始化SoundPool soundPool = new SoundPool(10, AudioManager.STREAM_MUSIC, 0); // 加载音频文件 soundPool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() { @Override public void onLoadComplete(SoundPool soundPool, int sampleId, int status) { loaded = true; } }); soundID = soundPool.load(this, R.raw.sound, 1); } public void playSound(View v) { if (loaded) { soundPool.play(soundID, 1, 1, 1, 0, 1f); } } @Override protected void onDestroy() { super.onDestroy(); soundPool.release(); soundPool = null; } } ``` 上述代码使用了Android提供的`SoundPool`类来播放.wav文件。在`onCreate`方法中,首先初始化了`SoundPool`,然后通过`setOnLoadCompleteListener`方法来监听文件是否加载完成,一旦完成就将`loaded`标志设置为`true`。最后调用`load`方法来加载.wav文件。 在`playSound`方法中,如果文件已经加载完成,就可以调用`SoundPool`的`play`方法来播放文件。`play`方法的参数依次为:音频文件的ID、左声道音量(0.0f-1.0f)、右声道音量(0.0f-1.0f)、优先级(0为最低)、循环次数(0表示不循环)、播放速度(1.0f为正常速度)。 最后在`onDestroy`方法中释放`SoundPool`占用的资源。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值