Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to encode Recorded voice to ogg vorbis?

I have recorded voice with android AudioRecord and I would like to convert it to ogg vorbis as it is patent free. I have try vorbis-java beta, but it seem not work or I make some mistake.

Here are 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 to a file with extension wav and use example of vorbis-java to encode, but output is only zzz.......

How to encode this to ogg vorbis in android?

like image 990
polen Avatar asked Sep 06 '11 04:09

polen


People also ask

How to Export as Ogg?

For the File Type, choose Ogg Vorbis. Select a location to save the new file then press Save. Nothing needs to be entered in the Edit Metadata window, so press OK to begin the export. Your new OGG file will appear in the destination location you chose to save the file to.

How to save audacity file as Ogg?

Also accessed by: File > Export > Export Multiple... then choosing Ogg Vorbis Files from the Save as type dropdown menu. In this case the options dialog will appear in the center of the Export Multiple dialog.

What is an Ogg Vorbis file?

Ogg Vorbis is a fully open, non-proprietary, patent-and-royalty-free, general-purpose compressed audio format for mid to high quality (8kHz-48.0kHz, 16+ bit, polyphonic) audio and music at fixed and variable bitrates from 16 to 128 kbps/channel.

What is Vorbis audio decoder?

Ogg Vorbis is a royalty-free, general purpose lossy audio compression codec supported by the open source community. The codec supports 16-bit stereo audio up to 48kHz and 500kb/s. The audio quality is comparable to that of MPEG-4 AAC.


2 Answers

I think i read this question a few weeks ago and was also super frustrated. I ended up writing the needed ndk wrapper to use Xiph.org's stuff. The only catch is that in order to make it run well, I had to enable floating point instructions. Emulators don't have floating point, so it'll crash the emulator. Run it on pretty much any phone, though, and you'll be good to go. It's designed to emulate a FileInputStream and FileOutputStream for interfacing with the vorbis files.

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

like image 132
Rannick Avatar answered Sep 19 '22 17:09

Rannick


You seem to write raw audio data into a file instead of wav format. Wav format does have headers, not just audio data.

Note: Don't 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.

Then you can call the native code from your app to encode the audio data.

like image 20
Randy Sugianto 'Yuku' Avatar answered Sep 21 '22 17:09

Randy Sugianto 'Yuku'