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代碼
反正很麻煩,我反正沒有在網上找到合適的第三方