录音的参数和识别录音的参数该怎么设置,求demo
格子的黑色幽默 发布于2016-04 浏览:2212 回复:3
0
收藏

现在我用的是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
个赞
共3条回复 最后由用户已被禁言回复于2022-04
#4c5812回复于2016-04



参考这段录音代码吧


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;

    }



}




0
#3格子的黑色幽默回复于2016-04

能给个能用于离线语音识别的录音的demo吗?这个才是最重要的!谢谢!

0
#2c5812回复于2016-04

从现象看是录制的声音有问题导致的

0
TOP
切换版块