录音的参数和识别录音的参数该怎么设置,求demo
Ta的回复 :参考这段录音代码吧 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; } }