我正在开发一个android语音听写应用程序,通过电子邮件发送录制的音频文件。而且它很难发送大尺寸的wav文件,所以我正在考虑转换wav文件到一个适当的格式,可以很容易地通过电子邮件发送。
在谷歌搜索后,我发现.dss文件消耗非常小的大小,可以很容易地发送,但我不知道如何将wav文件转换为dss格式。你的答案将会很有帮助。
发布于 2012-02-24 22:11:08
我推荐使用Speex,因为它是一个免费的音频编解码器。还有一个免费的java库,你应该很容易在android中使用它。
http://jspeex.sourceforge.net/
此外,还有JSPeex SVN回购,它应该可以帮助您开始。它有一些播放器和记录器的代码示例: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。
发布于 2012-03-09 01:29:38
我设置了ndk,并在我的项目中使用了speex。我能够成功地对wave文件进行编码,但当我尝试将其解码回来时,文件大小一直在增加到很大。我已经录制了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);
}我的代码中有什么错误吗?为什么它会有这么大的尺寸?
https://stackoverflow.com/questions/9430503
复制相似问题