A. android audiorecord 录音文件大小与什么有关6.0
[java] view plain
package ycq.testspeek;
import java.io.IOException;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;
import android.media.AudioFormat;
import android.media.AudioRecord;
import android.media.MediaRecorder;
import android.os.AsyncTask;
import android.util.Log;
public class RecordTask extends AsyncTask<Void, Integer, Void>{
private boolean isRecording=true;
private String ip_add;
private int port;
private OutputStream out_audio;
private Socket socket_audio;
private int frequence = 8000; // 录制频率,单位hz.这里的值注意了,写的不好,可能实例化AudioRecord对象的时候,会出错。我开始写成11025就不行。这取决于硬件设备
private int channelConfig = AudioFormat.CHANNEL_CONFIGURATION_MONO;
private int audioEncoding = AudioFormat.ENCODING_PCM_16BIT; // AudioFormat.ENCODING_PCM_16BIT;
private Video_instruction
把一些赞美当成春天我对我的热情和你的冷漠都失去了把一个和横店类似的村庄当成故乡耐心而它们活与不活真的是另外一件事情
C. android中 得到的音频 视频应该如何放入流内,应该如何对流进行压缩
用File就行吧。用字节流读取比较合适。
D. Android录音如何用Speex转码压缩
你一放假没你还敢已经没有和
E. Android 开发 如何实现高质量的录音
在移动APP开发中,每逢APP应用设计到多媒体开发的时候,都会让很多的程序员头疼不已,而且项目的开发进度会放慢、项目
的难度也会加大蛮多,同时APP的测试也会增加。Android中的多媒体开发,有音频的播放、音频的录制、视频的播放、视频的录制
等,虽然Android的SDK中提供了一些基础的开发API类,如音频的录制就提供了两种方式:AudioRecord录制音频和MediaRecorder录
制音频。AudioRecord类相对于MediaRecorder来说,更加接近底层,为我们封装的方法也更少。然而实现一个AudioRecord的音频录
制程序也很简单。
一、AudioRecord实现录制音频:
package com.hb56.MyAndroidUtil;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import android.app.Activity;
import android.content.ContentValues;
import android.content.Intent;
import android.hardware.Camera.AutoFocusCallback;
import android.media.AudioFormat;
import android.media.AudioManager;
import android.media.AudioRecord;
import android.media.AudioTrack;
import android.media.MediaPlayer;
import android.media.MediaRecorder;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
/**
* 该实例中,我们使用AudioRecord类来完成我们的音频录制程序
* AudioRecord类,我们可以使用三种不同的read方法来完成录制工作,
* 每种方法都有其实用的场合
* 一、实例化一个AudioRecord类我们需要传入几种参数
* 1、AudioSource:这里可以是MediaRecorder.AudioSource.MIC
* 2、SampleRateInHz:录制频率,可以为8000hz或者11025hz等,不同的硬件设备这个值不同
* 3、ChannelConfig:录制通道,可以为AudioFormat.CHANNEL_CONFIGURATION_MONO和AudioFormat.CHANNEL_CONFIGURATION_STEREO
* 4、AudioFormat:录制编码格式,可以为AudioFormat.ENCODING_16BIT和8BIT,其中16BIT的仿真性比8BIT好,但是需要消耗更多的电量和存储空间
* 5、BufferSize:录制缓冲大小:可以通过getMinBufferSize来获取
* 这样我们就可以实例化一个AudioRecord对象了
* 二、创建一个文件,用于保存录制的内容
* 同上篇
* 三、打开一个输出流,指向创建的文件
* DataOutputStream dos = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(file)))
* 四、现在就可以开始录制了,我们需要创建一个字节数组来存储从AudioRecorder中返回的音频数据,但是
* 注意,我们定义的数组要小于定义AudioRecord时指定的那个BufferSize
* short[]buffer = new short[BufferSize/4];
* startRecording();
* 然后一个循环,调用AudioRecord的read方法实现读取
* 另外使用MediaPlayer是无法播放使用AudioRecord录制的音频的,为了实现播放,我们需要
* 使用AudioTrack类来实现
* AudioTrack类允许我们播放原始的音频数据
*
*
* 一、实例化一个AudioTrack同样要传入几个参数
* 1、StreamType:在AudioManager中有几个常量,其中一个是STREAM_MUSIC;
* 2、SampleRateInHz:最好和AudioRecord使用的是同一个值
* 3、ChannelConfig:同上
* 4、AudioFormat:同上
* 5、BufferSize:通过AudioTrack的静态方法getMinBufferSize来获取
* 6、Mode:可以是AudioTrack.MODE_STREAM和MODE_STATIC,关于这两种不同之处,可以查阅文档
* 二、打开一个输入流,指向刚刚录制内容保存的文件,然后开始播放,边读取边播放
*
* 实现时,音频的录制和播放分别使用两个AsyncTask来完成
*/
/**
* 利用AudioRecord类实现自己的音频录制程序
* com.hb56.MyAndroidUtil.AudioRecord
*
* @author Admin-zhangyx
*
* create at 2014-10-16 下午2:03:13
*/
public class AudioRecordActivity extends Activity{
private TextView stateView;
private Button btnStart, btnStop, btnPlay, btnFinish;
private RecordTask recorder;
private PlayTask player;
private File audioFile;
private boolean isRecording = true, isPlaying = false; // 标记
private int frequence = 8000; // 录制频率,单位hz.这里的值注意了,写的不好,可能实例化AudioRecord对象的时候,会出错。我开始写成11025就不行。这取决于硬件设备
private int channelConfig = AudioFormat.CHANNEL_CONFIGURATION_MONO;
private int audioEncoding = AudioFormat.ENCODING_PCM_16BIT;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.my_audio_record);
stateView = (TextView) this.findViewById(R.id.view_state);
stateView.setText("准备开始");
btnStart = (Button) this.findViewById(R.id.btn_start);
btnStop = (Button) this.findViewById(R.id.btn_stop);
btnPlay = (Button) this.findViewById(R.id.btn_play);
btnFinish = (Button) this.findViewById(R.id.btn_finish);
btnFinish.setText("停止播放");
btnStop.setEnabled(false);
btnPlay.setEnabled(false);
btnFinish.setEnabled(false);
// 在这里我们创建一个文件,用于保存录制内容
File fpath = new File(Environment.getExternalStorageDirectory()
.getAbsolutePath() + "/data/files/");
fpath.mkdirs();// 创建文件夹
try {
// 创建临时文件,注意这里的格式为.pcm
audioFile = File.createTempFile("recording", ".pcm", fpath);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void onClick(View v) {
int id = v.getId();
switch (id) {
case R.id.btn_start:
// 开始录制
// 这里启动录制任务
recorder = new RecordTask();
recorder.execute();
break;
case R.id.btn_stop:
// 停止录制
this.isRecording = false;
// 更新状态
// 在录制完成时设置,在RecordTask的onPostExecute中完成
break;
case R.id.btn_play:
player = new PlayTask();
player.execute();
break;
http://www.2cto.com/kf/201503/382894.html
F. 为何要对录音进行压缩
有可能是录音格式为wav等压缩率不高或者未压缩的音频格式,占用很大空间,压缩一下可以减少空间占用,而音质不会发生很大变化。。所以要压缩。。。压缩一般就是转换格式。。
G. android中如何代码压缩音频视频文件呢
知道怎么压缩文件,音视频文件应该差不多吧O.O
package com.once;
import java.io.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipException;
import java.util.zip.ZipFile;
import java.util.zip.ZipOutputStream;
/**
* Java utils 实现的Zip工具
*
* @author once
*/
public class ZipUtils {
private static final int BUFF_SIZE = 1024 * 1024; // 1M Byte
/**
* 批量压缩文件(夹)
*
* @param resFileList 要压缩的文件(夹)列表
* @param zipFile 生成的压缩文件
* @throws IOException 当压缩过程出错时抛出
*/
public static void zipFiles(Collection<File> resFileList, File zipFile) throws IOException {
ZipOutputStream zipout = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(
zipFile), BUFF_SIZE));
for (File resFile : resFileList) {
zipFile(resFile, zipout, "");
}
zipout.close();
}
/**
* 批量压缩文件(夹)
*
* @param resFileList 要压缩的文件(夹)列表
* @param zipFile 生成的压缩文件
* @param comment 压缩文件的注释
* @throws IOException 当压缩过程出错时抛出
*/
public static void zipFiles(Collection<File> resFileList, File zipFile, String comment)
throws IOException {
ZipOutputStream zipout = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(
zipFile), BUFF_SIZE));
for (File resFile : resFileList) {
zipFile(resFile, zipout, "");
}
zipout.setComment(comment);
zipout.close();
}
/**
* 解压缩一个文件
*
* @param zipFile 压缩文件
* @param folderPath 解压缩的目标目录
* @throws IOException 当解压缩过程出错时抛出
*/
public static void upZipFile(File zipFile, String folderPath) throws ZipException, IOException {
File desDir = new File(folderPath);
if (!desDir.exists()) {
desDir.mkdirs();
}
ZipFile zf = new ZipFile(zipFile);
for (Enumeration<?> entries = zf.entries(); entries.hasMoreElements();) {
ZipEntry entry = ((ZipEntry)entries.nextElement());
InputStream in = zf.getInputStream(entry);
String str = folderPath + File.separator + entry.getName();
str = new String(str.getBytes("8859_1"), "GB2312");
File desFile = new File(str);
if (!desFile.exists()) {
File fileParentDir = desFile.getParentFile();
if (!fileParentDir.exists()) {
fileParentDir.mkdirs();
}
desFile.createNewFile();
}
OutputStream out = new FileOutputStream(desFile);
byte buffer[] = new byte[BUFF_SIZE];
int realLength;
while ((realLength = in.read(buffer)) > 0) {
out.write(buffer, 0, realLength);
}
in.close();
out.close();
}
}
/**
* 解压文件名包含传入文字的文件
*
* @param zipFile 压缩文件
* @param folderPath 目标文件夹
* @param nameContains 传入的文件匹配名
* @throws ZipException 压缩格式有误时抛出
* @throws IOException IO错误时抛出
*/
public static ArrayList<File> upZipSelectedFile(File zipFile, String folderPath,
String nameContains) throws ZipException, IOException {
ArrayList<File> fileList = new ArrayList<File>();
File desDir = new File(folderPath);
if (!desDir.exists()) {
desDir.mkdir();
}
ZipFile zf = new ZipFile(zipFile);
for (Enumeration<?> entries = zf.entries(); entries.hasMoreElements();) {
ZipEntry entry = ((ZipEntry)entries.nextElement());
if (entry.getName().contains(nameContains)) {
InputStream in = zf.getInputStream(entry);
String str = folderPath + File.separator + entry.getName();
str = new String(str.getBytes("8859_1"), "GB2312");
// str.getBytes("GB2312"),"8859_1" 输出
// str.getBytes("8859_1"),"GB2312" 输入
File desFile = new File(str);
if (!desFile.exists()) {
File fileParentDir = desFile.getParentFile();
if (!fileParentDir.exists()) {
fileParentDir.mkdirs();
}
desFile.createNewFile();
}
OutputStream out = new FileOutputStream(desFile);
byte buffer[] = new byte[BUFF_SIZE];
int realLength;
while ((realLength = in.read(buffer)) > 0) {
out.write(buffer, 0, realLength);
}
in.close();
out.close();
fileList.add(desFile);
}
}
return fileList;
}
/**
* 获得压缩文件内文件列表
*
* @param zipFile 压缩文件
* @return 压缩文件内文件名称
* @throws ZipException 压缩文件格式有误时抛出
* @throws IOException 当解压缩过程出错时抛出
*/
public static ArrayList<String> getEntriesNames(File zipFile) throws ZipException, IOException {
ArrayList<String> entryNames = new ArrayList<String>();
Enumeration<?> entries = getEntriesEnumeration(zipFile);
while (entries.hasMoreElements()) {
ZipEntry entry = ((ZipEntry)entries.nextElement());
entryNames.add(new String(getEntryName(entry).getBytes("GB2312"), "8859_1"));
}
return entryNames;
}
/**
* 获得压缩文件内压缩文件对象以取得其属性
*
* @param zipFile 压缩文件
* @return 返回一个压缩文件列表
* @throws ZipException 压缩文件格式有误时抛出
* @throws IOException IO操作有误时抛出
*/
public static Enumeration<?> getEntriesEnumeration(File zipFile) throws ZipException,
IOException {
ZipFile zf = new ZipFile(zipFile);
return zf.entries();
}
/**
* 取得压缩文件对象的注释
*
* @param entry 压缩文件对象
* @return 压缩文件对象的注释
* @throws UnsupportedEncodingException
*/
public static String getEntryComment(ZipEntry entry) throws UnsupportedEncodingException {
return new String(entry.getComment().getBytes("GB2312"), "8859_1");
}
/**
* 取得压缩文件对象的名称
*
* @param entry 压缩文件对象
* @return 压缩文件对象的名称
* @throws UnsupportedEncodingException
*/
public static String getEntryName(ZipEntry entry) throws UnsupportedEncodingException {
return new String(entry.getName().getBytes("GB2312"), "8859_1");
}
/**
* 压缩文件
*
* @param resFile 需要压缩的文件(夹)
* @param zipout 压缩的目的文件
* @param rootpath 压缩的文件路径
* @throws FileNotFoundException 找不到文件时抛出
* @throws IOException 当压缩过程出错时抛出
*/
private static void zipFile(File resFile, ZipOutputStream zipout, String rootpath)
throws FileNotFoundException, IOException {
rootpath = rootpath + (rootpath.trim().length() == 0 ? "" : File.separator)
+ resFile.getName();
rootpath = new String(rootpath.getBytes("8859_1"), "GB2312");
if (resFile.isDirectory()) {
File[] fileList = resFile.listFiles();
for (File file : fileList) {
zipFile(file, zipout, rootpath);
}
} else {
byte buffer[] = new byte[BUFF_SIZE];
BufferedInputStream in = new BufferedInputStream(new FileInputStream(resFile),
BUFF_SIZE);
zipout.putNextEntry(new ZipEntry(rootpath));
int realLength;
while ((realLength = in.read(buffer)) != -1) {
zipout.write(buffer, 0, realLength);
}
in.close();
zipout.flush();
zipout.closeEntry();
}
}
}
H. 手机录音文件如何压缩
手机录音文件压缩方法:
1、我们可以利用酷狗音乐来实现这一功能,我们点击左侧的更多,选择格式转换。
I. 录音怎么压缩
能导出MP3格式的文件吗,MP3就是压缩过的格式,并且保证音质! 如果不能导出MP3格式,那就找个音频转换精灵或者用“千千静听”转换为MP3的格式,体积会小很多!
J. 问题,android如何压缩视频文件质量
系统级别的api,只能通过录制视频调整分辨了,格式等尽量降低视频的大小
系统api是没办法压缩视频大小的,除非使用第三方编译的库如FFMPEG,等但是这些都没有标准的,自己研究需要懂音视频C代码
反正很麻烦,我反正没有在网上找到合适的第三方