我用
android AudioRecord录制了声音,我想将它转换为ogg vorbis,因为它是免专利的.我试过vorbis-
java beta,但它似乎不起作用或者我犯了一些错误.
这是我的代码:
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,mAudioEncoder,bufferSize); short[] buffer = new short[bufferSize]; audioRecord.startRecording(); while (isRecordStart) { int bufferReadResult = audioRecord.read(buffer,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(); }
我将它保存到扩展名为wav的文件中并使用vorbis-java编码进行编码,但输出只是zzz …….
如何在android中将此编码为ogg vorbis?
解决方法
我想我几个星期前读过这个问题,也非常沮丧.我最后编写了所需的ndk包装器来使用Xiph.org的东西.唯一的问题是,为了使其运行良好,我必须启用浮点指令.仿真器没有浮点,因此它会使仿真器崩溃.几乎可以在任何手机上运行它,你会很高兴.它旨在模拟FileInputStream和FileOutputStream,以便与vorbis文件进行交互.