Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/225.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 当播放频率高于输入hz时,播放频率分块出现-点击声音_Android_Buffer_Playback Rate - Fatal编程技术网

Android 当播放频率高于输入hz时,播放频率分块出现-点击声音

Android 当播放频率高于输入hz时,播放频率分块出现-点击声音,android,buffer,playback-rate,Android,Buffer,Playback Rate,我的第一个音频实验,所以这可能不是最聪明的问题。但我试着从麦克风录制音频,然后通过耳机或扬声器播放。将播放速率设置为HZ的一半效果很好,但将播放速率设置为HZ的两倍会使音频听起来像是成片播放。我假设没有足够的时间玩,我玩了睡眠和扩大记录缓冲区的大小,但没有成功 有人知道我如何解决这个问题吗 我有一个8000的缓冲区,例如hz=8000,而pbhz=11025 //audio configuration and SCO Bluetooth connection. android.

我的第一个音频实验,所以这可能不是最聪明的问题。但我试着从麦克风录制音频,然后通过耳机或扬声器播放。将播放速率设置为HZ的一半效果很好,但将播放速率设置为HZ的两倍会使音频听起来像是成片播放。我假设没有足够的时间玩,我玩了睡眠和扩大记录缓冲区的大小,但没有成功

有人知道我如何解决这个问题吗

我有一个8000的缓冲区,例如hz=8000,而pbhz=11025

    //audio configuration and SCO Bluetooth connection. 
    android.os.Process.setThreadPriority(
                android.os.Process.THREAD_PRIORITY_URGENT_AUDIO);
    aManager.startBluetoothSco();
    aManager.setBluetoothScoOn(true);
    aManager.setMode(AudioManager.MODE_NORMAL);

    arec = new AudioRecord(
                MediaRecorder.AudioSource.VOICE_RECOGNITION,
                hz,
                AudioFormat.CHANNEL_IN_MONO,
                AudioFormat.ENCODING_PCM_16BIT,
                buffersize); 

    if (AcousticEchoCanceler.isAvailable()) {
        AcousticEchoCanceler echoCanceller = AcousticEchoCanceler.create(arec.getAudioSessionId());
        if (echoCanceller != null) {
    //        echoCanceller.setEnableStatusListener(this);
            echoCanceller.setEnabled(true);
        }
    } else { Log.e("configAudio", "Echo Canceler not available");}

    // Creates noise suppressor if available
    if (NoiseSuppressor.isAvailable()) {
        NoiseSuppressor noiseSuppressor = NoiseSuppressor.create(arec.getAudioSessionId());
        if (noiseSuppressor != null) {
        //    noiseSuppressor.setEnableStatusListener(this);
            noiseSuppressor.setEnabled(true);
        }
    } else { Log.e("configAudio", "Noise Suppressor not available");}

    atrack = new AudioTrack(AudioManager.STREAM_MUSIC,
                    hz,
                    AudioFormat.CHANNEL_OUT_MONO,
                    AudioFormat.ENCODING_PCM_16BIT,
                    buffersize,
                    AudioTrack.MODE_STREAM);

    atrack.setPlaybackRate(pbhz);
    }

arec.startRecording();
        atrack.play();

        Runnable runnable = new Runnable() {
              @Override
              public void run() {
                  while (isRecording) {
                     arec.read(buffer, 0, buffersize);
                     atrack.write(buffer, 0, buffer.length);
                 }          
                }
            };
            new Thread(runnable).start();

当您启用SCO时,您需要使用STREAM_VOICE_CALL,而不是STREAM_MUSIC来播放声音