Open SyafiqTM opened 7 years ago
Hi, The path to the file is wrong please try this one:
private HttpEntity getEntityForSendFile() {
File directory = Environment.getExternalStorageDirectory();
File file = new File( directory + "/AudioRecorder" );
File[] localfiles = file.listFiles(); //get all files in Directory
InputStreamEntity reqEntity = null;
// Fetches file from local resources.
FileInputStream raw = null;
try {
raw = new FileInputStream(localfiles [0].getPath());
Log.i("Input_Stream_File",localfiles [0].getName().toString());
} catch (FileNotFoundException e) {
e.printStackTrace();
}
try {
raw = new FileInputStream(localfiles [0]);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
reqEntity = new InputStreamEntity(raw, -1);
return reqEntity;
}
Hi Sagi, thanks for your answer i've manage to send the sample audio to the server. FYI, I have an app that capture user's voice . I apply my code based on voice input guideline given "The API requires WAV PCM 8 KHz, 16 bit Mono." and a minimum 13 seconds of uninterrupted speech but i only get the same error just like before when i send file . Below is MediaRecorder specification that use in my app.
/* Record Thread */
public void MediaRecorderReady(){
mediaRecorder=new MediaRecorder();
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mediaRecorder.setAudioChannels(1); //mono
mediaRecorder.setAudioSamplingRate(8000); //8Khz sample rate
mediaRecorder.setAudioEncodingBitRate(16000); // 16bits
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mediaRecorder.setAudioEncoder(MediaRecorder.OutputFormat.AMR_NB);
mediaRecorder.setOutputFile(AudioSavePathInDevice);
}
Our api only supports wav files MediaRecorder library doesn't support wav. please take a look at this example
I got a response from server that tells me {"status:"failure","reason":"Not a WAVE file - no RIFF header"}. I try to upload the sample wav provided but from my device storage.