BeyondVerbal-V3 / Android-sample-code

The client application witch shows basic functionality of Beyond Verbal REST API
0 stars 1 forks source link

Trying to send wav file from device storage #1

Open SyafiqTM opened 7 years ago

SyafiqTM commented 7 years ago

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.

private HttpEntity getEntityForSendFile()
    {
        File directory = Environment.getExternalStorageDirectory();
        File file = new File( directory + "/AudioRecorder" );
        File AudioSavePathInDevice = new File( file + "/sample.wav" );
        InputStreamEntity reqEntity = null;
        // Fetches file from local resources.

        /*InputStream raw = getResources().openRawResource(R.raw.sample);*/
        try{
            InputStream raw = new FileInputStream(AudioSavePathInDevice);
            reqEntity = new InputStreamEntity(raw, -1);
        }catch (Exception e) {
            e.printStackTrace();
        }

        return reqEntity;
    }
SagiAmar84 commented 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;
}
SyafiqTM commented 7 years ago

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);
    }
SagiAmar84 commented 7 years ago

Our api only supports wav files MediaRecorder library doesn't support wav. please take a look at this example

https://github.com/mobro/android