运行 YandexSpeechKit 识别器时,我可以在文件中同时录制来自麦克风的声音吗?
需要同时进行语音识别(使用类识别器)并将声音从设备麦克风录制到文件中。使用标准机制 MediaRecord 是不可能的,因为 MediaRecord 和 YandexSpeechKit 使用本机方法和相同的资源。它导致某些进程(MediaRecord 或 Recognizer)失败。
我正在尝试使用 RecognizerListener -> onSoundDataRecorded(Recognizer Recognizer, byte[] bytes) 代码如下:
@Override
public void onSoundDataRecorded(Recognizer recognizer, byte[] bytes) {
Logger.d(TAG, "onSoundDataRecorded");
write(bytes);
}
public void write(byte[] bytes) {
File file = getTmpFile();
FileOutputStream fos = null;
try {
fos = new FileOutputStream(file, true);
fos.write(bytes);
} catch (IOException e1) {
e1.printStackTrace();
} finally {
if(fos != null) {
try {
fos.flush();
fos.close();
} catch(IOException e) {
}
}
}
}
但是虽然生成的文件无法播放。有人可以帮助我吗?
谢谢!