使用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,而原始文件是3Ko。
答案 0 :(得分:1)
这是我正在使用的代码,并且可以正常工作-在管道中,我还放置了一个PitchProcessor(此代码主要来自https://stackoverflow.com/a/45867328/4872992):
dispatcher = AudioDispatcherFactory.fromDefaultMicrophone(SAMPLE_RATE, 1024, 0);
AudioProcessor p = new PitchProcessor(PitchProcessor.PitchEstimationAlgorithm.FFT_YIN, 22050, 1024, pdh);
dispatcher.addAudioProcessor(p);
filePath = "/sdcard/recording_test.pcm";
RandomAccessFile outputFile = new RandomAccessFile(filePath, "rw");
TarsosDSPAudioFormat outputFormat = new TarsosDSPAudioFormat(SAMPLE_RATE, 16, 1, true, false);
WriterProcessor writer = new WriterProcessor(outputFormat, outputFile);
dispatcher.addAudioProcessor(writer);
recordingThread = new Thread(dispatcher, "Audio Dispatcher)");
recordingThread.start();