2014-08-30 4 views
0

Mediaplayer를 사용하여 사용자의 음성을 성공적으로 녹음했으며 파일이 SD 카드에 저장되었습니다. 이제 오디오 트랙을 사용하여 해당 음성을 재생하고 싶습니다. 그러나 내가 할 때 그것은 소음을 낸다. Y so.? 여기 AudioTrack에서 소리가 나기 때문에 오디오 파일을 제대로 재생하지 못합니다.

private void PlayAudioFileViaAudioTrack(String filePath) throws IOException 
    { 
    // We keep temporarily filePath globally as we have only two sample sounds now.. 
    if (filePath==null) 
    return; 

    int intSize = android.media.AudioTrack.getMinBufferSize(44100, AudioFormat.CHANNEL_CONFIGURATION_STEREO, 
    AudioFormat.ENCODING_PCM_16BIT); 

    AudioTrack at = new AudioTrack(AudioManager.STREAM_MUSIC, 44100, AudioFormat.CHANNEL_CONFIGURATION_STEREO, 
    AudioFormat.ENCODING_PCM_16BIT, intSize, AudioTrack.MODE_STREAM); 


    if (at==null){ 
    Log.d("TCAudio", "audio track is not initialised "); 
    return; 
    } 

    int count = 512 * 1024; // 512 kb 
    //Reading the file.. 
    byte[] byteData = null; 
    File file = null; 
    file = new File(filePath); 

    byteData = new byte[(int)count]; 
    FileInputStream in = null; 
    try { 
    in = new FileInputStream(file); 

    } catch (FileNotFoundException e) { 
    // TODO Auto-generated catch block 
    e.printStackTrace(); 
    } 

    int bytesread = 0, ret = 0; 
    int size = (int) file.length(); 
    at.play(); 
    while (bytesread < size) { ret = in.read(byteData,0, count); if (ret != -1) { // Write the byte array to the track 

     at.write(byteData,0, ret); bytesread += ret; } else break; } in.close(); at.stop(); at.release(); } 
+0

"잡음 만들기 ..." –

+0

잡음은 소리에 큰 왜곡을 만들어내는 것으로 분명하게 음성을 재생하지 못한다고 말할 수 있습니다. – AndroidiVore

+0

@Kenny m waiting – AndroidiVore

답변

0

소음으로 인해 작은 버퍼 될 수있다 .. 사운드를 재생할 수있는 코드이다.

시도 : 정확히 최소 버퍼 크기로 작업하는 경우

int intSize = android.media.AudioTrack.getMinBufferSize(44100, 
AudioFormat.CHANNEL_CONFIGURATION_STEREO, 
AudioFormat.ENCODING_PCM_16BIT); 
init *= 2; 

, 그것은 시끄러운 소리가 될 수 있습니다. 최소 크기의 두 배는 좋은 경험입니다 (제 경험상).