2012-02-24 162 views
2

我正在開發通過電子郵件發送錄製的音頻文件的android語音聽寫應用程序。而且它很難發送大尺寸的wav文件,所以我正在考慮將wav文件轉換爲可以通過電子郵件輕鬆發送的適當格式。將wav音頻文件轉換爲DSS音頻格式

谷歌搜索後,我發現.dss文件消耗非常小的尺寸,可以很容易地發送,但我不知道如何將wav文件轉換爲dss格式。你的答案將非常有用。

回答

1

我會推薦使用Speex,因爲它是免費的音頻編解碼器。 還有一個免費的Java庫,你應該很容易在android中使用。

http://jspeex.sourceforge.net/

此外,有JSPeex SVN回購,shich應該讓你開始。它有一個球員一些代碼示例,以及錄像機: http://jspeex.svn.sourceforge.net/viewvc/jspeex/main/trunk/player/src/main/java/org/xiph/speex/player/

藏漢作爲javadoc的http://jspeex.sourceforge.net/doc/index.html

+0

javax.sound在android中不支持,所以上面的鏈接無法幫助我。 – 2012-02-27 17:10:08

+0

你不需要:你可以把一些byte [] - s寫入編碼器http://jspeex.sourceforge.net/doc/org/xiph/speex/SpeexEncoder.html – devsnd 2012-02-28 17:43:13

1

我setuped NDK,在我的項目中使用的Speex。我能夠成功地對波形文件進行編碼,但是當我嘗試將其解碼時,文件大小不斷增加到很大。我錄製的音頻採樣率爲8000和16位,單聲道。

#include <jni.h> 
#include <stdio.h> 
#include "speex/speex.h" 

#define FRAME_SIZE 160 


void Java_com_m2_iSmartDm_ISmartDMActivity_spxDec(JNIEnv * env, jobject jobj, 
jstring dir1,jstring dir2) 
{ 
const char *inFile= (*env)->GetStringUTFChars(env,dir1,0); 
const char *outFile= (*env)->GetStringUTFChars(env,dir2,0); 
FILE *fin; 
FILE *fout; 
/*Holds the audio that will be written to file (16 bits per sample)*/ 
short out[FRAME_SIZE]; 
/*Speex handle samples as float, so we need an array of floats*/ 
float output[FRAME_SIZE]; 
char cbits[200]; 
int nbBytes; 
/*Holds the state of the decoder*/ 
void *state; 
/*Holds bits so they can be read and written to by the Speex routines*/ 
SpeexBits bits; 
int i, tmp; 

/*Create a new decoder state in narrowband mode*/ 
state = speex_decoder_init(&speex_nb_mode); 

/*Set the perceptual enhancement on*/ 
tmp=1; 
speex_decoder_ctl(state, SPEEX_SET_ENH, &tmp); 

fin = fopen(inFile, "r"); 
fout=fopen(outFile,"w"); 

speex_bits_init(&bits); 

while (1) 
{ 
/*Read the size encoded by sampleenc, this part will likely be 
different in your application*/ 
fread(&nbBytes, sizeof(int), 1, fin); 
if (feof(stdin)) 
break; 

/*Read the "packet" encoded by sampleenc*/ 
fread(cbits, 1, nbBytes, fin); 

/*Copy the data into the bit-stream struct*/ 
speex_bits_read_from(&bits, cbits, nbBytes); 

/*Decode the data*/ 
speex_decode(state, &bits, output); 

/*Copy from float to short (16 bits) for output*/ 
    for (i=0;i<FRAME_SIZE;i++) 
    out[i]=output[i]; 

/*Write the decoded audio to file*/ 
    fwrite(out, sizeof(short), FRAME_SIZE, fout); 

} 
/*Destroy the decoder state*/ 
speex_decoder_destroy(state); 
/*Destroy the bit-stream truct*/ 
speex_bits_destroy(&bits); 
fclose(fout); 
fclose(fin); 


} 

這有什麼錯在我的代碼:

解碼的代碼下面給出?爲什麼它有這麼大的尺寸?

+0

請問一個新問題,而不是把這個轉過來。 – devsnd 2012-03-13 16:32:51