Java 将wav音频文件转换为DSS音频格式

Java 将wav音频文件转换为DSS音频格式,java,android,audio,wav,Java,Android,Audio,Wav,我正在android上开发一个语音听写应用程序,通过电子邮件发送录制的音频文件。而且它很难发送大尺寸的wav文件,所以我正在考虑将wav文件转换为适当的格式,以便通过电子邮件轻松发送 在谷歌搜索之后,我发现.dss文件消耗的大小非常小,而且可以很容易地发送,但我不知道如何将wav文件转换为dss格式。你的回答会很有帮助 我建议使用Speex,因为它是免费的音频编解码器。 还有一个免费的java库,在android中应该很容易使用 此外,还有JSPeex SVN Repo,shich应该让您开始

我正在android上开发一个语音听写应用程序,通过电子邮件发送录制的音频文件。而且它很难发送大尺寸的wav文件,所以我正在考虑将wav文件转换为适当的格式,以便通过电子邮件轻松发送


在谷歌搜索之后,我发现.dss文件消耗的大小非常小,而且可以很容易地发送,但我不知道如何将wav文件转换为dss格式。你的回答会很有帮助

我建议使用Speex,因为它是免费的音频编解码器。 还有一个免费的java库,在android中应该很容易使用

此外,还有JSPeex SVN Repo,shich应该让您开始。它有一些播放器和录音机的代码示例:


除了javadoc之外,我还设置了ndk,并在项目中使用了speex。我能够成功地对wave文件进行编码,但当我尝试将其解码回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);


}
#包括
#包括
#包括“speex/speex.h”
#定义帧大小160
无效Java_com_m2_iSmartDm_iSmartDm activity_spxDec(JNIEnv*env,jobject jobj,
jstring dir1,jstring dir2)
{
const char*infle=(*env)->GetStringUTFChars(env,dir1,0);
const char*outFile=(*env)->GetStringUTFChars(env,dir2,0);
文件*fin;
文件*fout;
/*保存将写入文件的音频(每个样本16位)*/
短出[帧大小];
/*Speex将样本作为浮点处理,因此我们需要一个浮点数组*/
浮点输出[帧大小];
char-cbits[200];
int字节;
/*保存解码器的状态*/
无效*状态;
/*保存位,以便Speex例程可以读取和写入位*/
spex位;
int i,tmp;
/*在窄带模式下创建新的解码器状态*/
状态=speex_解码器_初始化(&speex_nb_模式);
/*将感知增强设置为on*/
tmp=1;
speex_解码器_ctl(状态、speex_设置_ENH和tmp);
fin=fopen(填入“r”);
fout=fopen(输出文件,“w”);
speex_bits_init(&bits);
而(1)
{
/*读取sampleenc编码的大小,此部分可能
不同的应用程序*/
fread(&nbBytes,sizeof(int),1,fin);
if(feof(stdin))
打破
/*读取sampleenc编码的“数据包”*/
fread(cbits,1,nbBytes,fin);
/*将数据复制到位流结构中*/
speex_位(从中读取)(&bits、cbits、nbBytes);
/*解码数据*/
speex_解码(状态、位、输出);
/*从浮点复制到短(16位)输出*/

for(i=0;ijavax.sound)在android中不受支持,因此上面的链接无论如何也帮不了我。你不需要:你只需在编码器中加入一些字节[]-s,请提出一个新问题,而不是扭转这个问题。