How to encode recorded voice for ogg vorbis?

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?

+6
source share
2 answers

I think I read this question a few weeks ago and was also upset. I ended up writing the necessary ndk shell to use the Xiph.org stuff. The only catch is that in order for it to work well, I had to include floating point instructions. Emulators do not have a floating point, so it will break the emulator. Run it on almost any phone, and you will be fine. It is designed to emulate FileInputStream and FileOutputStream to interact with vorbis files.

https://github.com/nwertzberger/libogg-vorbis-android

+8
source

It seems you are writing raw audio data to a file instead of the wav format. The Wav format has headers, not just audio.

Note. Do not use vorbis-java, but compile from libogg and libvorbis sources at http://www.xiph.org/downloads/

Use android NDK to compile them for embedding in your apk file.

You can then call your own code from your application to encode audio data.

+2
source

Source: https://habr.com/ru/post/896681/


All Articles