现在我用的是pcm格式了,但是识别不准,一个字都不正确。
以下是我的代码,您看以下参数设置对吗,android的:
以下是创建audioRecord的代码
int frequency = Constant.SAMPLE_16K;
int channelConfiguration = AudioFormat.CHANNEL_IN_MONO;
int audioEncoding = AudioFormat.ENCODING_PCM_16BIT;
int bufferSize = AudioRecord.getMinBufferSize(frequency, channelConfiguration, audioEncoding);
audioRecord = new AudioRecord(MediaRecorder.AudioSource.VOICE_DOWNLINK, frequency, channelConfiguration, audioEncoding, bufferSize);
以下是bindParam函数中的设置
//设置采样率
intent.putExtra(Constant.EXTRA_SAMPLE, Constant.SAMPLE_16K);
//设置垂直领域
String prop = "100021";
//命令词
intent.putExtra(Constant.EXTRA_PROP, Integer.parseInt(prop));
我把录音后的文件拷贝到电脑上,可以播放出声音,声音也完全正确。
我用这个bindParam函数设置参数后,用来识别自带的16k_test.pcm,也能完全识别正确。
谁能给个录音(pcm格式)的demo?
收藏
点赞
0
个赞
请登录后评论
TOP
切换版块
参考这段录音代码吧
public class RecorderTask extends AsyncTask<Void, Void, Void> {
private Context context;
private final String file;
long delay;
private static final int frequence = 16000;
private static final int channelConfig = AudioFormat.CHANNEL_CONFIGURATION_MONO;
private static final int audioEncoding = AudioFormat.ENCODING_PCM_16BIT;
private int mAudioSource;
RecorderTask(Context context, String file, long delay, int audioSource) {
this.mAudioSource = audioSource;
this.context = context;
this.file = file;
this.delay = delay;
}
@Override
protected Void doInBackground(Void... arg0) {
AudioRecord record = null;
OutputStream dos = null;
try {
Log.d("recorder", "---- recorder delay " + delay + "ms, " + file);
Thread.sleep(delay);
new File(file).getParentFile().mkdirs();
dos = new FileOutputStream(file);
Log.d("recorder", "---- audio source = " + mAudioSource) ;
record = new AudioRecord(mAudioSource, frequence, channelConfig, audioEncoding, 32 * 1024);
record.startRecording();
byte[] buffer = new byte[320];
while (!isCancelled()) {
int r = record.read(buffer, 0, buffer.length);
if (r < 0) {
throw new IOException("recorder busy!");
}
dos.write(buffer, 0, r);
dos.flush();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (null != record) {
record.release();
}
if (null != dos) {
try {
dos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return null;
}
}
能给个能用于离线语音识别的录音的demo吗?这个才是最重要的!谢谢!
从现象看是录制的声音有问题导致的