使用 Tarsos 提供的 WriterProcessor 时无法写入文件。该文件存在,并且没有显示错误。但是文件是空的,播放的时候没有声音。
final Float srf = 44100.0F;
dispatcher = AudioDispatcherFactory.fromPipe(mRecordFile.getPath(), srf.intValue(), bufferSize, 0);
mOutputLowFile = new File(v.getContext().getFilesDir(), mOutputLowFileName);
RandomAccessFile outputFile = null;
try {
outputFile = new RandomAccessFile( mOutputLowFile, "rw");
} catch (FileNotFoundException e) {
Log.i(TAG, "onFFT: FileNotFoundException: " + e);
e.printStackTrace();
}
TarsosDSPAudioFormat outputFormat = new TarsosDSPAudioFormat(44100, 16, 1, true, false);
WriterProcessor writer = new WriterProcessor(outputFormat, outputFile);
dispatcher.addAudioProcessor(writer);
final AudioDispatcher finalDispatcher1 = dispatcher;
Thread recordingThread = new Thread(new Runnable() {
@Override
public void run() {
finalDispatcher1.run();
}
}, "recordingThread Thread");
recordingThread.start();
outputFile 是 1Ko 大,而原始文件是 3 Ko。