I recorded a voice with android AudioRecord and I would like to convert it to ogg vorbis since it is not a patent. I tried vorbis-java beta, but it doesn't seem to work or I'm wrong.
Here is my code:
int frequency = 44100; int channel = AudioFormat.CHANNEL_IN_STEREO; int mAudioSource = MediaRecorder.AudioSource.MIC; int mAudioEncoder = AudioFormat.ENCODING_PCM_16BIT; try { final File outputFile = new File(mOutputPath); DataOutputStream dos = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(outputFile))); int bufferSize = AudioRecord.getMinBufferSize(frequency, channel, mAudioEncoder); AudioRecord audioRecord = new AudioRecord(mAudioSource, frequency, channel, mAudioEncoder, bufferSize); short[] buffer = new short[bufferSize]; audioRecord.startRecording(); while (isRecordStart) { int bufferReadResult = audioRecord.read(buffer, 0, bufferSize); for(int i = 0; i < bufferReadResult; i++) { dos.writeShort(buffer[i]); } } audioRecord.stop(); dos.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }
I save it in a file with the wav extension and use the vorbis-java example for encoding, but the output is only zzz .......
How to code this for ogg vorbis in android?
source share