没有合适的资源?快使用搜索试试~ 我知道了~
首页Android音频处理之通过AudioRecord去保存PCM文件进行录制,播放,停止,删除功能
Android音频处理之通过AudioRecord去保存PCM文件进行录制,播放,停止,删除功能
222 浏览量
更新于2023-05-26
评论
收藏 226KB PDF 举报
主要介绍了Android音频处理之通过AudioRecord去保存PCM文件进行录制,播放,停止,删除功能的相关资料,需要的朋友可以参考下
资源详情
资源评论
资源推荐

Android音频处理之通过音频处理之通过AudioRecord去保存去保存PCM文件进行录制,播放,停止,删除功能文件进行录制,播放,停止,删除功能
主要介绍了Android音频处理之通过AudioRecord去保存PCM文件进行录制,播放,停止,删除功能的相关资料,需要的朋友可以参考下
音频这方面很博大精深,我这里肯定讲不了什么高级的东西,最多也只是一些基础类知识,首先,我们要介绍一下Android他提供的录音类,实际上他有两个,一个是MediaRecorder,还有一个就是我们今
天要用到的AudioRecord,那他们有什么区别呢?
一一.区别区别
MediaRecorder和AudioRecord都可以录制音频,区别是MediaRecorder录制的音频文件是经过压缩后的,需要设置编码器。并且录制的音频文件可以用系统自带的Music播放器播放。
而AudioRecord录制的是PCM格式的音频文件,需要用AudioTrack来播放,AudioTrack更接近底层。
PCM可能更加可以理解为音频的源文件
二二.优缺点优缺点
AudioRecord
主要是实现边录边播以及对音频的实时处理,这个特性让他更适合在语音方面有优势
优点:语音的实时处理,可以用代码实现各种音频的封装
缺点:输出是PCM格式文件,如果保存成音频文件,是不能够被播放器播放的,所以必须先写代码实现数据编码以及压缩
MediaRecorder
已经集成了录音、编码、压缩等,支持少量的录音音频格式,大概有,aac,amr,3gp等
优点:集成,直接调用相关接口即可,代码量小
缺点:无法实时处理音频;输出的音频格式不是很多,例如没有输出mp3格式文件
三三.准备工作准备工作
我们要实现的是一个实时的去录音,播放,停止等功能的测试案例,那我们肯定要准备点什么,比如说,我这里先创建一个项目——PCMSample
然后写个布局
layout_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="10dp">
<Button
android:id="@+id/startAudio"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/button_bg"
android:text="开始录音"
android:textColor="@android:color/white"/>
<Button
android:id="@+id/stopAudio"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginTop="5dp"
android:background="@drawable/button_bg"
android:enabled="false"
android:text="停止录音"
android:textColor="@android:color/white"/>
<Button
android:id="@+id/playAudio"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/button_bg"
android:enabled="false"
android:text="播放音频"
android:textColor="@android:color/white"/>
<Button
android:id="@+id/deleteAudio"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:background="@drawable/button_bg"
android:text="删除PCM"
android:textColor="@android:color/white"/>
<ScrollView
android:id="@+id/mScrollView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="5dp"
android:layout_weight="1">
<TextView
android:id="@+id/tv_audio_succeess"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="初始化完成...."
android:textColor="@color/colorAccent"/>
</ScrollView>
</LinearLayout>
可以预览一下



















安全验证
文档复制为VIP权益,开通VIP直接复制

评论0