- 浏览: 559218 次
- 性别:
- 来自: 广州
文章分类
- 全部博客 (338)
- 已过时文章(留念用) (39)
- Android学习笔记 (30)
- Android开发指引自译 (100)
- Android NDK文档自译 (23)
- Android设计指引自译 (2)
- xp(ペケピー)&linux(理奈、铃)酱~ (4)
- ui酱&歌词自译~ (9)
- lua酱~ (9)
- 自我反省 (1)
- 羽game计划 (1)
- XSL酱 (2)
- java酱 (3)
- 设计的领悟 (58)
- 涂鸦作品(pixiv) (1)
- ruby酱 (2)
- Objective-C编程语言自译 (2)
- Android开发月报 (6)
- objc酱 (2)
- photoshop (3)
- js酱 (6)
- cpp酱 (8)
- antlr酱 (7)
- Lua 5.1参考手册自译 (11)
- 收藏品 (3)
- 待宵草计划 (4)
- 体验版截图 (1)
最新评论
-
naruto60:
太给力了!!!!我这网打不开Intel官网,多亏楼主贴了连接, ...
使用HAXM加速的Android x86模拟器(和一些问题) -
yangyile2011:
谢谢博主,翻译得很好哦
【翻译】(4)片段 -
ggwang:
牙痛的彼岸:痹!
牙痛的彼岸 -
ggwang:
总结得很简练清晰啊,学习了!
ANTLR学习笔记一:概念理解 -
leisurelife1990:
mk sdd
用git下载Android自带app的源代码
【翻译】(86)音频捕捉
see
http://developer.android.com/guide/topics/media/audio-capture.html
原文见
http://developer.android.com/guide/topics/media/audio-capture.html
-------------------------------
Audio Capture
音频捕捉
-------------------------------
In this document
本文目录
* Performing Audio Capture 执行音频捕捉
* Code Example 代码示例
Key classes
关键类
MediaRecorder
See also
另见
Android Supported Media Formats Android支持的媒体格式
Data Storage 数据存储
MediaPlayer
-------------------------------
The Android multimedia framework includes support for capturing and encoding a variety of common audio formats, so that you can easily integrate audio into your applications. You can record audio using the MediaRecorder APIs if supported by the device hardware.
Android多媒体框架包含对捕捉和编码各种通用音频格式的支持,使你可以轻易地集成音频进你的应用程序中。你可以使用MediaRecorder的API记录音频,如果它被设备硬件支持。
This document shows you how to write an application that captures audio from a device microphone, save the audio and play it back.
本文向你展示如何编写一个应用程序,它从一个设备麦克风中捕捉音频,保存音频,以及回放它。
-------------------------------
Note: The Android Emulator does not have the ability to capture audio, but actual devices are likely to provide these capabilities.
注意:Android模拟器没有能力捕捉音频,但实际设备多半提供这些功能。
-------------------------------
-------------------------------
Performing Audio Capture
执行音频捕捉
Audio capture from the device is a bit more complicated than audio and video playback, but still fairly simple:
设备的音频捕捉比音频和视频回放稍微复杂些,但仍然非常简单:
1. Create a new instance of android.media.MediaRecorder.
1. 创建一个android.media.MediaRecorder的新实例。
2. Set the audio source using MediaRecorder.setAudioSource(). You will probably want to use MediaRecorder.AudioSource.MIC.
2. 使用MediaRecorder.setAudioSource()设置音频源。你将很可能希望使用MediaRecorder.AudioSource.MIC。
3. Set output file format using MediaRecorder.setOutputFormat().
3. 使用MediaRecorder.setOutputFormat()设置输出文件格式。
4. Set output file name using MediaRecorder.setOutputFile().
4. 使用MediaRecorder.setOutputFile()设置输出文件名。
5. Set the audio encoder using MediaRecorder.setAudioEncoder().
5. 使用MediaRecorder.setAudioEncoder()设置音频编码器。
6. Call MediaRecorder.prepare() on the MediaRecorder instance.
6. 在MediaRecorder实例上调用MediaRecorder.prepare()。
7. To start audio capture, call MediaRecorder.start().
7. 为了开始音频捕捉,请调用MediaRecorder.start()。
8. To stop audio capture, call MediaRecorder.stop().
8. 为了停止音频捕捉,请调用MediaRecorder.stop()。
9. When you are done with the MediaRecorder instance, call MediaRecorder.release() on it. Calling MediaRecorder.release() is always recommended to free the resource immediately.
9. 当你使用完MediaRecorder实例时,请对它调用MediaRecorder.release()。调用MediaRecorder.release()总是建议的,以立即释放资源。
Example: Record audio and play the recorded audio
示例:记录音频和播放被记录的音频
The example class below illustrates how to set up, start and stop audio capture, and to play the recorded audio file.
下面的示例类描述如何配置、启动和停止音频捕捉,以及如何播放被记录的音频文件。
-------------------------------
/*
* The application needs to have the permission to write to external storage
* if the output file is written to the external storage, and also the
* permission to record audio. These permissions must be set in the
* application's AndroidManifest.xml file, with something like:
*
* 该应用程序需要拥有权限来写入外部存储如果输出文件被写入到外部存储,
* 还需要记录音频的权限。这些权限必须被设置在应用程序的AndroidManifest.xml
* 文件中,就像这样:
*
* <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
* <uses-permission android:name="android.permission.RECORD_AUDIO" />
*
*/
package com.android.audiorecordtest;
import android.app.Activity;
import android.widget.LinearLayout;
import android.os.Bundle;
import android.os.Environment;
import android.view.ViewGroup;
import android.widget.Button;
import android.view.View;
import android.view.View.OnClickListener;
import android.content.Context;
import android.util.Log;
import android.media.MediaRecorder;
import android.media.MediaPlayer;
import java.io.IOException;
public class AudioRecordTest extends Activity
{
private static final String LOG_TAG = "AudioRecordTest";
private static String mFileName = null;
private RecordButton mRecordButton = null;
private MediaRecorder mRecorder = null;
private PlayButton mPlayButton = null;
private MediaPlayer mPlayer = null;
private void onRecord(boolean start) {
if (start) {
startRecording();
} else {
stopRecording();
}
}
private void onPlay(boolean start) {
if (start) {
startPlaying();
} else {
stopPlaying();
}
}
private void startPlaying() {
mPlayer = new MediaPlayer();
try {
mPlayer.setDataSource(mFileName);
mPlayer.prepare();
mPlayer.start();
} catch (IOException e) {
Log.e(LOG_TAG, "prepare() failed");
}
}
private void stopPlaying() {
mPlayer.release();
mPlayer = null;
}
private void startRecording() {
mRecorder = new MediaRecorder();
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mRecorder.setOutputFile(mFileName);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
try {
mRecorder.prepare();
} catch (IOException e) {
Log.e(LOG_TAG, "prepare() failed");
}
mRecorder.start();
}
private void stopRecording() {
mRecorder.stop();
mRecorder.release();
mRecorder = null;
}
class RecordButton extends Button {
boolean mStartRecording = true;
OnClickListener clicker = new OnClickListener() {
public void onClick(View v) {
onRecord(mStartRecording);
if (mStartRecording) {
setText("Stop recording");
} else {
setText("Start recording");
}
mStartRecording = !mStartRecording;
}
};
public RecordButton(Context ctx) {
super(ctx);
setText("Start recording");
setOnClickListener(clicker);
}
}
class PlayButton extends Button {
boolean mStartPlaying = true;
OnClickListener clicker = new OnClickListener() {
public void onClick(View v) {
onPlay(mStartPlaying);
if (mStartPlaying) {
setText("Stop playing");
} else {
setText("Start playing");
}
mStartPlaying = !mStartPlaying;
}
};
public PlayButton(Context ctx) {
super(ctx);
setText("Start playing");
setOnClickListener(clicker);
}
}
public AudioRecordTest() {
mFileName = Environment.getExternalStorageDirectory().getAbsolutePath();
mFileName += "/audiorecordtest.3gp";
}
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
LinearLayout ll = new LinearLayout(this);
mRecordButton = new RecordButton(this);
ll.addView(mRecordButton,
new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT,
0));
mPlayButton = new PlayButton(this);
ll.addView(mPlayButton,
new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT,
0));
setContentView(ll);
}
@Override
public void onPause() {
super.onPause();
if (mRecorder != null) {
mRecorder.release();
mRecorder = null;
}
if (mPlayer != null) {
mPlayer.release();
mPlayer = null;
}
}
}
-------------------------------
Except as noted, this content is licensed under Apache 2.0. For details and restrictions, see the Content License.
除特别说明外,本文在Apache 2.0下许可。细节和限制请参考内容许可证。
Android 4.0 r1 - 16 Apr 2012 17:06
-------------------------------
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.
此页部分内容,是基于Android开源项目所创建和共享的工作,并且根据知识共享2.5署名许可证描述的条款来使用的修改版。
(本人翻译质量欠佳,请以官方最新内容为准,或者参考其它翻译版本:
* ソフトウェア技術ドキュメントを勝手に翻訳
http://www.techdoctranslator.com/android
* Ley's Blog
http://leybreeze.com/blog/
* 农民伯伯
http://www.cnblogs.com/over140/
* Android中文翻译组
http://androidbox.sinaapp.com/
)
发表评论
-
【翻译】(9-补丁2)电话簿提供者
2012-07-18 12:54 2331【翻译】(9-补丁2)电话簿提供者 see h ... -
【翻译】(8-补丁1)Android接口定义语言(AIDL)
2012-07-02 05:55 2849【翻译】(8-补丁1)Andro ... -
【翻译】(0)应用组件
2012-06-30 23:50 787【翻译】(0)应用组件 see http:// ... -
【翻译】(88)传感器
2012-05-21 21:25 1021【翻译】(88)传感器 ... -
【翻译】(87)复制与粘贴
2012-05-20 14:48 1882【翻译】(87)复制与粘贴 see http: ... -
【翻译】(85)照相机
2012-05-13 15:09 3725【翻译】(85)照相机 see http:// ... -
【翻译】(84)JetPlayer
2012-04-21 16:24 931【翻译】(84)JetPlayer see h ... -
【翻译】(83)媒体回放
2012-04-21 16:00 1799【翻译】(83)媒体回放 see http:/ ... -
【翻译】(82)多媒体与照相机
2012-04-18 23:05 902【翻译】(82)多媒体与照相机 see htt ... -
【翻译】(23-补丁3)构建无障碍服务
2012-04-18 21:57 1580【翻译】(23-补丁3)构 ... -
【翻译】(23-补丁2)使应用程序无障碍
2012-04-16 13:08 2028【翻译】(23-补丁2)使应用程序无障碍 see ... -
【翻译】(23-补丁1)无障碍
2012-04-11 22:38 853【翻译】(23-补丁1)无 ... -
【翻译】(81)Renderscript之运行时API参考手册
2012-04-11 22:13 1374【翻译】(81)Renderscript之运行时API参 ... -
【翻译】(80)Renderscript之计算
2012-04-09 14:09 1387【翻译】(80)Renderscript之计算 ... -
【翻译】(79)Renderscript之图形
2012-04-08 13:59 2798【翻译】(79)Renderscript之图形 ... -
【翻译】(78)Renderscript
2012-04-04 15:35 1393【翻译】(78)Renderscript see ... -
【翻译】(77)可绘画对象动画
2012-03-18 10:52 664【翻译】(77)可绘画对象动画 see htt ... -
【翻译】(76)视图动画
2012-03-18 10:04 757【翻译】(76)视图动画 see http:/ ... -
【翻译】(75)属性动画
2012-03-17 18:24 2471【翻译】(75)属性动画 see http:/ ... -
【翻译】(74)动画
2012-03-10 14:22 989【翻译】(74)动画 ...
相关推荐
直接从声卡录音音频捕捉 直接从声卡录音音频捕捉 直接从声卡录音音频捕捉 直接从声卡录音音频捕捉 直接从声卡录音音频捕捉
基于C++实现的扩音器音频捕捉器+将PCM文件转为WAV文件源码+sln.zip基于C++实现的扩音器音频捕捉器+将PCM文件转为WAV文件源码+sln.zip基于C++实现的扩音器音频捕捉器+将PCM文件转为WAV文件源码+sln.zip基于C++实现的...
用java实现音频捕捉的源代码,通过该段代码,可以从硬件实时捕获声音信号,可以将该信号实时传输到网络上,可以轻松实现QQ语音聊天的效果
此程序可以录制声卡播放的声音,实现对声卡的音频捕捉的功能。
通过directshow实现对摄像头画面的捕捉,以及对系统声音的捕捉,可以实时得到数据流
易语言源码易语言提取google翻译音频源码.rar 易语言源码易语言提取google翻译音频源码.rar 易语言源码易语言提取google翻译音频源码.rar 易语言源码易语言提取google翻译音频源码.rar 易语言源码易语言提取...
易语言提取google翻译音频源码,提取google翻译音频
java 语音聊天关键两个类的源代码,包括音频输出和音频捕捉
摩斯密码翻译器,感兴趣的同学可以下载,挺好用的
摄像头视频捕捉程序
该软件支持图片、音频、视频及窗口捕捉、截长图等功能,还有附带测量图片像素的尺
音频制作软件音频裁切 音频合成软件是一个集声音编辑,播放,录制,和转换的音频工具,体积小巧, 功能却不弱。可打开的音频文件相当多,包括WAV, OGG, VOC, IFF, AIF, AFC, AU, SND, MP3, MAT, DWD, SMP, VOX, SDS...
程序结合易语言互联网支持库,调用google翻译播放音频。
MP3音频可视化源码MP3音频可视化源码MP3音频可视化源码MP3音频可视化源码MP3音频可视化源码MP3音频可视化源码MP3音频可视化源码MP3音频可视化源码MP3音频可视化源码MP3音频可视化源码MP3音频可视化源码MP3音频可视化...
音频混合,android 音频混合 音频混合,android 音频混合 音频混合,android 音频混合 音频混合,android 音频混合 音频混合,android 音频混合 音频混合,android 音频混合 音频混合,android 音频混合 音频混合,android ...
C# 音频捕获 音频传输 音频编解码 音频压缩 Lumisoft UDP P2P语音聊天 有实例可以借鉴,非常好,难得一见的好资源
可实现音频加速变慢、男女声变换等音频处理操作,还可以分析音频的频谱
音频测试wav文件,可直接pcm播放,用于验证speaker或者headset功能。
python实现音频添加隐写数据 1. 解析音频格式: 通过python自带的wav音频格式进行音频解析与输出 通过pydub解析任意格式音频进行解析,最后输出为wav格式音频文件 2. 添加隐写数据: 将解析的音频转为二进制并...
音频剪辑,可合并音频文件 音频剪辑,可合并音频文件 音频剪辑,可合并音频文件 音频剪辑,可合并音频文件