Reputation: 3828
I am developing a speech dictation app in android that send the recorded audio file through email. And its difficult to send large size wav files, so I am thinking about converting wav files to an appropriate format that can be sent easily by email.
After googling I found that .dss files consumes very less size and can be easily sent, but I don't know how to convert wav files into dss format. Your answers will be very helpfull.
Upvotes: 2
Views: 2226
Reputation:
I setuped ndk and used speex in my project. I am able to encode the wave file successfully, but when i try to decode it back the file size keeps on increasing to a large size. I have recorded the audio at a sample rate of 8000 and 16 BIT, MONO.
The code for decoding is given below:
#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);
}
Is there anything wrong in my code? Why it gives in such a large size?
Upvotes: 1
Reputation: 7722
I would recommend using Speex, since it is a free audio codec. There also is a free java library, which you should be easy to use in android.
http://jspeex.sourceforge.net/
Also, there is the JSPeex SVN Repo, shich should get you started. It has some code examples for a player and a recorder: http://jspeex.svn.sourceforge.net/viewvc/jspeex/main/trunk/player/src/main/java/org/xiph/speex/player/
Aswell as the javadoc http://jspeex.sourceforge.net/doc/index.html
Upvotes: 1