我一直在从事一个项目,该项目将呼吸模式的模式识别作为语音受损说话者的一种交流形式。
我知道如何做到这一点,但我对Java有非常基本的了解。我被卡住了。我想从麦克风中获取音频数据,并将其存储在阵列中。在这样做的过程中,我可以传递数据并对其进行规范化,从中提取特征,然后将新数组存储在我的数据库中。
请帮忙。非常感谢。
首先您应该编码为字符串
private void encodeAudio(String selectedPath) {
byte[] audioBytes;
try {
// Just to check file size.. Its is correct i-e; Not Zero
File audioFile = new File(selectedPath);
long fileSize = audioFile.length();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
FileInputStream fis = new FileInputStream(new File(selectedPath));
byte[] buf = new byte[1024];
int n;
while (-1 != (n = fis.read(buf)))
baos.write(buf, 0, n);
audioBytes = baos.toByteArray();
// Here goes the Base64 string
_audioBase64 = Base64.encodeToString(audioBytes, Base64.DEFAULT);
} catch (Exception e) {
DiagnosticHelper.writeException(e);
}
}
然后在接收设备中解码
private void decodeAudio( String base64AudioData, File fileName, String path, MediaPlayer mp) { try { FileOutputStream fos = new FileOutputStream(fileName); fos.write(Base64.decode(base64AudioData.getBytes(), Base64.DEFAULT)); fos.close(); try { mp = new MediaPlayer(); mp.setDataSource(path); mp.prepare(); mp.start(); } catch (Exception e) { DiagnosticHelper.writeException(e); } } catch (Exception e) { e.printStackTrace(); } }