录制声音并在Android中播放调制声音?

前端之家收集整理的这篇文章主要介绍了录制声音并在Android中播放调制声音?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

您好我正在做一个与声音调制相关的应用程序我需要知道如何录制声音并调制另一个声音中录制的声音.喜欢会说话的汤姆猫应用.我尝试了从堆栈流程From HERE解决方

并从另一个博客Blog Address

但我没有得到任何想法.任何人请给我一些想法或解决方案?

最佳答案
最后我找到了解决方案,这可能对某人有所帮助

http://android-er.blogspot.in/2012/06/implement-voice-changer-by-changing.html

public class Sound_modActivity extends Activity {

 Integer[] freqset = {11025,16000,22050,44100};
 private ArrayAdapterdioRecord.getMinBufferSize(sampleFreq,AudioFormat.CHANNEL_CONFIGURATION_MONO,AudioFormat.ENCODING_PCM_16BIT);

  short[] audioData = new short[minBufferSize];

  AudioRecord audioRecord = new AudioRecord(MediaRecorder.AudioSource.MIC,sampleFreq,AudioFormat.ENCODING_PCM_16BIT,minBufferSize);

  audioRecord.startRecording();

  while(recording){
  int numberOfShort = audioRecord.read(audioData,minBufferSize);
  for(int i = 0; i < numberOfShort; i++){
 dataOutputStream.writeShort(audioData[i]);
   }
  }

  audioRecord.stop();
  dataOutputStream.close();

  } catch (IOException e) {
  e.printStackTrace();
   }

  }

 void playRecord(){

 File file = new File(Environment.getExternalStorageDirectory(),"test.pcm");

    int shortSizeInBytes = Short.SIZE/Byte.SIZE;

  int bufferSizeInBytes = (int)(file.length()/shortSizeInBytes);
  short[] audioData = new short[bufferSizeInBytes];

  try {
InputStream inputStream = new FileInputStream(file);
BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
DataInputStream dataInputStream = new DataInputStream(bufferedInputStream);

int i = 0;
while(dataInputStream.available() > 0){
 audioData[i] = dataInputStream.readShort();
i++;
}

 dataInputStream.close();

 int sampleFreq = (Integer)spFrequency.getSelectedItem();

 AudioTrack audioTrack = new AudioTrack(
 AudioManager.STREAM_MUSIC,bufferSizeInBytes,AudioTrack.MODE_STREAM);

audioTrack.play();
audioTrack.write(audioData,bufferSizeInBytes);


 } catch (FileNotFoundException e) {
 e.printStackTrace();
} catch (IOException e) {
 e.printStackTrace();
}
 }

}
原文链接:https://www.f2er.com/android/430566.html

猜你在找的Android相关文章