コード例 #1
0
    void testSampleRate()
    {
        int ret = SampleRateDll.src_is_valid_ratio(0.05f);

        int inCnt = 44100;

        float[] samples = new float[inCnt];
        for (int i = 0; i < inCnt; ++i)
        {
            samples[i] = 0.1f;
        }
        int outCnt;

        float[] outSamples;
        //long outCnt = 8000;
        //float[] outSamples = new float[outCnt];
        int result = SampleRateDll.call_src_simple_plain(samples, out outSamples, inCnt, out outCnt, (float)outCnt / (float)inCnt, (int)SampleRateConvertType.SRC_SINC_FASTEST, 1);

        Debug.Log("finished: " + result + ", " + outSamples[4000]);
    }
コード例 #2
0
    void testRecognition()
    {
        VoiceRecognition v = GetComponent <VoiceRecognition>();

        Debug.Log("aaaaaaaa");
        v.init((bool inited_) => {
            Debug.Log("bbbbbbbb: " + inited_);
            // convert pcm to float
            int total = pcmFile.bytes.Length / 2;
            float[] pcms;
            SampleRateDll.convertPCMInt16ToFloat(pcmFile.bytes, total, out pcms);

            // upsample to 44100
            //int upSampleCnt = (int)(44100.0f / 8000.0f * total);
            //float[] upBuffer = new float[upSampleCnt];
            int upSampleCnt;
            float[] upBuffer;
            upSampleCnt = SampleRateDll.call_src_simple_plain(pcms, out upBuffer, total, out upSampleCnt, 44100f / 8000f, (int)SampleRateConvertType.SRC_SINC_FASTEST, 1);

            // downsample to 8000
            //int downSampleCnt = (int)(upSampleCnt * (8000f / 44100f));
            //float[] downBuffer = new float[downSampleCnt];
            int downSampleCnt;
            float[] downBuffer;
            downSampleCnt = SampleRateDll.call_src_simple_plain(upBuffer, out downBuffer, upSampleCnt, out downSampleCnt, 8000f / 44100f, (int)SampleRateConvertType.SRC_SINC_FASTEST, 1);

            // convert pcm to int16
            byte[] final;
            SampleRateDll.convertPCMFloatToInt16(downBuffer, (int)downSampleCnt, out final);

            v.getVoiceStr(final, (string result_) =>
            {
                Debug.Log("result: " + result_);

                v.getVoiceStr(final, (string another_) =>
                {
                    Debug.Log("another: " + another_);
                });
            });
        });
    }